Skip to content

Instantly share code, notes, and snippets.

View jgable's full-sized avatar

Jacob Gable jgable

  • Making Other People Money
  • San Carlos, CA
  • X @jacob4u2
View GitHub Profile
@jgable
jgable / timerPageSnip-Bug.js
Created March 8, 2012 01:07
Magnitude Blog Post Code
SurveyTimersPage.prototype.updateTimerQuestionResponse = function () {
var newResponseId = null;
if (this.timerMgr.hasValuesEntered()) {
// Update this questions response to the timer measurement response.
var resp = this.surveyMgr.getCorrectResponse(this.timerQuestion.AllowableValues);
if (resp !== null) {
newResponseId = resp.id;
@jgable
jgable / quickClass.js
Created April 18, 2012 23:19
Minimum JS - Classes 1
// The quick and dirty way
var baby1 = {
name: "cutesy",
sex: "F",
speak: function() {
return "gaga"; // As in Lady
}
};
// Functionally equivalent to this...
@jgable
jgable / prototypeClass.js
Created April 18, 2012 23:21
minimum JS - Classes 2
// The classical prototype way
/* Define a constructor */
function Baby(name, sex, says) {
// Set some variables on the object
this.name = name;
this.sex = sex;
this.says = says;
}
@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) {
@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 / 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 / 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 / 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 / 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 / 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)