Skip to content

Instantly share code, notes, and snippets.

@bahamas10
bahamas10 / early-exit.js
Created August 20, 2012 18:19
Node.js v0.8 exiting child_process.spawn early
var spawn = require('child_process').spawn;
function exec(args, callback) {
var out = '',
err = '',
child = spawn(args[0], args.slice(1));
child.stdout.on('data', function(data) {
console.log('exec got stdout'+out);
out += data;
@bahamas10
bahamas10 / output.txt
Created August 28, 2012 19:58
figure out what is trying to write to a stream in node
Trace
at WriteStream.process.stdout.write (/Users/dave/dev/node-latest/index.js:4:11)
at Object.exports.log (console.js:25:18)
at Object.keys.forEach.console.(anonymous function) [as log] (/Users/dave/dev/node-latest/node_modules/log-timestamp/index.js:13:14)
at defaultCb (/Users/dave/dev/node-latest/node_modules/npm/lib/npm.js:205:16)
at Conf.done (/Users/dave/dev/node-latest/node_modules/npm/node_modules/npmconf/npmconf.js:218:15)
at Object.oncomplete (fs.js:297:15)
undefined
@bahamas10
bahamas10 / String.js
Created September 21, 2012 19:47
string casting speed in node.js/javascript
var a = 5,
count = 100 * 1000 * 1000;
for (var i = 0; i < count; i++)
String(a);
@bahamas10
bahamas10 / 00-results.md
Created December 3, 2012 05:01
postincrement vs preincrement in Node.js/JavaScript

post-increment vs pre-increment in Node.js

Testing to see which one is faster

Results

pre-increment wins... barely

@bahamas10
bahamas10 / shell.md
Created December 15, 2012 04:50
url parsing for the shell in node that supports pipelining commands, easy screen scraping ahead
$ echo 'http://www.daveeddy.com/some/path/here?name=dave' | urlparse | json query.name
dave
$ echo 'http://www.daveeddy.com/some/path/here?name=dave' | urlparse | json pathname
/some/path/here
$ echo 'http://www.daveeddy.com/some/path/here?name=dave' | urlparse
{
  "protocol": "http:",
  "slashes": true,
 "host": "www.daveeddy.com",
@bahamas10
bahamas10 / ipf.conf
Created March 1, 2013 03:43
block specific port on illumos ipf
# i suck and always forget this
block in from any to port = 80
# more http://wiki.joyent.com/wiki/display/jpc2/Using+IPFilter+Rules
@bahamas10
bahamas10 / readme.md
Created March 27, 2013 04:39
create m3us for all free di.fm streams (great for mpd playlists)

di.fm m3u

run this to create m3u files for each free radio station that http://di.fm provides.

do this in a tempdir or something

egrep -o 'http://listen\.di\.fm/public3/.*\.pls' < <(curl -s http://www.di.fm/) | \
while read link; do
@bahamas10
bahamas10 / README.md
Last active December 16, 2015 20:39
libfasttime.so on smartos
@bahamas10
bahamas10 / README.md
Last active December 16, 2015 21:20
redis-server 2.4-eventport on smartos with libfasttime.so

redis-server and libfasttime.so

Testing out libfasttime.so with redis-server on SmartOS. see https://gist.github.com/bahamas10/5493551 for info on libfasttime.so.

Benchmarking done with DTrace and redis-benchmark from the redis source code

Without libfasttime.so

@bahamas10
bahamas10 / gen-flame.sh
Created June 3, 2013 18:00
generate flamegraph
#!/usr/bin/env bash
#
# Simply create a flame graph and open it
#
# gen-flame.sh <trace file> [ filter ]
if [[ ! -f "$1" ]]; then
echo "Usage: ${0##*/} <trace file>" >&2
exit 1
fi