Skip to content

Instantly share code, notes, and snippets.

View jfsiii's full-sized avatar

John Schulz jfsiii

View GitHub Profile
@max-mapper
max-mapper / helloworld.js
Created November 27, 2012 06:55
droneduino
var serialport = require('node-serialport')
var sp = new serialport.SerialPort("/dev/ttyO3", {
parser: serialport.parsers.raw,
baud: 9600
})
sp.on('data', function(chunk) {
console.log(chunk.toString('hex'), chunk.toString(), chunk)
})
@sindresorhus
sindresorhus / git-dirty-checks.md
Created October 16, 2012 11:20
Benchmark results of the fastest way to check if a git branch is dirty

Tested against the WebKit git repo by entering the repo with 1 file dirty.


git diff --quiet --ignore-submodules HEAD # Will tell if there are any uncomitted changes, staged or not.
0.6 sec

git diff-index --quiet HEAD # Only tracked
2 sec

@domenic
domenic / promises.md
Last active April 1, 2025 01:54
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@max-mapper
max-mapper / index.js
Created September 26, 2012 04:30
html5 audio capture
// get latest canary and turn on web audio in chrome://flags
navigator.webkitGetUserMedia({audio:true}, function (stream) {
var context = new webkitAudioContext()
var streamSource = context.createMediaStreamSource(stream)
var sent = false
bufferFiller = context.createJavaScriptNode(2048, 1, 1)
bufferFiller.onaudioprocess = function(e) {
if (sent) return
@slevithan
slevithan / es6-unicode-shims.js
Created April 3, 2012 09:14
ES6 Unicode Shims for ES3+
/*!
* ES6 Unicode Shims 0.1
* (c) 2012 Steven Levithan <http://slevithan.com/>
* MIT License
*/
/**
* Returns a string created using the specified sequence of Unicode code points. Accepts integers
* between 0 and 0x10FFFF. Code points above 0xFFFF are converted to surrogate pairs. If a provided
* integer is in the surrogate range, it produces an unpaired surrogate. Comes from accepted ES6
var source = [255,128,0]; // orange-ish
// get pixels from canvas
for (i = 0; i < pixels.data.length; i += 4) {
brightness = ((3*pixels.data[i]+4*pixels.data[i+1]+pixels.data[i+2])>>>3) / 256;
pixels.data[i] = ((source[0] * brightness)+0.5)>>0;
pixels.data[i+1] = ((source[1] * brightness)+0.5)>>0
pixels.data[i+2] = ((source[2] * brightness)+0.5)>>0
}
@ry
ry / fib.js
Created March 12, 2012 00:17
a proper fibonacci server in node. it will light up all your cores.
var http = require('http')
var fork = require('child_process').fork;
function fib(n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}

Inspired by Robert O'Callahan's blog

To reduce the need for "visual confirmation" tests:

  • store the base-64 encoded data-uri of a reference png as a string
  • copy the outerHTML of your test fixture into an SVG wrapper, prefixed with "data:image/svg+xml,"
  • set the src of an image to the value of the SVG wrapper
  • copy the image into a canvas context
  • assert equality of canvas.context.toDataURL() and previously stored reference string
@abozhilov
abozhilov / gist:1779852
Created February 9, 2012 13:02
HashMap
var HashMap = (function () {
var PROTO_SUPPORT = !Object.prototype.isPrototypeOf({__proto__ : null}),
OBJECT_CREATE = typeof Object.create != 'undefined',
DONT_ENUM_BUG = !{'toString' : true}.propertyIsEnumerable('toString');
var hasOwnP = {}.hasOwnProperty,
dontEnums = [];
if (DONT_ENUM_BUG) {
dontEnums = [
@Gozala
Gozala / example.js
Created January 29, 2012 03:46
Workaround for lack of "tail call optimization" in JS
// Lack of tail call optimization in JS
var sum = function(x, y) {
return y > 0 ? sum(x + 1, y - 1) :
y < 0 ? sum(x - 1, y + 1) :
x
}
sum(20, 100000) // => RangeError: Maximum call stack size exceeded
// Using workaround