Skip to content

Instantly share code, notes, and snippets.

View jasonwyatt's full-sized avatar
:shipit:
Typing, probably

Jason Feinstein jasonwyatt

:shipit:
Typing, probably
  • Robinhood
  • Seattle, WA
  • 13:13 (UTC -07:00)
  • X @jasonwyatt
View GitHub Profile
@jasonwyatt
jasonwyatt / goodalert.js
Created December 16, 2009 23:48
Tiny javascript snippet/file to overwrite how alert usually works by forcing it to behave like console.log when possible.
/**
* Overwrites the old alert method and chooses to use console.log instead (if it's
* available).
* Author: Jason Feinstein
*/
var oldAlert = alert;
alert = function(){
if(window.console != null){
console.log.apply(null, arguments);
} else {
/**
* Permanently bind a function to an object.
*
* @param fn (function)
* Function to bind.
* @param object (object)
* Object scope to force the function to run within.
* @return
* New function, where the argument function is forced to
* execute within the scope of object.
@jasonwyatt
jasonwyatt / livesync.rb
Created January 12, 2010 20:10
Livesync
#!/opt/local/bin/ruby -w
################################################
# Settings
################################################
# Directory to watch
watch_location = "."
# Pattern for files to watch
watch_pattern = "**/*" #all files/subdirectories
@jasonwyatt
jasonwyatt / willow.js
Created February 3, 2010 19:55
Willow is a magical logging framework that makes the output to console.log be more useful when debugging issues.
/*
* Copyright (c) 2010 Jason Wyatt Feinstein
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
// 1: how could you rewrite the following to make it shorter?
bar['doSomething' + (foo ? '' : 'Else')](el);
// 2: what is the faulty logic in the following code?
// It will always print "world" to the console because foo is undefined in the
// anonymous function's closure at the time of the shortcut attempt.
dojo.require('dojo.window');
dojo.addOnLoad(function(){
var body = dojo.body(),
footerId = 'footer'; // change this to whatever your footer's id is.
function adjustFooter(){
dojo.create('div', {style: 'clear:both', id: 'adjustFooter'}, body);
var bodySize = dojo.marginBox(body),
windowSize = dojo.window.getBox(),
changes = { 'bottom': '0px', 'clear': '', 'position': 'absolute' };
// Triggers the 'onresize' event for the window manually.
if(document.createEventObject){
window.fireEvent('onresize', document.createEventObject());
} else {
var evt = document.createEvent("HTMLEvents");
evt.initEvent('resize', true, true);
window.dispatchEvent(evt);
}
@jasonwyatt
jasonwyatt / polylinefade.js
Created November 18, 2010 17:13
Fade out a google maps polyline.
function fadeOut(line, keepAround, fadeDuration){
keepAround = keepAround || 1000;
fadeDuration = fadeDuration || 500;
setTimeout(function(){
var startingOpacity = line.strokeOpacity,
startTime = (new Date()).getTime();
function step(){
var currentTime = (new Date()).getTime(),
@jasonwyatt
jasonwyatt / MySingleton.js
Created July 26, 2011 15:09
Singleton Pattern with Require JS
define(function(){
var instance = null;
function MySingleton(){
if(instance !== null){
throw new Error("Cannot instantiate more than one MySingleton, use MySingleton.getInstance()");
}
this.initialize();
}
@jasonwyatt
jasonwyatt / debouncer.js
Created September 21, 2011 15:00
How to **correctly** debounce an event that will be triggered many times with identical arguments.
function debounce(fn, debounceDuration){
// summary:
// Returns a debounced function that will make sure the given
// function is not triggered too much.
// fn: Function
// Function to debounce.
// debounceDuration: Number
// OPTIONAL. The amount of time in milliseconds for which we
// will debounce the function. (defaults to 100ms)