Skip to content

Instantly share code, notes, and snippets.

View boutell's full-sized avatar

Tom Boutell boutell

View GitHub Profile
#
# 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 / 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>
@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 / 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 / nodeup.sh
Last active December 24, 2015 08:09
nodeup: a tiny script that installs the desired version of node on any Ubuntu Linux server. Builds from source but does it quickly with 4 cores. Also installs forever
#!/bin/sh
# On the specified host, install the specified version of node
if [ -z "$1" ]
then
echo "First argument must be somehost.com, second argument must be desired node version"
exit 1
fi
@boutell
boutell / gist:7183307
Created October 27, 2013 15:04
Subshells + Bash's "and" and "or" operators = kinda awesome
(
(cd server-status && git pull) ||
(rm -rf server-status && git clone https://github.com/punkave/server-status)
) &&
cd server-status &&
npm install ... etc
server {
listen 80;
server_name site1 www.site1;
location / {
rewrite ^/apartments http://site2/communities;
rewrite ^.*$ http://site2/something-else;
}
}
@boutell
boutell / gist:11055808
Last active August 29, 2015 14:00
Verify server is at least mongodb 2.6
self.db.command({ 'serverStatus': 1 }, function(err, result) {
if (err) {
return callback(err);
}
var versions = result.version.split(/\./);
if ((versions[0] < 2) || ((versions[0] == 2) && (versions[1] < 6))) {
return callback(new Error('\n\nMONGODB TOO OLD: your server must be at least MongoDB 2.6.0.\nYou currently have: ' + result.version));
}
return callback(null);
});
@boutell
boutell / gist:3be15e4b5c72597db273
Created June 6, 2014 15:47
nginx redirect example
server {
listen 80;
server_name oldname;
location / {
rewrite ^(.*)$ http://newname$1;
}
}
@boutell
boutell / gist:bf6bf1ae22dae2d77cc1
Created June 6, 2014 17:36
npm guru meditation with 200 OK result code
npm ERR! <?xml version="1.0" encoding="utf-8"?>
npm ERR! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
npm ERR! "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
npm ERR! <html>
npm ERR! <head>
npm ERR! <title>200 OK</title>
npm ERR! </head>
npm ERR! <body>
npm ERR! <h1>Error 200 OK</h1>
npm ERR! <p>OK</p>