Skip to content

Instantly share code, notes, and snippets.

@domenic
domenic / bytearray.txt
Created April 28, 2015 11:45
V8 natives byte array
This file has been truncated, but you can view the full file.
[10, 34, 117, 115, 101, 32, 115, 116, 114, 105, 99, 116, 34, 59, 10, 118, 97,
114, 32, 107, 68, 101, 102, 97, 117, 108, 116, 66, 97, 99, 107, 116, 114, 97,
99, 101, 76, 101, 110, 103, 116, 104, 61, 49, 48, 59, 10, 118, 97, 114, 32, 68,
101, 98, 117, 103, 61, 123, 125, 59, 10, 118, 97, 114, 32, 115, 111, 117, 114,
99, 101, 76, 105, 110, 101, 66, 101, 103, 105, 110, 110, 105, 110, 103, 83, 107,
105, 112, 61, 47, 94, 40, 63, 58, 92, 115, 42, 40, 63, 58, 92, 47, 92, 42, 46,
42, 63, 92, 42, 92, 47, 41, 42, 41, 42, 47, 59, 10, 68, 101, 98, 117, 103, 46,
68, 101, 98, 117, 103, 69, 118, 101, 110, 116, 61, 123, 66, 114, 101, 97, 107,
58, 49, 44, 10, 69, 120, 99, 101, 112, 116, 105, 111, 110, 58, 50, 44, 10, 78,
101, 119, 70, 117, 110, 99, 116, 105, 111, 110, 58, 51, 44, 10, 66, 101, 102,
@domenic
domenic / emergency-fund.md
Last active August 29, 2015 14:20
Emergency fund model

Inputs (defaults in parens):

  • F = An investment fund (SPX, or 70/30 split, or, ...)
  • Y = years until retirement (40)
  • S = starting year when you make the decision between strategies. At least Y years in the past since we want to draw on historical data. (now - Y)
  • T = total starting capital. This should be the amount of accumulated lifetime savings you have in non-retirement accounts, and you need to decide what strategy to use on it. ($100K)
  • E = emergency fund value. Sources suggest 3-6 months living expenses. ($20K)
  • P = probability that you need to access $E in an emergency, some time between S and S+Y. (10%???)
  • X = the year you need access to $E, in P*100% of universes (see below)
  • strategy = { invest, emergency fund }
  • invest = put all of T into F
@domenic
domenic / image-flipper.js
Created June 24, 2015 06:49
Image-flipping server
"use strict";
const http = require("http");
const url = require("url");
const request = require("request");
const jsdom = require("jsdom");
const Canvas = require("canvas");
http.createServer(function (req, res) {
console.log(req.url);
const pageUrl = url.parse(req.url, true).query["proxy-me"];
@domenic
domenic / jsdom6.md
Last active August 29, 2015 14:26
jsdom 6.0 changelog draft

6.0.0

This major release is focused on massive improvements in speed, URL parsing, and error handling. The potential breaking changes are highlighted in bold below; the largest ones are around the jsdom.env error-handling paradigm.

This release also welcomes long-time contributer @Joris-van-der-Wel to the core team. You may recognize him from earlier changelogs. We're very happy to have his help in making jsdom awesome!

  • io.js 2.0 onward is now required, as we have begun using ES2015 features only present there.
  • Improved performance dramatically, by ~10000x in some cases, due to the following changes:
    • Overhauled the named properties tracker to not walk the entire tree, thus greatly speeding up the setting of id and name attributes (including during parsing).
var promise = paymentRequest(supportedInstruments, details, schemeData);
promise.then(function (paymentConfigurator) { // needs a slightly better name
paymentConfigurator.addEventListener("shippingAddressChange", function () { // no need for event
var newAddress = paymentConfigurator.address;
console.log(newAddress.street, newAddress.city, newAddress.state, newAddress.zip, newAddress.country);
// Return back new shipping options
paymentConfigurator.updateShippingOptions(newShippingOpions);
});
@domenic
domenic / .bashrc
Last active September 1, 2015 17:50
.bashrc with GitHub PR function
pr () {
git fetch origin refs/pull/$1/head:refs/remotes/origin/pr/$1 --force
git checkout -b pr/$1 origin/pr/$1
git rebase master
git checkout master
git merge pr/$1 --ff-only
}
@domenic
domenic / asyncdefer.svg
Created September 10, 2015 19:54
Async/defer SVG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@domenic
domenic / di-plus-sl-modules.js
Last active September 27, 2015 13:17
Intermediate DI/service locator solution for JavaScript modules
//////////////////////////
// Pure "DI style" modules
// BackEndAnalytics.js
define(function () {
return function BackEndAnalytics() {
this.send = function () { };
};
});
@domenic
domenic / promise-assertions.js
Created November 10, 2011 23:26
Sample of upcoming promise assertions module
// Say that doSomethingAsync returns a promise, and expected is the value we want it to return.
// With my library you can do the following
test("doSomethingAsync() returns expected", function () {
equal(doSomethingAsync(), expected, "As expected");
});
// Normally you would have to do
test("doSomethingAsync() returns expected", function () {
QUnit.stop();
@domenic
domenic / gist:1370488
Created November 16, 2011 16:08
Discussion of AMD vs. CommonJS Modules/2.0

Just want to chime in that I'm glad people are still interested in CommonJS Modules/2.0. We have a working implementation that hopefully will be of interest, and have factored out the generally applicable parts of our test suite. Also see the announcement thread on the CommonJS list.

That said, personally I've been a bit disappointed with the CommonJS community's lack of enthusiasm on Modules/2.0. We picked it up early in our project lifecycle, and ran with it full speed. At the time it seemed like a more standardized alternative to AMD.

However, over time it's become clear that AMD has not only won mindshare but also has a much more active group of maintainers and a better, more egalitarian standards process. Whereas, Modules/2.0 has only the perennially busy Wes Garland, leaving a self-hosted PDF s