Skip to content

Instantly share code, notes, and snippets.

It would be nice to have a browser native delay function that added
a function to the call stack to be run immediately, but not blocking
UI, similar to
> setTimeout(func, 0).
Currently prototype does this - prototype.function.defer sets a
timeout of 0.01.
In my experience though, setting a timeout has a delay - Resig's
@peterbraden
peterbraden / optparse.js
Created December 1, 2010 20:52
Option Parsing for node.js scripts
/*
* returns [{opts}, [args]]
*/
var optParse = function(argv){
var opts = {}
, args = []
for(var i in argv){
var x = argv[i]
if (x[0] == '-'){
@peterbraden
peterbraden / Local ISO String for Date
Created December 23, 2010 00:40
toISOString with timezone support
Date.prototype.toLocalISOString = function(){
// ISO 8601
var d = this
, pad = function (n){return n<10 ? '0'+n : n}
, tz = d.getTimezoneOffset() //mins
, tzs = (tz>0?"-":"+") + pad(parseInt(tz/60))
if (tz%60 != 0)
tzs += pad(tz%60)
@peterbraden
peterbraden / JQuery Highlighter .js
Created February 16, 2011 19:18
Highlight words in html with a jquery plugin using jquery methods rather than raw DOM.
/*
* HTML Highlighter
*/
(function($){
$.fn.highlight = function(words, options){
var elements = $(this)
, settings = {
className: 'highlight'
, caseSensitive: false
}
@peterbraden
peterbraden / gist:1005153
Created June 2, 2011 19:52
Arduino to Traffic Light
int incomingByte = 0;
int prev = 0;
int RED = 13;
int ORANGE = 12;
int GREEN = 11;
void setup() {
pinMode(RED, OUTPUT);
pinMode(ORANGE, OUTPUT);
var sys = require('sys')
var tests = []
exports.runTest= function(t, browser, cb){
var err = function(e){
sys.print('E')
console.log("\n Error: ", t[1], ">>> ", e.name, e.message, '\n', e.stack)
cb()
@peterbraden
peterbraden / gist:1448369
Created December 8, 2011 20:17
Facebook Greasemonkey
// ==UserScript==
// @name pb-fb
// @namespace fb
// @description fb
// @include https://www.facebook.com/
// ==/UserScript==
document.getElementById("blueBar").style.setProperty("position", "absolute", "important");
var _findByVal = function(tag, val, cb){
@peterbraden
peterbraden / gist:1644678
Created January 20, 2012 02:55
Face Detection in Node.JS
var cv = require('opencv')
var im = new cv.Image("./examples/test.jpg")
, face_cascade = new cv.CascadeClassifier("./examples/haarcascade_frontalface_alt.xml")
var faces = face_cascade.detectMultiScale(im, function(err, faces){
for (var i=0;i<faces.length; i++){
var x = faces[i]
im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
}
var s = new cv.ImageStream();
fs.createReadStream('./examples/mona.jpg').pipe(s);
// ---
cv.ImageStream = function(){
this.data = Buffers([])
}
@peterbraden
peterbraden / gist:3455116
Created August 24, 2012 20:11
Webcam Face Detection in 16 lines of Javascript
var cv = require('opencv')
new cv.VideoCapture(0).read(function(mat){
mat.resize(200,100)
mat.detectObject("./data/haarcascade_frontalface_alt.xml", {min : [30,30]}, function(err, faces){
for (var i=0;i<faces.length; i++){
var x = faces[i]
mat.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);