Node.js Basit RestApi

package.json { “name”: “node-api”, “main”: “server.js”, “dependencies”: { “express”: “~4.0.0″, “body-parser”: “~1.0.1″, “mysql”: “*”, “sequelize”: “*”, “crypto”: “*” } } user.js var users = [ { "id": "1", "name": "Mark Brown", "age": 27 }, { "id": "2", "name": "Tim Gray", "age": 29 }, { "id": "3", "name": "Mark Blue", "age": 27 } ]; exports.getAllUsers = […]

Read More

Ajax Post vs. jQuery Post

$.ajax({ url: site_url + “ajax/post”, data: ({‘email’: email, ‘password’: password}), type: “post”, success: function(response, textStatus, jqXHR){ $(‘#sign-up’).html(response); } }); $.post(site_url + “ajax/post”, {‘email’: email, ‘password’: password}, function(html){ $(‘#sign-up’).html(html); });

Read More

Table Sorting

function sortTable(col, type){ var rows = $(‘table tbody tr’).get(); rows.sort(function(a, b) { var A = $(a).children(‘td’).eq(col).text().toUpperCase(); var B = $(b).children(‘td’).eq(col).text().toUpperCase(); if(A < B) { if(type === 'asc'){ return -1; }else{ return 1; } } if(A > B) { if(type === ‘asc’){ return 1; }else{ return -1; } } return 0; }); $.each(rows, function(index, row) { […]

Read More

JSON Array Sorting Fonksiyonu

var arr = [ { "ID": 1, "Name": "Fargo Chan", "Age": 21 }, { "ID": 5, "Name": "Aaron Luke", "Age": 18 }, { "ID": 2, "Name": "Dilip Singh", "Age": 32 } ]; 1. Yöntem: function SortByID(x,y) { return x.ID – y.ID; } function SortByName(x,y) { return ((x.Name == y.Name) ? 0 : ((x.Name > y.Name) […]

Read More

Sayfa Yönlendirme Fonksiyonu

function redirect($time = 0, $page){ echo “<meta http-equiv=\”refresh\” content=\”$time;url=$page\”>\n”; } redirect(2, “index.php”); redirect(“www.google.com”);

Read More

Xampp apc Eklentisi

Öncelikle buraya tıklayarak apc eklenti dosyalarını indirin. Daha sonra php.ini dosyasını açıp şu kodları ekleyin: extension=php_apc.dll [APC] apc.enabled = 1 ;istege bagli olarak asagidakiler de eklenebilir apc.shm_segments = 1 apc.shm_size = 64 apc.max_file_size = 10M apc.stat = 1

Read More

Seçilen Zamanın Belirtilen Aralıkta Olup Olmadığını Hesaplama

<?php $start = strtotime(’02:00:00′); $end = strtotime(’16:00:00′); //$now = strtotime(date(“H:i:s”)); $now = strtotime(’08:00:00′); if($start < $end){ // regular day if($now > $start && $now < $end){ echo “Gece”; }else{ echo “Gunduz”; } }else{ // rotate day if($now > $start || $now < $end){ // early night echo “Gece”; }else{ echo “Gunduz”; } } ?>

Read More

Mysql Batch Insert

mysql fonksiyonları ile: $sql = array(); foreach( $data as $row ) { $sql[] = ‘(“‘.mysql_real_escape_string($row['text']).’”, ‘.$row['user_id'].’)’; } mysql_query(‘INSERT INTO table (text, user) VALUES ‘.implode(‘,’, $sql)); mysqli fonksiyonları ile: $query = mysqli_prepare(“INSERT INTO table (text, user) VALUES(?,?,?)”); foreach($JSON_data as $key => $value) { $query->bind_param($value["text"], $value["user_id"]); $query->execute(); }

Read More