Skip to content

Instantly share code, notes, and snippets.

View bengl's full-sized avatar
💭
Set your status

Bryan English bengl

💭
Set your status
View GitHub Profile
@bengl
bengl / redis.rb
Created February 7, 2014 23:51
Homebrew script for DeNA's fork of redis
require 'formula'
class Redis < Formula
homepage 'http://redis.io/'
url 'http://download.redis.io/releases/redis-2.8.5.tar.gz'
sha1 'f0eb48609ff66ead3c7f06bbe8a8dd1aa7341b73'
bottle do
sha1 "3670032929123972994cdc29374628311e5fb874" => :mavericks
sha1 "9240b55f06576409d8f9e9f6f4d00d67a6861da0" => :mountain_lion
@bengl
bengl / keybase.md
Created March 7, 2014 06:15
keybase.md

Keybase proof

I hereby claim:

  • I am bengl on github.
  • I am bengl (https://keybase.io/bengl) on keybase.
  • I have a public key whose fingerprint is 12DA A122 E4B0 3089 0F5D A100 02E1 DF2D F935 CE6D

To claim this, I am signing this object:

@bengl
bengl / output.txt
Created April 1, 2014 18:17
randomized mock data tests
$ mocha test.js
0 passing (4ms)
1 failing
1) RandomStuff should work for all of mockData:
Error: 2/6 failed
at Context.<anonymous> (/Users/benglish/testcrap.js:26:19)
@bengl
bengl / .gitconfig
Created May 6, 2014 01:31
handy way to create npm module releases
[alias]
lasttag = describe --abbrev=0 --tags
releasenotes = !bash -c 'git shortlog --no-merges HEAD --not $(git lasttag)'
release = !bash -c 'echo \"%s\n\n$(git releasenotes)\" | xargs -0 npm version $0 -m'
@bengl
bengl / maybePromisify.js
Created June 12, 2014 01:11
Promisify if it calls a callback, pass through if it returns a promise.
// non-`Promise.defer()` version of https://github.com/petkaantonov/bluebird/issues/159#issuecomment-38348877
var Promise = require('bluebird');
function maybePromisify(fn, ctx){
return function() {
var args = Array.prototype.slice.call(arguments);
return new Promise(function(fulfill, reject){
args.push(function(err, result){
if (err)
@bengl
bengl / camera.js
Created October 1, 2014 04:05
simple webcam thing for tessel
var tessel = require('tessel');
var camera = require('camera-vc0706').use(tessel.port['A']);
var notificationLED = tessel.led[3];
camera.on('error', function(err) {
console.error(err);
});
camera.on('ready', function() {

Keybase proof

I hereby claim:

  • I am bengl on github.
  • I am bengl (https://keybase.io/bengl) on keybase.
  • I have a public key whose fingerprint is F2FE 3552 09D6 F280 BF6A B807 FE32 AE04 E6BF 5E9E

To claim this, I am signing this object:

Populating npm caches with BitTorrent

NOTE: This concept has probably been covered before, so if anyone can point me in the direction of some prior art, that would be great.

This past June, I attended NodeConf for the first time. While it was an amazing event, and I've love to go next year, it wasn't without its hiccups. In particular, all the sessions involved some npm install, and with hundreds of programmers on a small pipe to the internet, this became rather tiresome rather quickly.

First of all, cheers to everyone involved in setting up npm registry mirrors at the event (npm, Inc. and others). This worked out reasonably well, but often the mirrors were just slightly out of date, which was problematic because many instructors were updating their course material in real-time.

This sort of situation seems like it can be relatively common, so lots of solution ideas came from this. Here is one such solution.

# hundreds of lines like this...
info attempt registry request try #1 at 14:45:50
http request GET https://registry.npmjs.org/media-typer/
info attempt registry request try #1 at 14:45:50
http request GET https://registry.npmjs.org/mime-types/
info attempt registry request try #1 at 14:45:50
http request GET https://registry.npmjs.org/mime-db/
info attempt registry request try #1 at 14:45:50
http request GET https://registry.npmjs.org/util-extend/
info attempt registry request try #1 at 14:45:50
@bengl
bengl / extendedpromise.js
Created February 16, 2015 23:57
You can't extend promises in node 0.12.0
function ExtendedPromise (resolver) {
Promise.call(this, resolver)
}
require('util').inherits(ExtendedPromise, Promise)
ExtendedPromise.__proto__ = Promise
new ExtendedPromise(function (resolve) {
resolve(1)
}).then(console.log)