This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/ruby -w | |
################################################ | |
# Settings | |
################################################ | |
# Directory to watch | |
watch_location = "." | |
# Pattern for files to watch | |
watch_pattern = "**/*" #all files/subdirectories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function(){ | |
var instance = null; | |
function MySingleton(){ | |
if(instance !== null){ | |
throw new Error("Cannot instantiate more than one MySingleton, use MySingleton.getInstance()"); | |
} | |
this.initialize(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer