Skip to content

Instantly share code, notes, and snippets.

🐢
Turtles all the way

Marc Harter wavded

🐢
Turtles all the way
Block or report user

Report or block wavded

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View proto_inheritance.js
// Prototypal Inheritance (this function will eventually be in the JavaScript language)
if (typeof Object.create !== 'function') {
Object.create = function(o) {
function F() {}
F.prototype = o;
return new f();
}
}
View xhtml_base.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
</body>
</html>
View singleton.js
var singleton = function() {
var privateVariable;
function privateFunction(x){
//privateVariable
}
return {
firstMethod: function(a, b) {
//privateVariable
},
secondMethod: function(a) {
View gist:252771
/*
evaluates as a block — "{" and "}" — containing one labeled statement — `a:"a"`.
labeled statement, in its turn, evaluates to "a".
*/
{a:"a"}
/*
evaluates as an expression, where "(" and ")" are grouping operator and "{" and "}" constitute an object literal.
evaluates to this object value.
View gist:252777
/* in few words:no round brackets=function or object, round brackets:anything, arguments.callee included.diff is the left assignment */
var a = function(){return 1}(); // 1
var b = function(){return {}}(); //object
function(){return 1}(); //error
function(){return {}}(); //error
var c = (function(){return arguments.callee})(); //function
var d = (function(){return []})(); //array
View gist:253421
var a = {};
//to note: nothing is passed in and no private variables/functions/etc. on purpose
var b = (function(){
return {};
})();
/*
Is there any difference between a and b in regards to scope/execution? Any advantage one has over the other? (besides like arguments.callee/recursive stuff);
*/
View geolocation.js
if (!navigator.geolocation) {
navigator.geolocation = (function (window) {
function getCurrentPosition(callback) {
// NOTE: for some reason, chaging the url is *allowed* with this service. Useful, but random
// source: http://www.maxmind.com/app/javascript_city
// The source is open source, as per: http://www.maxmind.com/app/api, but doesn't discuss specific license use. Hopefully it's just free to use - yay internet!
var geourl = 'http://j.maxmind.com/app/geoip.js_' + Math.random(),
iframe = document.createElement('iframe'),
doc, win;
View crockfordfacts.js
var sys = require("sys")
var http = require("http");
var twitter = http.createClient(80, "search.twitter.com");
var count = 10
for (var i = 1; i <= count; i++) {
var request = twitter.request("GET", "/search.json?q=crockfordfact+OR+crockfordfacts&rpp=100&page=" + i, {"host": "search.twitter.com"});
request.addListener('response', function(response) {
View localStorage wrapper
/* Overwrite localStorage w/ cookie-based storage if browser does not support */
if(typeof localStorage === "undefined" || localStorage === null){
(function(){
function getExpiration(isRemove){
var date = new Date();
if(isRemove){
date.setTime((+date)-1000); //sometime in past
} else {
date.setTime((+date)+30758400000); //356 days ahead
}
View node-proxy-server
//sample proxy server for node.js from http://www.catonmat.net/http-proxy-in-nodejs
var http = require('http');
http.createServer(function(request, response) {
var proxy = http.createClient(80, request.headers['host'])
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.addListener('response', function (proxy_response) {
proxy_response.addListener('data', function(chunk) {
response.write(chunk);
You can’t perform that action at this time.