Skip to content

Instantly share code, notes, and snippets.

@simonratner
simonratner / get_facility_code_wiegan_length_from_format_name.js
Created November 7, 2017 19:21 — forked from goliatone/get_facility_code_wiegan_length_from_format_name.js
Calculate parity bit for a string representation of a binary number, i.e 0101011101
var FACILITY_CODE = /(\d+)$/;
var WIEGAND_LENGTH = /^Wiegand (\d+)/i;
function getFacilityCode(format=''){
let match = format.match(FACILITY_CODE);
if(!match) return undefined;
let code = match[1];
return parseInt(code);
}
@simonratner
simonratner / git.js.patch
Created December 9, 2015 22:28
Patch npm to support msys2
--- node_modules/npm/lib/utils/git.js 2015-12-09 14:20:29.967240900 -0800
+++ node_modules/npm/lib/utils/git.js 2015-12-09 14:20:37.271994500 -0800
@@ -12,6 +12,14 @@
, git = npm.config.get("git")
, assert = require("assert")
, log = require("npmlog")
+ , msys = process.platform === "win32" && (/mingw/i.test(process.env.MSYSTEM))
+
+function convertArgs (arg) {
+ if (msys && /^([A-Za-z]):\\/.test(arg)) {
@simonratner
simonratner / mongodb.freebsd.userdata
Last active August 29, 2015 14:02
Provision a mongodb instance on FreeBSD/AWS
#!/bin/sh
cat <EOF >>/etc/rc.conf
syslogd_enable="YES"
syslogd_flags="-sv"
zfs_enable="YES"
# Install packages on first boot
firstboot_pkgs_list="mongodb"
@simonratner
simonratner / gist:5640436
Created May 24, 2013 00:05
Dot-decimal to integer and back
function dot2num(dot)
{
var d = dot.split('.');
return ((((((+d[0])*256)+(+d[1]))*256)+(+d[2]))*256)+(+d[3]);
}
function num2dot(num)
{
var d = num%256;
for (var i = 3; i > 0; i--)
@simonratner
simonratner / should.js
Last active December 17, 2015 03:48
Beating nodeunit + should into shape

Should assertions don't register with nodeunit. To makes them so, add a chainable prototype function that ensures that any subsequent should chain has access to the right nodeunit test object for registering its assertions.

Usage:

exports.suite = {
  "should pass": function(test) {
    value.in(test).should.be.ok();
    test.done();
  }

}

@simonratner
simonratner / cmd
Created December 20, 2011 01:26
Compiled assets in rails development environment
$ bundle exec rake assets:precompile
@simonratner
simonratner / gist:1372192
Created November 17, 2011 02:27 — forked from powmedia/gist:1081802
Backbone.sync for Titanium
//Customise Backbone.sync to work with Titanium rather than jQuery
Backbone.sync = (function() {
var methodMap = {
'create': 'POST',
'read' : 'GET',
'update': 'PUT',
'delete': 'DELETE'
};
var xhr = Ti.Network.createHTTPClient({ timeout: 5000 });