Skip to content

Instantly share code, notes, and snippets.

@lenary
lenary / gitconfig.ini
Created February 18, 2011 01:21
a special excerpt of my gitconfig
$ git clone github:lenary/guides.git
Cloning into guides...
remote: Counting objects: 255, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 255 (delta 111), reused 163 (delta 35)
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done.
Resolving deltas: 100% (111/111), done.
$ cd guides
$ git remote -v
@subtleGradient
subtleGradient / global1.js
Created March 5, 2011 06:42
Globalize JS
var Foo = 'bar';
var Browser = require('Browser').Browser;
var Request;
(function(){
Request = Browser.something ? new Class(...) : new Class(...);
})();
// -*- 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
@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(),
var extend = function(child, parent) {
for(var i in parent) {
if(parent.hasOwnProperty(i)) {
child[i] = parent[i];
}
}
return child;
};
@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('"', '"');
}
plistParser.getInteger = function (string) {
this.value = parseInt(string, 10);
@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
@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;
});
...
@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;