Skip to content

Instantly share code, notes, and snippets.

View briancavalier's full-sized avatar

Brian Cavalier briancavalier

  • Pittsburgh
View GitHub Profile
define(["my/module"], function(module){
return {
wire$plugin: function authPlugin(ready, destroyed, options){
var providers = options.providers || [];
return {
ready: function(resolver, proxy, wire){
function maskCreditCardNumber(value) {
function multiply(x, y) {
return x * y;
}
function identyOf(number) {
return multiply(number, 1);
}
function toArrayOfIndividualDigits(value) {
@briancavalier
briancavalier / ZZZ_MyView.js
Created November 23, 2011 12:40 — forked from unscriptable/ZZZ_MyView.js
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 / bp1.js
Created November 9, 2011 03:18 — forked from unscriptable/bp1.js
boilerplate for CommonJS, AMD, plain old global hackfest
(function (namespace, myLib) {
//Set up myLib here.
if (typeof define == 'function' && define.amd) {
define(myLib);
}
else {
namespace.myLib = myLib;
}
@briancavalier
briancavalier / universal-module.js
Created September 30, 2011 18:02 — forked from millermedeiros/universal-module.js
Universal JavaScript Module, supports AMD (RequireJS), Node.js, and the browser.
// Define a global define() that works in the current environment
(function(global) {
var define;
define = global.define;
// If AMD, just use existing global.define
if(!(typeof define === 'function' && define.amd)) {
@briancavalier
briancavalier / semantic tiny Promise.js
Created February 11, 2011 17:00 — forked from unscriptable/tiny Promise.js
An attempt at a more sematic promise API
function Promise () {
this._resolve = [];
this._reject = [];
this._progress = [];
}
Promise.prototype = {
/* This is the "front end" API. */
// Promise implementation based on unscriptable's minimalist Promise:
// https://gist.github.com/814052/
function Promise () {
this._thens = [];
}
Promise.prototype = {
/* This is the "front end" API. */
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}