Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@millermedeiros
millermedeiros / image.js
Created February 10, 2011 22:19
RequireJS Image Plugin
/*
* Example #1 : usage example
* - Image paths are relative to the HTML file.
* - Support absolute paths as well.
* - Appending `!bust` to the end of the file name will avoid caching the image.
*/
require(['image!lol_cat.gif', 'image!http://tinyurl.com/4ge98jz', 'image!dynamic_image.jpg!bust'], function(cat, awesome, dynamic){
//add loaded images to the document!
document.body.appendChild(awesome);
document.body.appendChild(cat);
@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
@briancavalier
briancavalier / then-promise.js
Created March 30, 2011 13:19
Promise chaining implementation of then()
Promise.prototype.then = function (onResolve, onReject, onProgress) {
if(isPromise(onResolve)) {
// Chain promise
this.then(
function(val) { onResolve.resolve(onReject ? onReject : val); },
function(err) { onResolve.reject(err); },
function(update) { onResolve.progress(update); }
);
} else {
// capture calls to then()
@bgerrissen
bgerrissen / js-loader.js
Created May 24, 2011 09:05
Robust cross browser JS Loader for dependency management.
/**
* Author: Ben Gerrissen
* Date: 9-3-11
* License: MIT
*/
(function( global ){
var undefined
, preloads = false
@unscriptable
unscriptable / AMD module list.md
Created May 26, 2011 15:25
List of AMD-compliant modules in the wild

A List of actively-supported, reusable, open-source, AMD-compliant modules in the wild. Let me know if you have another module to add to the list!

querySelectorAll (css3-based dom selector engine)

Promises / Deferreds

(function(){
function Klass(id){ this._id = id; }
Klass.prototype.id = function(){ console.log(this._id); }
var freeExports = typeof exports == 'object' && exports;
if (freeExports) {
for (var prop in Klass) freeExports[prop] = Klass[prop];
} else if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
define(function() { return Klass; });
@unscriptable
unscriptable / ZZZ_MyView.js
Created November 23, 2011 11:05
cujo-ish view/widget
// MyView.js when concatenated together using cram.js
// cram.js needs two new features to make this work:
// 1. an option to NOT normalize module ids
// 2. an option to more easily exclude modules from the build (wire plugins, for instance)
define('./myView/controller', {
_onClick: function (e) {
this.rootNode.classList.toggle(this.states.selected);
}
});
@briancavalier
briancavalier / soon.js
Created January 6, 2012 19:31
Enqueue a task for nextTick in many environments
soon = (function() {
var enqueueTask;
if(typeof process != 'undefined' && typeof process.nextTick == 'function') {
// Node nextTick
enqueueTask = process.nextTick;
} else if (typeof setImmediate == 'function') {
// setImmediate for new IE
@unscriptable
unscriptable / _spec.js
Created April 5, 2012 02:43
wire plugin to create functions without violating JSON
define({
myFunc: {
expr: {
body: 'alert(e.target.textContent);',
params: ['e']
}
},
body: {