Skip to content

Instantly share code, notes, and snippets.

View subtleGradient's full-sized avatar
👋

Tom Aylott subtleGradient

👋
View GitHub Profile
@tlrobinson
tlrobinson / LICENSE.txt
Created October 2, 2011 08:56
Extremely simple lexer, parser, compiler, and interpreter for a prefix notation calculator.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Tom Robinson <http://tlrobinson.net/>
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
@ryanflorence
ryanflorence / universal-module.js
Created September 6, 2011 18:10
Universal JavaScript Module, supports AMD (RequireJS), Node.js, and the browser.
(function (name, definition){
if (typeof define === 'function'){ // AMD
define(definition);
} else if (typeof module !== 'undefined' && module.exports) { // Node.js
module.exports = definition();
} else { // Browser
var theModule = definition(), global = this, old = global[name];
theModule.noConflict = function () {
global[name] = old;
return theModule;
@fabiomcosta
fabiomcosta / sync-settimout-snippet.js
Created August 26, 2011 21:06
Mocks the setTimeout function with jasmine, making setTimeout dependent tests synchronous and easier to test.
// inside your beforeEach hook
spyOn(window, 'setTimeout').andCallFake(function(fn){
fn.apply(null, [].slice.call(arguments, 2));
return +new Date;
});
...
@subtleGradient
subtleGradient / Safer Module.example.js
Created June 21, 2011 18:06
Simple JavaScript Module Pattern
function MyClass(){
if (this instanceof MyClass){
this.init.apply(this, arguments);
} else {
MyClass.from(arguments[0])
}
}
MyClass.from = function(object){
// convert object into a MyClass or something
@hanshuebner
hanshuebner / plist-parser.js
Created June 1, 2011 05:44
plist parser written in node.js
var plistParser = require("../lib/sax").parser(false, {lowercasetags:true, trim:true}),
sys = require("sys"),
fs = require("fs");
function entity (str) {
return str.replace('"', '&quot;');
}
plistParser.getInteger = function (string) {
this.value = parseInt(string, 10);
var extend = function(child, parent) {
for(var i in parent) {
if(parent.hasOwnProperty(i)) {
child[i] = parent[i];
}
}
return child;
};
@louisremi
louisremi / serverReachable.js
Created April 22, 2011 11:39
better navigation.onLine: serverReachable()
function serverReachable() {
// IE vs. standard XHR creation
var x = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" ),
s;
x.open(
// requesting the headers is faster, and just enough
"HEAD",
// append a random string to the current hostname,
// to make sure we're not hitting the cache
"//" + window.location.hostname + "/?rand=" + Math.random(),
// -*- ObjC -*-
// Hiroshi Saito / Yakitara.com
/*
You know OCMock does great, but (If I'm not get wrong with it)
- it will supposed to be used in tests not a production code
- it can't mock class methods
- it requires an instace to be mocked accessible in your tests
If you not familiar with alias_method_chain, see:
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/aliasing.rb
var Browser = require('Browser').Browser;
var Request;
(function(){
Request = Browser.something ? new Class(...) : new Class(...);
})();
@subtleGradient
subtleGradient / global1.js
Created March 5, 2011 06:42
Globalize JS
var Foo = 'bar';