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]; |
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
//----------------------------------------------------------------------------- | |
// 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
#------------------------------------------------------------------------------ | |
# 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
<?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
javascript:%0Aif(window.hasOwnProperty('pinyin'))%0Awindow.pinyin();else%0A$('script').attr('src','https://raw.github.com/yhirose/wol-bookmarklets/master/pinyin.js').appendTo('body'); |
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 lz4_decompress(path) | |
def read_value(data, pos, size) | |
case size | |
when 1; type = 'C' | |
when 2; type = 'S' | |
when 4; type = 'L' | |
end | |
[pos + size, data[pos, size].unpack(type)[0]] | |
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
template <typename T, typename Pred, typename Conv> | |
auto filter_and_map(const vector<T>& cont, Pred pred, Conv conv) -> vector<typename std::remove_const<decltype(conv(T()))>::type> { | |
vector<typename std::remove_const<decltype(conv(T()))>::type> r; | |
for (const auto& el: cont) { | |
if (pred(el)) r.push_back(conv(el)); | |
} | |
return r; | |
} |
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
bool read_file(const char* path, vector<char>& buff) | |
{ | |
ifstream ifs(path, ios::in | ios::binary); | |
if (ifs.fail()) { | |
return false; | |
} | |
buff.resize(static_cast<unsigned int>(ifs.seekg(0, ios::end).tellg())); | |
if (!buff.empty()) { | |
ifs.seekg(0, ios::beg).read(&buff[0], static_cast<streamsize>(buff.size())); |
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
template<typename T, typename F> | |
std::basic_string<T> regex_replace_with_lambda( | |
const std::basic_string<T>& str, | |
const std::basic_regex<T>& re, | |
F f) | |
{ | |
typedef std::basic_string<T> StrT; | |
auto ret = StrT(); |
OlderNewer