Skip to content

Instantly share code, notes, and snippets.

View maciejhirsz's full-sized avatar

Maciej Hirsz maciejhirsz

View GitHub Profile
@maciejhirsz
maciejhirsz / bench.js
Last active June 25, 2016 11:30
Benchmark JSON in Node.js
let json = `{"timestamp":2837513946597,"zone_id":123456,"zone_plan":1,"http":{"protocol":2,"status":200,"host_status":503,"up_status":520,"method":1,"content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":2},"country":238,"cache_status":3,"server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}`;
let data = JSON.parse(json);
const bytes = json.length;
const maxIterations = 500000;
function bench(iter) {
let iterations = maxIterations;
const start = Date.now();
let totalNanos = 0;
sys = require 'sys'
{exec} = require 'child_process'
fsevents = require 'fsevents'
###################################
compiling = false
compiler = null
notify = (message, type = 'info') ->
@maciejhirsz
maciejhirsz / magic.coffee
Created August 27, 2014 13:58
Magic config inheritance
class Base
constructor: ->
@config()
config: ->
magic = (options) =>
@config = {} if typeof @config is 'function'
@config[option] = value for option, value of options
return magic
@maciejhirsz
maciejhirsz / example.coffee
Last active December 22, 2015 03:39
Iteratively call an async method, get all callback results into a single array with preserved order and getting a single callback in return.
# get a single result
@processOne requiredStringArgument, requiredNumberArgument, id, (result) ->
# single result of processOne method
console.log result
@processOne.interative @, requiredStringArgument, requiredNumberArgument, arrayWithIds, (results) ->
# multiple results of processOne method in an array, with order of arrayWithIds preserved
console.log results