This file contains hidden or 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
var buildKeySus = function (patternObj, data) { | |
var pattern = patternObj.pattern | |
var duration = patternObj.duration || DEFAULT_CACHE_AGE_MS | |
data = data || {} | |
var patternParts = pattern.split('/') | |
var key = '' | |
for (var i = 0; i < patternParts.length; i++) { | |
if (patternParts[i].charAt(0) === ':') { |
This file contains hidden or 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
var genKeyBuilder = function(key) { | |
return function (data) { | |
return key.replace(/(:(\w+))/g, function (_, _, inner) { | |
return data[inner] | |
}) | |
} | |
} | |
console.log(genKeyBuilder('/:controller/:action/:id')({controller: 'foo', action: 'bar', id: '123'})) | |
// #=> /foo/bar/123 |
This file contains hidden or 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
Benchmark Samples Time Per Rate | |
Built In | |
Do nothing 10,000,000 0.028s 0.003µs 357,000,000/sec | |
Call a function 10,000,000 0.076s 0.008µs 131,000,000/sec | |
Create a string 10,000,000 0.027s 0.003µs 370,000,000/sec | |
Create an array 10,000,000 0.131s 0.013µs 76,300,000/sec | |
Create a persistent array 10,000,000 0.131s 0.013µs 76,300,000/sec | |
Increment a number in own scope 10,000,000 0.027s 0.003µs 370,000,000/sec | |
Increment a number in enclosing scope 10,000,000 0.044s 0.004µs 227,000,000/sec |
This file contains hidden or 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
var kb = 10 | |
var range = 1024 * kb | |
var paragraph = 'Vegan cornhole semiotics keffiyeh direct trade. Before they sold out fanny pack Carles scenester, keffiyeh High Life Austin flannel 8-bit. Fashion axe scenester Neutra, bicycle rights ethnic aesthetic sustainable letterpress. Pop-up mlkshk Schlitz meh Marfa kitsch pork belly, selvage street art. Dreamcatcher messenger bag Godard, viral ethnic keytar fanny pack post-ironic. Hashtag forage flexitarian hoodie DIY, banh mi shoreditch squid. Selvage master cleanse tote bag, trust fund fingerstache Odd Future you probably havent heard of them street art banjo single-origin coffee Bushwick.' | |
var paragraphLength = paragraph.length | |
var buffer = new Buffer(range * paragraphLength) | |
var string = "" | |
var time = +new Date |
This file contains hidden or 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
var printf = function (str) { | |
var args = Array.prototype.slice.call(arguments) | |
console.log(str.split('%').map(function (e, i) { | |
return (e[0] === 'x' ? String(args[i]) + e.substr(1) : e) | |
}).join('')) | |
} | |
printf('hello world') // => hello world | |
printf('number: %x, string: %x', 1, 'foo') // => number: 1, string: foo | |
printf('number: %x, string: %x', 'lol', 1, 'foo') // => number: lol, string: 1 |
This file contains hidden or 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
invertPosition = function (position) { | |
return ((position === 'top' || position === 'bottom') ? (position === 'top' ? 'bottom' : 'top') : ((position === 'left' || position === 'right') ? (position === 'left' ? 'right' : 'left') : null)) | |
} |
This file contains hidden or 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
function sendAllGChatThreadsToURL(url) { | |
var total = 0 | |
, offset = 500 // the max | |
Logger.log('starting...') | |
for (var start = 0; ; start += offset) { | |
var threads = GmailApp.getChatThreads(start, offset) | |
if (threads.length === 0) { |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# usage: | |
# $ ruby texting.rb ["<Name>", ...] | |
# | |
# There should be a folder called SMSBackups with XML files created by SMS Backup Tool for Android. | |
# | |
# example: | |
# $ ruby texting.rb "Sam Smith" "Bobby Lynch" "Julia Roberts" |
This file contains hidden or 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
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
fi | |
export PS1="\W \$ " | |
export PATH=/usr/local/share/npm/bin:$PATH | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* |
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <signal.h> | |
#include <hiredis/hiredis.h> | |
#include <hiredis/async.h> | |
#include <hiredis/adapters/libevent.h> | |
void onMessage(redisAsyncContext * c, void *reply, void * privdata) { |