Skip to content

Instantly share code, notes, and snippets.

// 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
//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);
};
@j-5-s
j-5-s / lineReader.js
Created September 26, 2012 12:32
Node Line Reader (Stream for large files)
'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);
@j-5-s
j-5-s / backbone-method-extensions.js
Created March 10, 2012 11:29
Extending Backbone Methods
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) {
@j-5-s
j-5-s / SomeBackboneView.js
Created September 11, 2011 12:28
how to use backbone and jquery validator together
var someView = Backbone.View.extend({
initialize: function(options) {
},
events: {
'keyup .error': 'validateField'
},
validateField: function(e){
$(e.currentTarget).valid();
},
render: function(){
@j-5-s
j-5-s / backbone-localstorage.js
Created July 11, 2011 01:57
backbonejs local storage adapter
// 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.
@j-5-s
j-5-s / localstorage.js
Created July 11, 2011 01:55 — forked from juliocesar/localstorage.js
Backbone.js localStorage if specified
// 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());
};