Skip to content

Instantly share code, notes, and snippets.

@james-gardner
james-gardner / grunt.js
Last active December 19, 2015 21:19
Basic attempt at a grunt file that concatenates and minifies CSS (from LESS) and JavaScript into a folder based upon the given version label.
var path = require("path");
module.exports = function(grunt) {
grunt.initConfig({
less: {
options: {
yuicompress : true
},
desktop : {
files: {
@james-gardner
james-gardner / a.js
Last active August 29, 2015 13:56
Vanilla Examples
var i, len, list, main, item;
var onItemClicked = function (e) {
var i = 0, len = devices.length;
for(i = 0; i < len; i++) {
if(devices[i].name === e.target.innerText) {
devices[i].status = (devices[i].status === 'in') ? 'out' : 'in';
console.log(devices[i].status);
}
@james-gardner
james-gardner / queue.js
Created February 14, 2014 15:03
Idea for a simple $.Deferred queue
var Queue = function () {
this.initialize.apply(this, arguments);
};
var p = Queue.prototype;
p.initialize = function () {
_.bindAll(this, ['check']);
this.items = [];
var Item = function (obj) {
this.children = [];
_.extend(this, obj);
};
var p = Item.prototype;
p.add = function (obj) {
this.children.push(new Item(obj));
return _.last(this.children);
function (number, country) {
var req, valid = $.Deferred();
req = $.ajax({
type : 'GET',
url : '/api/v3/validation-url',
dataType : 'json',
data : {
phonenumber : number,
countryid : country
@james-gardner
james-gardner / DummyCollection.js
Last active August 29, 2015 14:00
Testing Backbone with Jasmine 2 and Sinon (RequireJS)
define(['backbone', 'dummy/models/DummyModel'], function (Backbone, DummyModel) {
var Collection = Backbone.Collection.extend({
url : '/dummies',
model : DummyModel
});
return Collection;
});
@james-gardner
james-gardner / blueprint.js
Created October 30, 2014 22:28
First attempt at mocking an API using mockjax and factories
(function (global) {
var Blueprint = function () {
};
var p = Blueprint.prototype;
p.generate = function (api) {
var obj = {}, template = this.template(api);
@james-gardner
james-gardner / wrapper.js
Created November 6, 2014 14:04
Cherry pick and pre-bind underscore methods (borrowed from backbone)
var Url = function (url) {
this._url = url;
};
_.extend(Url.prototype, {
/* more prescriptive methods */
});
var methods = ['forEach', 'each', 'map', 'find', 'detect', 'filter',
'select', 'reject', 'every', 'all', 'some', 'any', 'include',
@james-gardner
james-gardner / initializers.js
Last active August 29, 2015 14:09
Example application initializers
/**
* Initialization could be broken down into swappable blocks (which could be turned on or off).
* Point is, the init sequence is more controllable if it's broken out into phases/functions.
*
* This is how it's done within Marionette:
* https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.application.js
*
* http://jsfiddle.net/agoftkng/5/
*/
var App = function() {
@james-gardner
james-gardner / console.js
Last active August 29, 2015 14:10
console wrapper
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(function() {
return (root.Logger = factory());
});
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Logger = factory();
}