This file contains hidden or 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
// Usage: | |
// Put this in a separate file and load it as the first module | |
// (See https://github.com/jrburke/requirejs/wiki/Internal-API:-onResourceLoad) | |
// Methods available after page load: | |
// rtree.map() | |
// - Fills out every module's map property under rtree.tree. | |
// - Print out rtree.tree in the console to see their map property. | |
// rtree.toUml() | |
// - Prints out a UML string that can be used to generate UML | |
// - UML Website: http://yuml.me/diagram/scruffy/class/draw |
This file contains hidden or 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
//src http://stackoverflow.com/questions/5529718/how-to-detect-internet-speed-in-javascript?rq=1#answer-5529841 | |
//JUST AN EXAMPLE, PLEASE USE YOUR OWN PICTURE! | |
var imageAddr = "http://www.kenrockwell.com/contax/images/g2/examples/31120037-5mb.jpg"; | |
var downloadSize = 4995374; //bytes | |
window.onload = function() { | |
var oProgress = document.getElementById("progress"); | |
oProgress.innerHTML = "Loading the image, please wait..."; | |
window.setTimeout(MeasureConnectionSpeed, 1); | |
}; |
This file contains hidden or 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
'use strict'; | |
function lineReader(fileName){ | |
var EM = require("events").EventEmitter, | |
ev = new EM(), | |
stream = require("fs").createReadStream(fileName), | |
remainder = null; | |
stream.on("data",function(data){ | |
if(remainder !== null){//append newly received data chunk | |
var tmp = new Buffer(remainder.length+data.length); |
This file contains hidden or 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
myModel = Backbone.Model.extend({ | |
initialize: function(){ | |
}, | |
set: function(attributes, options) { | |
//do something with the attributes | |
Backbone.Model.prototype.set.call(this, attributes, options); | |
}, | |
get: function(key) { |
This file contains hidden or 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 someView = Backbone.View.extend({ | |
initialize: function(options) { | |
}, | |
events: { | |
'keyup .error': 'validateField' | |
}, | |
validateField: function(e){ | |
$(e.currentTarget).valid(); | |
}, | |
render: function(){ |
This file contains hidden or 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
// A simple module to replace `Backbone.sync` with *localStorage*-based | |
// persistence. Models are given GUIDS, and saved into a JSON object. Simple | |
// as that. | |
// Generate four random hex digits. | |
function S4() { | |
return (((1+Math.random())*0x10000)|0).toString(16).substring(1); | |
}; | |
// Generate a pseudo-GUID by concatenating random hexadecimal. |
This file contains hidden or 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
// Generate four random hex digits. | |
function S4() { | |
return (((1+Math.random())*0x10000)|0).toString(16).substring(1); | |
}; | |
// Generate a pseudo-GUID by concatenating random hexadecimal. | |
function guid() { | |
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); | |
}; |