Skip to content

Instantly share code, notes, and snippets.

@metamatt
metamatt / keybase.md
Created February 17, 2015 07:14
Keybase proof of identity

Keybase proof

I hereby claim:

  • I am metamatt on github.
  • I am metamatt (https://keybase.io/metamatt) on keybase.
  • I have a public key whose fingerprint is 6EBF C4F0 19C0 122A 168F 600E 0452 043E 5FC8 7E11

To claim this, I am signing this object:

@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 [email protected]
gyp info using [email protected] | 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 / 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