Skip to content

Instantly share code, notes, and snippets.

View jgable's full-sized avatar

Jacob Gable jgable

  • Making Other People Money
  • Redwood City, CA
  • X @jacob4u2
View GitHub Profile
@jgable
jgable / app.js
Created April 1, 2013 17:56
Abstracting express routes
var express = require("express");
var routes = require("./lib/routes");
// You're existing code to instantiate the app.
var app = express();
// ... and configure it...
// Set your routes.
@jgable
jgable / grunt-gzip.js
Created February 7, 2013 15:32
Grunt gzip task
var fs = require("fs"),
path = require("path");
var common = require("./lib/common");
module.exports = function(grunt) {
var Ss = grunt.config("Ss"),
_ = grunt.util._,
async = grunt.util.async;
@jgable
jgable / subviews.coffee
Created February 5, 2013 17:59
Subview example for zzart
# snipped all the outer require js stuff
class InnerViewBase extends Chaplin.View # Or whatever your base view is
autoRender: true
container: "#innerViewContainer"
containerMethod: "html"
initialize: (templateName) ->
@template = require templateName
@jgable
jgable / currentTimezone.js
Last active October 12, 2015 21:39
Brief History of Time Code Examples
// Some basic javascript Date examples
// NOTE: Javascript dates have 0 indexed months, because they are awesome
// January 1, 2012 (Chicago, IL)
var firstOfYear = new Date(2012, 0, 1),
// 6 Hour offset (before DST change)
hoursOffset = firstOfYear.getTimezoneOffset() / 60;
// April 1, 2012 (Chicago, IL)
@jgable
jgable / arraysEqual.coffee
Created November 15, 2012 16:26
Arrays Equal in CoffeeScript
arraysEqual = (nums1, nums2) ->
# Check the length
return false unless nums1.length == nums2.length
# Sort the arrays
nums1.sort()
nums2.sort()
# A helper for checking indices are same
@jgable
jgable / fizzbuzz.coffee
Created November 15, 2012 15:39
FizzBuzz in CoffeeScript
isMult = (num, mult) -> (num % mult) is 0
isMult3 = (num) -> isMult num, 3
isMult5 = (num) -> isMult num, 5
fizzBuzz = (min = 0, max = 100) ->
output = (num) ->
is3 = isMult3 num
is5 = isMult5 num
@jgable
jgable / customWhen.coffee
Created October 25, 2012 13:48
$.when pseudo implementation in CoffeeScript
_when = (proms..., cb) ->
def = newPromise()
promCount = proms.length
finishProm = ->
promCount--
# May be -1 here...
unless promCount > 0
def.resolve()
@jgable
jgable / BackboneBaseViews.js
Created October 5, 2012 15:45
Backbone Disposable and SubViews
DisposableView = Backbone.View.extend({
modelUnbindAll: function() {
var modelOrCollection = this.model || this.collection;
if (modelOrCollection) {
modelOrCollection.off(null, null, this);
}
},
@jgable
jgable / greatScoping.js
Created April 25, 2012 22:27
Minimum JS - Scoping 2
// pages.Page1.js
// I like to include the file name at the top in case we ever concatenate our scripts and need to find this file to debug.
// Wrap each block of code in a self executing function.
// At the bottom, we pass in these objects to this function and immediately execute it.
(function($, window, document) {
"use strict";
// Optionally, a single string "use strict" will force strict mode and help you catch common javascript errors before they get into the wild.
// Pass in jQuery and the window object to protect from other people messing with their values.
@jgable
jgable / badScoping.js
Created April 25, 2012 22:24
Minimum JS - Scoping 1
function highlightMenu() {
// Find my the current menu item and highlight it...
};
function loadWizzyMathinger() {
// Load the almighty Wizzy Mathinger
};
function handleItemClick(evt) {