Skip to content

Instantly share code, notes, and snippets.

View ifandelse's full-sized avatar

Jim Cowart ifandelse

View GitHub Profile
@ifandelse
ifandelse / postal.ideas.js
Created March 21, 2012 20:20
Postal API Ideas
// Below are FOUR possible examples of publish method signatures for the upcoming v0.6.0 release.
// Each one is using a simple "data" object (containing Alex's first and last name, since we were chatting as I wrote the gist)
// It's also worth bearing in mind that this is the top level API publish (where you don't have a handle to a channel already)
// you'll still be able to say var channel = postal.channel({ channel: "someChannel", topic: "someTopic" }), and then call publish off that later
// 1.) Single Payload, envelope is special member
/*
PROS:
one object to publish (data/env)
focus is on "DATA" being published - nice for consuming dev?
@ifandelse
ifandelse / DistributedTask.js
Created March 29, 2012 20:20
Machina-based linear/fork-join FSM Task Idea
define([
'underscore',
'machina'
], function( _, machina ){
return function(config) {
var base = {
initialState: "notStarted",
checkIfReady: function() {
if(_.all(this.constraints[this.state].checkList, function(constraint) { return constraint; })) {
this.transition(this.constraints[this.state].nextState);
@ifandelse
ifandelse / groupsOf.js
Created April 5, 2012 15:54
Underscore mixin that takes a list and splits it into multiple lists, where each list is n elements long
_.mixin({
groupsOf: function(list, num) {
if (!_.isArray(list)) {
list = _.toArray(list);
}
var result = [];
while (list.length) {
result.push(list.splice(0, num));
}
return result;
@ifandelse
ifandelse / appInitFsm.js
Created April 17, 2012 02:00
Hierarchical State Machine API ideas for machina.js
// FSM to handle app init concerns - 90% of the time it would have linear progression through states
var appInitFsm = new machina.Fsm({
initialState: "uninitialized";
states: {
uninitialized: {
_onEnter: function() {
this.transition("initializing");
}
},
@ifandelse
ifandelse / amqpBindingResolver.js
Created May 20, 2012 19:50
AMQP Style Bindings for postal.js
var amqpBindingsResolver = {
cache : { },
compare : function ( binding, topic ) {
if ( this.cache[topic] && this.cache[topic][binding] ) {
return true;
}
// binding.replace(/\./g,"\\.") // escape actual periods
// .replace(/#/g, ".*") // hashes match any value
// .replace(/\*/g, "[A-Z,a-z,0-9]*"); // asterisks match any alpha-numeric 'word'
@ifandelse
ifandelse / changes.md
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"
@ifandelse
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
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 = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
@ifandelse
ifandelse / README.md
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
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.