Skip to content

Instantly share code, notes, and snippets.

@sandywu
sandywu / README
Created June 30, 2012 10:31 — forked from vangberg/README
Deploying a Sinatra app to Heroku
# Deploying a Sinatra app to Heroku
## Database
The location of the database Heroku provides can be found in the environment
variable DATABASE_URL. Check the configure-block of toodeloo.rb for an example
on how to use this.
## Server
Heroku is serving your apps with thin, with means you have all your thin goodness available,
such as EventMachine.
@sandywu
sandywu / gist:1983976
Created March 6, 2012 06:03 — forked from cmoore4/gist:998126
Node.io Scraper
// This is the library that'll handle all of our input tracking and job dispatching
var nodeio = require('node.io');
// The base_url is the site you want to crawl.
// Links is an array of all the links seen as <a> tags, but not yet scraped.
// crawled_links is the array of all the pages already scraped.
var base_url = 'http://reddit.com',
links = [base_url],
crawled_links = [];
var fs = require('fs'),
sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
checkBalanceFile(req, res);
}).listen(8000);
function checkBalanceFile(req, res) {
fs.stat("balance", function(err) {
@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);
@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 / 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 / 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 / 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 / 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 <[email protected]>
*
* 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 / 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.