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
/* | |
* Simple Pub/Sub Implementation for jQuery | |
* | |
* Inspired by work from Peter Higgins (https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js) | |
* | |
* This is about the simplest way to write a pubsub JavaScript implementation for use with jQuery. | |
*/ | |
(function($) { | |
// Cache of all topics |
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
body::before | |
content: '< 480px' | |
@media only screen and (min-width: 480px) | |
body::before | |
content: '480px < 600px' | |
@media only screen and (min-width: 600px) | |
body::before | |
content: '600px < 768px' |
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
/* | |
* LinkedList | |
* Very simple LinkedList implementation | |
*/ | |
function Node(item, next) { | |
this.item = item; | |
this.next = next; | |
} |
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
var Plan = (function() { | |
// protected | |
var records = []; | |
// the Plan constructor | |
function Plan(id, price) { | |
this.id = id; | |
this.price = price; | |
records.push(this); |
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
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm') | |
begin | |
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME'])) | |
rvm_lib_path = File.join(rvm_path, 'lib') | |
#$LOAD_PATH.unshift rvm_lib_path | |
require 'rvm' | |
RVM.use_from_path! File.dirname(File.dirname(__FILE__)) | |
rescue LoadError | |
raise "RVM ruby lib is currently unavailable." | |
end |
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
var start = new Date(); | |
setTimeout(function () { var end = new Date(); console.log("Timeout 3ms elapsed:", end - start, "ms"); }, 3); | |
setTimeout(function () { var end = new Date(); console.log("Timeout 2ms elapsed:", end - start, "ms"); }, 2); | |
setTimeout(function () { var end = new Date(); console.log("Timeout 1ms elapsed:", end - start, "ms"); }, 1); | |
while( new Date() - start < 2000 ) {} | |
setTimeout(function () { var end = new Date(); console.log("Timeout 0ms elapsed:", end - start, "ms"); }, 0); |
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
squareRoot = ( num ) -> | |
square = ( x ) -> x * x | |
avg = ( x, y ) -> (x + y) / 2 | |
goodEnough = ( x ) -> Math.abs( square( x ) - num ) < 0.01 | |
improveGuess = ( x ) -> avg( x, num/x ) | |
iter = ( guess ) -> | |
return guess if goodEnough guess | |
iter improveGuess guess | |
iter 1.0 |
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 longestCommonPrefix ( arr ) { | |
var result = ""; | |
var firstWord = arr[0]; | |
for ( var i = 0; i < firstWord.length; i++ ) { | |
for ( var j = 0; j < arr.length; j++) { | |
if ( firstWord[i] === arr[j][i]) { | |
continue; | |
} else { | |
return result; |
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 Foo () { | |
this.a = []; | |
} | |
+function Bar () { | |
+ Foo.call(this); | |
+} | |
-function Bar () {} | |
Bar.prototype = new Foo(); |
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
var inspect = require('util').inspect, // To help with printing to console | |
log = console.log; | |
// Define class Foo | |
function Foo () { | |
this.a = []; | |
} | |
// Define class Bar which inherits from Foo | |
function Bar () {} |
NewerOlder