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
// document.body.scrollTop = 1; // uncomment this line and it works every time. | |
console.log(daysTop); // 15141 | |
console.log($(document).height()); // 54005 | |
document.body.scrollTop = daysTop; | |
console.log(document.body.scrollTop); // 0, sometimes, in chrome (and the page doesn't move to 15141).... | |
/* | |
if I attach the above code to a click handler, then when the bug occurs, it occurs on | |
every click until I manually scroll the page, then it starts working. |
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
function SomeBuggyInstantiatedObject() { | |
this.name = "bob"; | |
someElement.onclick = function() { | |
alert(this.name); // undefined, because this context is the click event | |
} | |
} | |
function SomeSuperCoolInstantiatedObject() { | |
var that = this; | |
this.name = "bob"; |
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 way to use module pattern along with new keyword | |
function Foo() { | |
this.baz = 4; | |
function bar() { | |
return this.baz; | |
} | |
return { | |
"bar":bar.bind(this) | |
}; | |
} |
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
/*jslint node:true*/ | |
// Usage curl localhost:8080/http://example.com | |
// - proxies the request, adding Access-control-allow-origin: * and stripping Origin and Referer headers and fixing Host | |
"use strict"; | |
var request = require("request"), | |
http = require("http"), | |
url = require("url"); | |
http.createServer(function proxy(req, res) { |
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
define(['require', 'dependency1', 'dependency2'], function (require, dependency1, dependency2) { | |
return 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
/**/ | |
someCode(); | |
goesHere(); | |
lotsOfCode(); | |
/**/ | |
// With removal/addition of just one char we can toggle commenting of the whole block: | |
/** | |
someCode(); |
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
// Succinct, does not create strictly unnecessary variables | |
// but not easy to read | |
if((a.notes && a.notes.trim() != "") && (b.notes && b.notes.trim() != "")) { | |
skip = true; | |
console.log('too many notes - skipping'); | |
} | |
// Verbose, creates two vars which are not really needed | |
// but it's instantly clear what the 'if' is doing | |
var aHasNotes = (a.notes && a.notes.trim() != ""); |
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
$ telnet couchdb portno | |
Trying [ipaddress]... | |
Connected to couchdb | |
Escape character is '^]'. | |
GET /dbname/_design/dname/_view/viewname?key="keyname"&include_docs=true&limit=20&descending=true | |
HTTP/1.1 200 OK | |
X-Couch-Request-ID: 9dc69414 | |
Server: CouchDB/1.1.1 (Erlang OTP/R14B01) | |
Etag: eb2051218277fa86006969ac40867b28 | |
Date: Mon, 17 Sep 2012 08:28:02 GMT |
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 rawAnswers = [38,264,35]; | |
// Truncate eg 12345 to 12 to account for data errors. | |
var answers = []; | |
rawAnswers.forEach(function(e, i, c) { | |
answers.push(parseInt(e.toString().substring(0,2))); | |
}); | |
var correct=0,sum=0,b=[], mode='', maxi=0; |
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
this.foo = 1; | |
console.log(this.foo); // 1 | |
function First() { | |
this.foo = 2; | |
console.log(this.foo); // 2 | |
} | |
First(); |