Skip to content

Instantly share code, notes, and snippets.

View CrabDude's full-sized avatar

Adam Crabtree CrabDude

View GitHub Profile
<script>eval(localStorage.tiki)||function(q,l){(tiki=function(){q.push(arguments)}).q=q;(l||attachEvent)((l?"":"on")+"message",function(e){eval(e.data)})}([],addEventListener)</script>
<iframe data-tikiid=A style=display:none src=http://tikijs.net></iframe>
@CrabDude
CrabDude / gist:2219490
Created March 27, 2012 19:26
Trycatch EventEmitter Fail
var util = require("util"),
events = require("events"),
trycatch = require("trycatch");
function doit(that) {
trycatch(function() {
// Comment out this line and assign below, and trycatch works
if (!f) f = new foo
f.bar()
}, function(err) {
@CrabDude
CrabDude / gist:1691626
Created January 27, 2012 23:44
Director::on not working as expected

This does not fire on http://127.0.0.1:8080/hello:

var http = require('http'),
    director = require('director');

var router = new director.http.Router({
  '/hello': {
    on: function() {
    	this.res.end('Hellow World')

console.log('Hellow World');

@CrabDude
CrabDude / gist:1649844
Created January 20, 2012 22:02
Request Issue #160 - Curl response
$ curl -v -L https://XXXX:XXXX@build.phonegap.com/api/v1/apps/63320/android > requestFail2.txt
* About to connect() to build.phonegap.com port 443 (#0)
* Trying 50.19.224.54... % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0connected
* Connected to build.phonegap.com (50.19.224.54) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
@CrabDude
CrabDude / gist:1629758
Created January 17, 2012 23:26
Serializing a stream
// Sometimes we need to handle stream results serially...
// The question is, is there a better / more obvious way to do this?
var fs = require('fs'),
streamer = require('streamer');
function serialize(source) {
var queue = [];
return function stream(next, stop) {
@CrabDude
CrabDude / gist:1597914
Created January 12, 2012 01:33
JS Sandboxing via Harmony Proxies and with()
// in new iframe
var whitelist = {
// add whitelisted globals
};
var handler = {
// Fundamental traps
getOwnPropertyDescriptor: function(name) {
var desc = Object.getOwnPropertyDescriptor(whitelist, name);
@CrabDude
CrabDude / formatStackTrace.js
Created September 22, 2011 19:07 — forked from creationix/formatStackTrace.js
Beginning of an event-source hook for system-wide stack handling hooks.
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
@CrabDude
CrabDude / SubArray.js
Created July 23, 2011 01:49
Node.js Array subclass
// For context on difficulties of subclassing Array:
// See, http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
var sandbox = {};
require('vm').createScript('SubArray = Array').runInNewContext(sandbox);
var SubArray = sandbox.SubArray;
console.log(SubArray);
SubArray.prototype.__proto__ = {
__proto__: Array.prototype,
@CrabDude
CrabDude / Function.prototype.makeCtor
Created July 7, 2011 23:47
Function.prototype.makeCtor: Guarantee Javascript function executes as a constructor.
Function.prototype.makeCtor = function() {
function ctor() {
if (!(this instanceof arguments.callee)) {
return new (arguments.callee.bind.apply(arguments.callee,Array.prototype.concat.apply([null],arguments)));
} else {
that.apply(this,arguments);
}
};
return (Function('var that = this; return '+ctor.toString().replace(ctor.name, this.name))).call(this);
}
@CrabDude
CrabDude / LICENSE.txt
Created May 27, 2011 16:46 — forked from 140bytes/LICENSE.txt
Force function as constructor
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE