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 | |
class ArrayPermutator implements IteratorAggregate { | |
protected $result = array(); | |
function __construct($items) { | |
$this->permute($items); | |
} | |
function getIterator() { | |
return $this->result; | |
} | |
protected function permute($items, $perms = array()) { |
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
[alias] | |
merge-all = "!sh -c 'for BRANCH in $(git branch -r | grep origin | grep -v HEAD | grep -v master | sed \"s/ *origin.//\") ; do git checkout $BRANCH && git merge master ; done ; git checkout master'" | |
up = "!sh -c 'git fetch origin ; for BRANCH in $(git branch -r | grep origin | grep -v HEAD | sed \"s/ *origin.//\") ; do git checkout $BRANCH && git pull origin $BRANCH ; done ; git checkout master && git submodule update --init'" |
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 | |
function is_valid_luhn($number) { | |
settype($number, 'string'); | |
$sumTable = array( | |
array(0,1,2,3,4,5,6,7,8,9), | |
array(0,2,4,6,8,1,3,5,7,9)); | |
$sum = 0; | |
$flip = 0; | |
for ($i = strlen($number) - 1; $i >= 0; $i--) { | |
$sum += $sumTable[$flip++ & 0x1][$number[$i]]; |
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 | |
function is_valid_iban($str) { | |
static $charmap = array ( | |
'A' => 10, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 'Z' => 35, | |
); | |
if (!preg_match("/\A[A-Z]{2}\d{2} ?[A-Z\d]{4}( ?\d{4}){1,} ?\d{1,4}\z/", $str)) { | |
return false; | |
} | |
$iban = str_replace(' ', '', $str); | |
$iban = substr($iban, 4) . substr($iban, 0, 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
import sys | |
import os | |
import subprocess | |
def git(args, **kwargs): | |
environ = os.environ.copy() | |
if 'repo' in kwargs: | |
environ['GIT_DIR'] = kwargs['repo'] | |
if 'work' in kwargs: | |
environ['GIT_WORK_TREE'] = kwargs['work'] |
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
select ceil((datediff(now(), created_at) - (dayofweek(now()) - 2)) / 7) ; |
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
@import url("reset-fonts-grids.css"); | |
@import url("hk-pyg.css"); /* for syntax highlighting */ | |
html { background: #f9f9f9; color: black; } | |
body { margin: 10px; font-family: verdana; } | |
fieldset { border: 1px solid #ccc; padding: 1em; } | |
legend { font-weight: bold; margin-left: 1em; padding: 4px; } | |
h1, h2, h3, h4, h5, h6 { font-weight: normal; } | |
table, tr, td, th { border: none; } | |
hr { height: 1px; color: #aaa; background-color: #aaa; border: 0; margin: .2em 0 .2em 0; } |
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
require 'gollum/frontend/app' | |
require 'digest/sha1' | |
class App < Precious::App | |
User = Struct.new(:name, :email, :password_hash, :can_write) | |
before { authenticate! } | |
before /^\/(edit|create|delete|livepreview|revert)/ do authorize_write! ; end | |
helpers do |
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 | |
/** | |
* Default settings for image_thumb. | |
*/ | |
$GLOBALS['image_thumb'] = array( | |
// FS path to location of image cache. Must be writable by web server. Must end with slash. | |
'local_path' => '/var/www/imagery/', | |
// HTTP path to local_path. Must end with slash. | |
'http_root' => '/imagery/', | |
// TTL for cached images, in sec. |
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 | |
/** | |
* @package fileutil | |
*/ | |
interface fileutil_FileHandler { | |
function handleFile(fileutil_File $file); | |
} | |
/** | |
* @package fileutil |