Skip to content

Instantly share code, notes, and snippets.

@sandywu
sandywu / gist:962190
Created May 9, 2011 07:18 — forked from tlrobinson/gist:961765
Slightly less ghetto JavaScript console bookmarklet for MobileSafari
javascript:(function(){var l,r="";while(l=prompt(r)){try{r=String(eval(l));}catch(e){r="Error: "+e}}})();
@sandywu
sandywu / tiny Promise.js
Created July 1, 2011 08:11 — forked from unscriptable/tiny Promise.js
A minimalist implementation of a javascript promise
function Promise () {
this._thens = [];
}
Promise.prototype = {
/* This is the "front end" API. */
// then(onResolve, onReject): Code waiting for this promise uses the
// then() method to be notified when the promise is complete. There
@sandywu
sandywu / erlang-scheduler.js
Created August 5, 2011 13:56 — forked from DmitrySoshnikov/erlang-scheduler.js
Simple (cooperative) processes with the Scheduler
/**
* The simplest processes (cooperative tasks) with Scheduler
* (sort of Erlang's processes but without messages yet)
* See also: http://www.dabeaz.com/coroutines/index.html
*
* Deps: JS 1.7 with generators (yield)
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*/
@sandywu
sandywu / es6proxy.htm
Created September 14, 2011 03:24 — forked from nzakas/es6proxy.htm
Example of ES6 Proxy
<!DOCTYPE html>
<!--
This is a simple experiment relying on ECMAScript 6 Proxies. To try this out,
use Aurora (http://www.mozilla.org/en-US/firefox/channel/).
The goal was to create a HTML writer where the method names were really just
the HTML tags names, but without manually creating each method. This uses
a Proxy to create a shell to an underlying writer object that checks each
method name to see if it's in a list of known tags.
@sandywu
sandywu / supr.js
Created October 26, 2011 05:20 — forked from ydaniv/supr.js
simple wrapper for the ES5 Object.create mechanism and a function that fetches overridden methods from the prototype chain.
/*
* Copyright (C) 2011 Yehonatan Daniv <maggotfish@gmail.com>
*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
*
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*
* supr.js is a simple wrapper for the Object.create mechanism of ES5,
* to ease the creation of objects via the Create function.
@sandywu
sandywu / minimalist-classes.js
Created November 2, 2011 05:38 — forked from BrendanEich/minimalist-classes.js
less minimalism, richer leather
// A response to jashkenas's fine proposal for minimalist JavaScript classes.
// Harmony always stipulated classes as sugar, so indeed we are keeping current
// JavaScript prototype semantics, and classes would only add a syntactic form
// that can desugar to ES5. This is mostly the same assumption that Jeremy
// chose, but I've stipulated ES5 and used a few accepted ES.next extensions.
// Where I part company is on reusing the object literal. It is not the syntax
// most classy programmers expect, coming from other languages. It has annoying
// and alien overhead, namely colons and commas. For JS community members who
@sandywu
sandywu / gist:1347739
Created November 8, 2011 13:30 — forked from remy/gist:350433
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@sandywu
sandywu / errorception-tracking-script-minified.html
Created November 20, 2011 06:36 — forked from rakeshpai/errorception-tracking-script-minified.html
Errorception tracking snippet - extra verbosity edition
<script>var _errs=["<application id here>"];(function(a,b){if(b.location.protocol!="https:"){a.onerror=function(a,c,b)
{_errs.push({m:a,u:c,l:b});return!1};var d=function(){var a=b.createElement("script"),
c=b.getElementsByTagName("script")[0];a.src="http://errorception.com/projects/"+_errs[0]+"/beacon.js";c.parentNode.insertBefore(a,c)};
a.addEventListener?a.addEventListener("load",d,!1):a.attachEvent("onload",d)}})(window,document);</script>
@sandywu
sandywu / flickr_action_queue.js
Created November 30, 2011 14:46 — forked from voidfiles/flickr_action_queue.js
Flickrs actionQueue code isolated
(function(F) {
var registered_ids = {},
id_to_module_map = {},
interim_actions = {},
cleanup_actions = {},
clicked_ids = {},
queueing = true;
function register_id(id, callbacks, required_module) {
id = id.replace('*', '.*');
@sandywu
sandywu / static_super.js
Created November 30, 2011 15:29 — forked from rauschma/static_super.js
Static super references in JavaScript
// Simulated static super references (as proposed by Allen Wirfs-Brock).
// http://wiki.ecmascript.org/doku.php?id=harmony:object_initialiser_super
//------------------ Library
function inherits(subC, superC) {
var subProto = Object.create(superC.prototype);
// At the very least, we keep the "constructor" property
// At most, we preserve additions that have already been made
copyOwnFrom(subProto, subC.prototype);