Skip to content

Instantly share code, notes, and snippets.

@metamatt
metamatt / README.md
Created February 18, 2015 17:08
Demo for NodeJS preemption bugs via node::MakeCallback.

Demo for NodeJS preemption bugs via node::MakeCallback.

Usage:

  • node 0.12.0 should be on your PATH
  • grab all the files from this gist into the same directory
  • node-gyp rebuild to compile preemptor.cc into build/Release/preemptor.node
  • node demo to run the demo

For me, the demo output is

@metamatt
metamatt / node-gyp-output
Created February 27, 2015 00:33
node-webkit-agent compile errors in node 0.12.0 after nan patch
matt@matt-dev ~/s/n/node-webkit-agent> node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.2
gyp info using node@0.12.0 | linux | x64
child_process: customFds option is deprecated, use stdio instead.
gyp info spawn python
gyp info spawn args [ '/usr/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
@metamatt
metamatt / gist:c53e6b80bb3d0c89f9a2
Created March 3, 2015 01:53
In NodeJS 0.10 (V8 3.14), V8 Error.stack getter replaces itself on the first call. In NodeJS 0.10 (V8 3.28), it does not. How to tell if it's already been called?
matt@matt-dev ~> ~/node-binaries/nodejs-0.10.33
> e = new Error()
[Error]
> Object.getOwnPropertyDescriptor(e, 'stack')
{ get: [Function],
set: [Function],
enumerable: false,
configurable: true }
> e.stack
'Error\n at repl:1:6\n at REPLServer.self.eval (repl.js:110:21)\n at Interface.<anonymous> (repl.js:239:12)\n at Interface.emit (events.js:95:17)\n at Interface._onLine (readline.js:202:10)\n at Interface._line (readline.js:531:8)\n at Interface._ttyWrite (readline.js:760:14)\n at ReadStream.onkeypress (readline.js:99:10)\n at ReadStream.emit (events.js:98:17)\n at emitKey (readline.js:1095:12)'
@metamatt
metamatt / QBird.js
Created June 11, 2015 23:00
Replace Angular $q with Bluebird
app.config(['$qProvider', function($qProvider) {
// Tell Angular to create Bluebird promises instead of $q promises.
$qProvider.$get = function() {
function QBird(resolver) {
return new Promise(resolver);
}
QBird.defer = function() {
var deferred = {};
deferred.promise = new Promise(function(resolve, reject) {
@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 / risk_dice.py
Last active August 7, 2022 23:23
Calculate odds of single Risk battle
#! /usr/bin/env python3
#
# Purpose: calculate the odds
# usage: risk_dice.py [ number of attacking armies ] [ number of defending armies ]
# eg: risk_dice.py 3 2
#
# I first tried looking this up to see what others had found: https://www.google.com/search?q=risk+dice+odds
# The first 3 Google results have answers which disagree substantially:
# 1) https://www.reddit.com/r/theydidthemath/comments/2h224y/comment/ckottiv/ has an analytic approach
# which doesn't seem to apply the actual game rules