Skip to content

Instantly share code, notes, and snippets.

@yhirose
yhirose / gist:3195927
Created July 29, 2012 03:32
PHP tiny mustache implementation
<?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]])) {
#------------------------------------------------------------------------------
# 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
//-----------------------------------------------------------------------------
// alert
//-----------------------------------------------------------------------------
[[NSAlert alertWithMessageText:@"Caption"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"Message"] runModal];
@yhirose
yhirose / NumConv.vim
Created February 2, 2012 22:06
Conver number to number at cursor in VIM
" 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
@yhirose
yhirose / memoize.php
Created February 2, 2012 03:32
PHP Lambda based memoizer
<?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];