Skip to content

Instantly share code, notes, and snippets.

@dmcaulay
dmcaulay / linux_linked_list.h
Created December 17, 2014 02:04
an example using the linux linked list data structure
// define person who has siblings and children
struct person {
int age;
struct list_head siblings;
struct list_head children;
}
// declare a father
struct person father = {
.age = 32,
@dmcaulay
dmcaulay / init.js
Last active August 29, 2015 14:01
stats for node.js and winston
var os = require("os");
// winston config
var winston = require('winston');
winston.clear();
config.label = os.hostname() + ":" + process.pid;
winston.setLevels(config.levels); // make sure you have a stats level
winston.addColors(config.colors); // you need to add a stats color
winston.add(winston.transports.Console, config);
@dmcaulay
dmcaulay / callbacks.js
Last active August 29, 2015 13:57
node.js callbacks
var asyncFunction = function(arg, callback) {
anotherAsync(function(err, res) {
if (err) return callback(err);
var returnValue = res + 1;
callback(null, returnValue);
});
};
var callbacks = require('asunder').split;
@dmcaulay
dmcaulay / payments.js
Last active January 4, 2016 20:39
example of configuring payments module
var config = require('config');
// require braintree implementation
var payments = require('payments-braintree');
// or require stripe implementation
var payments = require('payments-braintree');
// init
payments.config(config.payments);
s = open "| screen -r"
s.each do |sess|
pid = /\d+/.match(sess)
if pid
puts "killing #{pid}"
open "| screen -X -S #{pid} kill"
end
end
@dmcaulay
dmcaulay / mongo.ex
Created August 1, 2013 22:51
small elixir wrapper around the erlang driver for mongodb
defmodule Mongo do
defrecord Collection, pid: nil, db: nil, name: nil
def init do
:application.start :bson
:application.start :mongodb
end
def shutdown do
:application.stop :bson
@dmcaulay
dmcaulay / profile.js
Last active December 13, 2015 17:28
simple tool for profiling node.js web apps
var config = require('config')
var profilingEnabled = config.profile === undefined ? true : config.profile
var callback = function(name, callback) {
if (!profilingEnabled) return callback
var start = new Date()
var step = 0
return function end() {
console.log(name,'profile:',((new Date()) - start),'ms',step++)
callback.apply(this, arguments)
@dmcaulay
dmcaulay / index_spec.js.coffee
Created February 24, 2012 01:41
using jasmine: simple unit tests for a backbone index view
describe "Comnspace.Views.Entries.Index", ->
entries = undefined
view = undefined
$el = undefined
beforeEach ->
entries = new Comnspace.Collections.Entries()
entries.reset [
title: "Railscasts"
url: "www.railscasts.com"