This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_string(length = 6) | |
rand(36**length).to_s(36) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
/* | |
int a, b; | |
a = 10; | |
b = 4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Binomial Coefficients | |
* | |
* @author K. Umut Aktürk <http://umut.me> | |
* @date October 20, 2012 | |
*/ | |
#include <iostream> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g++ helloWorld.cpp -o helloWorld | |
ls | |
./helloWorld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseConvert | |
CHARS = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz" # !-+*$ | |
BASE = CHARS.length | |
def self.num_to_str(num = nil) | |
str = "" | |
return 0 if num.nil? || num.zero? | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def slugify(text) | |
accents = { | |
['à','á','â','ã','å','ǻ','ā','ă','ą','ǎ','ª'] => 'a', | |
['ä','æ','ǽ'] => 'ae', | |
['Æ','Ǽ'] => 'AE', | |
['Ä'] => 'Ae', | |
['Ü'] => 'Ue', | |
['Ç','Ć','Ĉ','Ċ','Č'] => 'C', | |
['ç','ć','ĉ','ċ','č'] => 'c', | |
['Ð','Ď','Đ'] => 'D', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BACKUP_DIR="$HOME/path/to/backup" | |
USER="db_user" | |
PASS="db_pass" | |
HOST="db_host" | |
PORT="db_port" | |
NAME="db_name" | |
if [ ! -d $BACKUP_DIR ];then |
OlderNewer