Skip to content

Instantly share code, notes, and snippets.

@metamatt
metamatt / pings
Created June 22, 2014 05:27
San Francisco ISP latency
2014/06/21 (10:23pm on a saturday night, maybe bad case for monkeybrains):
astound:
wormhole:~# ping -I eth0.101 204.195.74.1
PING 204.195.74.1 (204.195.74.1) from 204.195.74.x eth0.101: 56(84) bytes of data.
64 bytes from 204.195.74.1: icmp_req=1 ttl=64 time=9.76 ms
64 bytes from 204.195.74.1: icmp_req=2 ttl=64 time=7.21 ms
64 bytes from 204.195.74.1: icmp_req=3 ttl=64 time=10.3 ms
64 bytes from 204.195.74.1: icmp_req=4 ttl=64 time=9.39 ms
@metamatt
metamatt / shell.txt
Created July 23, 2014 06:37
errors upgrading Discourse 0.9.6.4 to 0.9.9.13
discourse@chunkalicious:/var/www/discourse$ RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake db:migrate
WARNING: --------------------------------------------------------------------------
You are running an old version of bundler, please update by running: gem install bundler
WARNING: --------------------------------------------------------------------------
You are running an old version of bundler, please update by running: gem install bundler
rake aborted!
@metamatt
metamatt / gist:e654f8ce7e25ed0fc906
Last active August 29, 2015 14:06
url.parse api changes between node 0.10 and node 0.12 break karma
See for example https://github.com/karma-runner/karma/blob/master/lib/middleware/karma.js#L40, which assumes the result of `url.parse(foo, true)` always has a non-null `.query` property.
In node 0.10.26:
magi@ubuntu ~/s/d/experiments> node-0.10.26
> url.parse('/foo', true)
{ protocol: null,
slashes: null,
auth: null,
host: null,
@metamatt
metamatt / preemption.js
Created October 10, 2014 08:35
Demo of undesirable preemption in NodeJS due to MakeCallback.
//
// preemption.js
//
// Demo of undesirable preemption in NodeJS 0.10 (at least) due to MakeCallback;
// outer JS code that's running along happily but transitions to C++ code and then
// some inner JS code and back can find that state has changed out from under it,
// in ways it cannot predict (or conversely, that the inner JS code can observe
// shared data structures in an inconsistent state because the outer code was in
// the process of making changes to them that were intended to be atomic, and are
// not atomic due to this preemption).
@metamatt
metamatt / fiberStacks.js
Last active August 29, 2015 14:07
Demo of the call stacks you get from console.trace for a few scenarios involving node-fibers.
'use strict';
var Fiber = require('fibers');
var Future = require('fibers/future');
function test() {
console.trace('trace from root non-fiber');
// Create fiber explicitly, the low-level way.
var f1 = Fiber(function fiber1() {
@metamatt
metamatt / fast wake
Created October 28, 2014 17:01
This is my new mandatory sequence after upgrading OS X, since I prioritize my laptop waking up the second I open it higher than month-long standby, and this is apparently contrary to Apple's priorities since every OS X upgrade seems to nerf my settings back to the defaults: http://blog.metamatt.com/blog/2013/03/20/apple-is-getting-really-aggress…
magi@duality ~> sudo pmset -b standbydelay 43200
magi@duality ~> sudo pmset -c standby 0
magi@duality ~> pmset -g
Active Profiles:
Battery Power -1*
AC Power -1
Currently in use:
standbydelay 43200
standby 1
halfdim 1
@metamatt
metamatt / bigStrings.js
Created November 13, 2014 19:54
v8 does not intern strings that are identical, at least not if they're big. You can see distinct string objects in the heap dump.
require('webkit-devtools-agent')
b1 = fs.readFileSync('/usr/bin/nodejs')
b2 = fs.readFileSync('/usr/bin/nodejs')
c1 = b1.toString(); 0
c2 = b2.toString(); 0
c1 === c2 // true!
@metamatt
metamatt / Debug vs Release.md
Last active August 29, 2015 14:11
Be careful when building Node.js from source and asking for both debug and release versions.

If you build Node.js from source and want to try both the Debug and Relase configurations, and you notice that if you do

% ./configure --without-snapshot --debug
% make

you get both Debug and Release versions, and you think you can use them normally, think again:

@metamatt
metamatt / debug node fails.md
Last active August 29, 2015 14:11
reproducible v8 fatal error in debug version of nodejs 0.10.33
  1. Check out node 0.10.33 source
  2. ./configure --without-snapshot --debug
  3. make
  4. copy/symlink out/Debug/node so it's the node binary on your path
  5. create a package.json with the following contents
{
  "dependencies": {
    "archiver": "0.13",
@metamatt
metamatt / promise-chain.js
Created February 3, 2015 19:07
promise chaining in Q and angular $q
// find Q/$q implementation
var Q;
try {
$injector = angular.injector([ 'ng' ]);
Q = $injector.get('$q');
} catch (err) {
Q = require('q');
}
// helper function to attach handlers that show how promise is resolved