Skip to content

Instantly share code, notes, and snippets.

View wavded's full-sized avatar
🐢
Turtles all the way

Marc Harter wavded

🐢
Turtles all the way
View GitHub Profile
// 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();
}
}
<!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>
var singleton = function() {
var privateVariable;
function privateFunction(x){
//privateVariable
}
return {
firstMethod: function(a, b) {
//privateVariable
},
secondMethod: function(a) {
@wavded
wavded / gist:252771
Created December 9, 2009 20:17 — forked from kangax/gist:252265
/*
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.
/* 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
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);
*/
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;
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) {
/* 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
}
//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);