Skip to content

Instantly share code, notes, and snippets.

View boutell's full-sized avatar

Tom Boutell boutell

View GitHub Profile
@boutell
boutell / dotNotation.js
Created September 16, 2013 19:30
Dot notation is a cool feature of mongodb that lets you set nested properties of an object. It's not hard to support this in your own JavaScript code. Here's the _get method I use in the joinr npm module to allow access to sub-properties of 'o' via syntax like 'name.last'. Also works for arrays. And if you pass a function, that function is calle…
// This supports: foo, foo.bar, foo.bar.baz (dot notation,
// like mongodb) and also passing in a custom accessor function
_get: function(o, accessor) {
var fn = accessor;
if (typeof(accessor) === 'string') {
fn = function(o) {
var keys = accessor.split(/\./);
_.each(keys, function(key) {
o = o[key];
@boutell
boutell / mandelbrot.c
Created June 7, 2013 02:11
As part of testing the performance of my asm.js mandelbrot set renderer, I've backported it to C in order to see what performance is like there. If you are not careful gcc or clang will optimize away the whole thing and complete in seemingly zero time because it knows you're not really using the computed data. I found that passing the image data…
#include <math.h>
#include <stdio.h>
#include <sys/time.h>
double microtime();
// C version of bench from Bug 879891. 1 iteration completes in 0.17 seconds
void compute(int *image);
@boutell
boutell / asm-js-mandelbrot.html
Last active December 18, 2015 02:29
Mandelbrot Set with core routine in asm.js. Does not appear to be any faster than not using asm.js in Firefox 22 beta, even though the console reports asm.js was successfully compiled.
<!doctype html>
<html>
<head>
<title>Mandelbrot set with asm.js</title>
<meta charset="utf-8" />
</head>
<body>
<canvas id="c"></canvas>
<div id="status"></div>
<script>
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
@boutell
boutell / gist:5412937
Created April 18, 2013 14:02
How do I make my object an event emitter/receiver?
function Thing() {
var self = this;
// Thing is now an event emitter/receiver
require('events').EventEmitter.call(self);
}
var thing = new Thing();
thing.emit('foo');
@boutell
boutell / gist:5409228
Created April 18, 2013 01:31
Piping a knox S3 http response (an input stream) to an output file, reliably detecting error and invoking a completion callback
var res = // Any input stream
var out = fs.createWriteStream(localPath);
res.pipe(out);
var dead = false;
function die(err) {
if (!dead) {
dead = true;
res.end();
out.end();
return callback(err);
@boutell
boutell / gist:5024073
Created February 24, 2013 14:40
gitc: the all-purpose "add and commit and merge and push and just DO ALL THE THINGS" git command
alias gitc='git add -A . && git commit && git pull && git push'
./symfony doctrine:build --all --db --env=prod
./symfony project:sync-content frontend prod from staging@staging
(cd /var/www/dukelist && ./app/console dukelist:cleanup --env=prod --send-emails)
(cd /var/www/dukelist && ./app/console dukelist:cleanup --env=staging)