Skip to content

Instantly share code, notes, and snippets.

View ifandelse's full-sized avatar

Jim Cowart ifandelse

View GitHub Profile
ifandelse / when_gen.js
Created August 25, 2014 18:07
Adapting ES6 presentation example from Q to when.js
var gen = require('when/generator');* () {
try {
var [pratt, ferrell] = yield when.all([
} catch (e) {
ifandelse / AMDOutput.js
Last active August 29, 2015 14:05
Trying to understand traceur's module transpilation output
define([], function() {
"use strict";
var myVar = {};
var $__default = myVar;
return {
get default() {
return $__default;
__esModule: true
ifandelse /
Last active August 29, 2015 14:04
Webpack Shim Question

In Require.js, it's possible to take a dependency on a "plain JS" lib (i.e. - it places a value on the window). For example, in the require.config, you'd do something along these lines:

      paths: {
        myAmdModule: "/path/to/my/amd/module",
        thirdPartyJS: "/path/to/plain/global/lib",
        jquery: "/path/to/jquery"
/** @jsx React.DOM */
], function(React, machina, Mousetrap) {
return machina.Fsm.extend({
initialize: function() {
ifandelse / main.js
Created May 15, 2014 22:15
Using Lodash with Postal in place of underscore
// Let's pretend we wanted to take the require js configuration from
// and tell it to use lodash instead of underscore.
// Since postal 0.9.0 and earlier expect the module ID (in AMD
// environments) to be "underscore", all you have to do is define a path
// for "underscore" and point it to lodash:
require.config( {
paths : {
underscore : "../../../bower/lodash/lodash",
ifandelse / umd.js
Last active December 11, 2015 14:59
UMD boilerplate to handle AMD, Commonjs, and standard browser js
// Example UMD wrapper for a module that takes dependencies on underscore and postal.js
(function ( root, factory ) {
if ( typeof module === "object" && module.exports ) {
// Node, or CommonJS-Like environments
// Intentionally returning a factory method
module.exports = function( _, postal ) {
return factory( _, postal );
} else if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
ifandelse /
Created November 21, 2012 20:15
Backbone.sync Override Using amplify.request

Backbone + Amplify.Request Experiment

Be warned - this code has not been tested yet....I just jotted it down stream-of-conscious style...

I will follow up with usage examples and verify that it really does work.

ifandelse / bind.js
Created July 29, 2012 03:05
bind shim
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
var aArgs =, 1),
fToBind = this,
fNOP = function () {},
ifandelse / uuid.js
Created July 2, 2012 04:30
Looking for "Good Enough" client-side UUID generator
I cannot claim this - it was recommended by a friend as a 'good enough' unique id generator
for local client side scenarios in the browser. The use case I'm looking to address has to
do with cross-frame messaging, where each point of origin needs a unique id (to be used as an
"origin" or correlation identifier). Therefore - the IDs do not need to be unique on a large
scale (e.g. - across a vast network of connected clients), but only in the browser, locally,
for the life of the session. Question is: is this good enough?
function createUUID() {
var s = [];
ifandelse /
Created May 25, 2012 03:30
Postal.js Bindings Resolver - Looming Changes....

Darn Straight - change is coming

The Way Postal.js Handles Topic Bindings Is About to Change

postal.js currently supports wildcard topic bindings by providing two special characters that can be used in a binding. The current implementation works as follows:

  • Topics are period-delimited string values. Periods are not required, but if they are included, the section of alpha-numeric text between periods is referred to as a word or topic segment.
  • Current wildcard characters:
    • * - an asterisk acts as a wildcard for any length of the topic.
      • "Home*" would match "Home.Sweet.Home" and "Homeless.Programmer"
  • "Home.*" would match "Home.Sweet.Home, but not "Homeless.Programmer"