Skip to content

Instantly share code, notes, and snippets.

View umutakturk's full-sized avatar
🏠
Working from home

Umut Akturk umutakturk

🏠
Working from home
View GitHub Profile
@umutakturk
umutakturk / random_string.rb
Last active January 7, 2023 23:03
Generate random string in Ruby.
def random_string(length = 6)
rand(36**length).to_s(36)
end
@umutakturk
umutakturk / time_ago.rb
Last active September 19, 2024 09:03
Ruby readable time ago function
def time_ago(timestamp)
delta = Time.now.to_i - timestamp
case delta
when 0..30 then "just now"
when 31..119 then "about a minute ago"
when 120..3599 then "#{delta / 60} minutes ago"
when 3600..86399 then "#{(delta / 3600).round} hours ago"
when 86400..259199 then "#{(delta / 86400).round} days ago"
else Time.at(timestamp).strftime('%d %B %Y %H:%M')
end
@umutakturk
umutakturk / jsonp_decode.php
Created September 29, 2012 19:10
JSONP Decode
<?php
$jsonp_string = preg_replace("/[^(]*\((.*)\)/", "$1", file_get_contents("http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=http://9gag.com/"));
$json = json_decode($jsonp_string, true);
echo $json['count'];
?>
@umutakturk
umutakturk / php_mongodb_simple_pagination.php
Created September 29, 2012 19:01
PHP MongoDB Simple Pagination
<?php
$mongodb = new Mongo("mongodb://username:password@localhost/database_name");
$database = $mongodb->database_name;
$collection = $database->collection;
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$limit = 12;
$skip = ($page - 1) * $limit;
$next = ($page + 1);
$prev = ($page - 1);