Skip to content

Instantly share code, notes, and snippets.

View ox's full-sized avatar
👹
what is this, AIM?

Artem Titoulenko ox

👹
what is this, AIM?
View GitHub Profile
@ox
ox / cache.js
Last active December 19, 2015 23:29
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) === ':') {
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
@ox
ox / gist:6015522
Created July 16, 2013 21:56
profiling of various javascript faculties
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
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
@ox
ox / printf.js
Last active December 19, 2015 11:19
printf bunny
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
@ox
ox / invert.js
Created June 11, 2013 20:52
Compiler-safe invertPosition
invertPosition = function (position) {
return ((position === 'top' || position === 'bottom') ? (position === 'top' ? 'bottom' : 'top') : ((position === 'left' || position === 'right') ? (position === 'left' ? 'right' : 'left') : null))
}
@ox
ox / get_gchats.js
Last active December 17, 2015 18:18
Fetch all of your gchat messages and threads and stuff them into couchdb.
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) {
@ox
ox / texting.rb
Last active December 17, 2015 13:29
Pass in names of contacts and this script will create a table of messages received from those people according to date. $ruby texting.rb "Sam Smith" "Bobby Lynch" "Julia Roberts"
#!/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"
@ox
ox / .bash_profile
Last active December 17, 2015 09:39
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*
@ox
ox / pub_sub.c
Created February 27, 2013 04:56
An example of a C program using hiredis to SUBSCRIBE to a Redis channel. It listens for messages and prints them out.
#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) {