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 | |
# Simple Mustache template engine | |
function render($tmpl, $params) { | |
return preg_replace_callback( | |
'/(?:\{\{(\w+)\}\}|\{\{\{(\w+)\}\}\})/', | |
function($m) use($params) { | |
if (isset($params[$m[1]])) { | |
return htmlspecialchars($params[$m[1]]); | |
} else if (isset($params[$m[2]])) { |
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
#------------------------------------------------------------------------------ | |
# play_sound | |
#------------------------------------------------------------------------------ | |
def play_sound(url_string) | |
url = NSURL.URLWithString(url_string) | |
s = NSSound.alloc.initWithContentsOfURL(url, byReference: false) | |
s.delegate = self | |
s.play | |
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
//----------------------------------------------------------------------------- | |
// alert | |
//----------------------------------------------------------------------------- | |
[[NSAlert alertWithMessageText:@"Caption" | |
defaultButton:@"OK" | |
alternateButton:nil | |
otherButton:nil | |
informativeTextWithFormat:@"Message"] runModal]; |
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
" Conver number to number at cursor. | |
function! NumConv(base, fmt) | |
let b = a:base | |
let fmt = a:fmt | |
let w = expand('<cword>') | |
let d = str2nr(w, b) | |
let h = printf(fmt, d) | |
execute "normal ciw" . h | |
endfunction |
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 | |
// Lambda based memoizer | |
function memoize($fn) { | |
$cache = array(); | |
return function ($key) use($fn, &$cache) { | |
if (!isset($cache[$key])) { | |
$cache[$key] = $fn($key); | |
} | |
return $cache[$key]; |
NewerOlder