Skip to content

Instantly share code, notes, and snippets.

View justgord's full-sized avatar

Gordon Anderson justgord

View GitHub Profile
@justgord
justgord / scoped_timer.cpp
Created January 8, 2013 09:26
C++11 scoped timer class and usage
// C++11 scoped timer class and usage
//
// an example of RAII 'resource acquisition is initialisation' idiom
// build : g++ -Wall -std=c++11 -O5 -o scoped_timer scoped_timer.cpp
//
// on linux x64 resolution of timer seems to be microseconds [ on win/VC it may be much worse ]
//
// I like this approach as it doesnt litter your existing code with garbage,
// although there might be some inaccuracy due to stack setup/pulldown of the timer class itself
//
@justgord
justgord / jsonpath.js
Created September 5, 2011 05:46
handy command line util for looking into JSON files - based on JSONPath npm module
#!/usr/bin/env node
var fs = require('fs');
var jsonpath = require('JSONPath');
if (process.argv.length<3)
{
console.log('usage: jsonpath json_filename json_path_expr');
exit;
@justgord
justgord / serialq.js
Created March 23, 2011 08:01
serialq implementation - call functions sequentially for Node.js
exports.SerialQueue = function()
{
var sq =
{
funcs : [],
next : function()
{
var Q = this;
var f = Q.funcs.shift();
if (f)