Skip to content

Instantly share code, notes, and snippets.

View xjamundx's full-sized avatar

Jamund Ferguson xjamundx

View GitHub Profile
@xjamundx
xjamundx / data-models.md
Last active August 29, 2015 14:16
common data model

Backbone has models for both display state and server data. Views bind to models and respond to various events on the models.

Ampersand has have the concept of session data (for display stuff) and props (for server synced data) (http://read.humanjavascript.com/ch06-models.html)

Ember has controllers which "allow you to decorate your models with display logic" (http://emberjs.com/guides/controllers/)

React has state and props. State is local to the component (view) and props are immutable and passed down from a parent.

Relay Relay "By co-locating the queries with the view code...components can be moved anywhere in a render hierarchy without having to apply a cascade of modifications to parent components or to the server code which prepares the data payload." (http://facebook.github.io/react/blog/2015/02/20/introducing-relay-and-graphql.html)

@xjamundx
xjamundx / no-define.js
Last active August 29, 2015 14:25
no-define
/**
* @fileoverview Rule to prefer require() (CJS) over define() (AMD)
* @author Jamund Ferguson
*/
'use strict';
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@xjamundx
xjamundx / no-cjs.js
Created July 22, 2015 16:39
ESLint Rule for encouraging es6 modules over commonJS
/**
* @fileoverview Rule to prefer ES6 to CJS
* @author Jamund Ferguson
*/
'use strict';
var EXPORT_MESSAGE = 'Expected "export" or "export default"',
IMPORT_MESSAGE = 'Expected "import" instead of "require()"';
@xjamundx
xjamundx / es6-examples.md
Last active August 29, 2015 14:26
Examples for my talk ES6 for everyone

If you're a designer your main interaction with JavaScript is probably through jQuery and jQuery plugins. If that's you, here are a few examples of how ES6 might make your life a litle bit better.

Default Parameters

$.fn.makeJump = function(height) {
    height = height || 50; // jump up 50px
    // ...
}
$(".chickens").makeJump();
@xjamundx
xjamundx / cookies.js
Created February 3, 2011 22:10
expressjs cookie fail
//express server creation
var app = express.createServer()
var MemoryStore = require('connect/middleware/session/memory')
// configuration
app.configure(function() {
app.use(express.cookieDecoder());
app.use(express.session({
secret:"HAHAHHAHAHAHAHAHAH"
}))
@xjamundx
xjamundx / mustacheMathAddOn.js
Created February 19, 2011 22:39
This was a commonJS module we played around with for node.
////
// Math Support
//
// This is an an awesome addition to mustache.js to
// add support for basic math operations. No evals!
//
// Examples:
//
// 2 == {{#math}} {{four}} / {{two}} {{/math}}
// 20 == {{#math}} 100 / 5 {{/math}}
@xjamundx
xjamundx / sencha-touch-signature.js
Created February 26, 2011 16:18
Signature Drawing Canvas Panel in Sencha Touch
(function() {
var clicked, canvas, ctx, coords, offsetX, offsetY, oldX, oldY;
app.views.Signature = Ext.extend(Ext.Panel, {
layout: {
type: 'vbox',
pack: "center",
align: "center"
},
@xjamundx
xjamundx / gist:911831
Created April 9, 2011 22:14
simple mongo collection with mongohq
~ $ mongo -u USERNAME -p PASSWORD Flame.mongohq.com:27094/wereviewutah
MongoDB shell version: 1.6.5
connecting to: Flame.mongohq.com:27094/wereviewutah
> db.logs.find()
{ "_id" : ObjectId("4da0d8a5a130714ae1000023"), "count" : 1 }
> db.logs.findOne()
{ "_id" : ObjectId("4da0d8a5a130714ae1000023"), "count" : 1 }
> db.logs.update({}, {$inc:{count:1}})
> db.logs.findOne()
{ "_id" : ObjectId("4da0d8a5a130714ae1000023"), "count" : 2 }
@xjamundx
xjamundx / express-locals.js
Created April 11, 2011 13:22
Express JS Locals
// using the res.local syntax
app.all('*', function(req, res, next) {
db.logs.findOne(function(err, logs) {
if (err) return console.log("Error: ", err);
res.local('count', logs.count);
res.local('edit', false);
next();
});
});
@xjamundx
xjamundx / db.js
Created April 11, 2011 13:27
Simple MongoDB Wrapper
////////////////////////////////////////
// Simple MongoDB Wrapper //
// Written to use with MongoHQ.com //
// By Jamund Ferguson //
// April 9, 2011
////////////////////////////////////////
var mongodb = require('mongodb'),
db;