Skip to content

Instantly share code, notes, and snippets.

View shiawuen's full-sized avatar

Tan Shiaw Uen shiawuen

View GitHub Profile
@remy
remy / gist:350433
Created March 31, 2010 14:58
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();
@tbtlr
tbtlr / get_barcode_from_image.js
Created June 1, 2010 19:33
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active November 2, 2024 12:56
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@cowboy
cowboy / HEY-YOU.md
Last active October 25, 2024 15:29
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@creationix
creationix / chatServer.js
Created November 19, 2010 20:47
A simple TCP based chat server written in node.js
// Load the TCP Library
net = require('net');
// Keep track of the chat clients
var clients = [];
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client
@statianzo
statianzo / jade.vim
Created November 20, 2010 03:51
Jade syntax highlighting for vim
" Vim syntax file
" Language: Jade
" Filenames: *.jade
" Ported from tvim-haml - https://github.com/tpope/vim-haml
" For use with Jade - http://jade-lang.com/
" Now maintained at: https://github.com/statianzo/vim-jade
if exists("b:current_syntax")
finish
endif
@getify
getify / gist:710231
Created November 22, 2010 16:48
how to detect IE from JavaScript using conditional comments
// stripped down version just detecting IE
(function(global){
global._isIE = false;
try {
var div = document.createElement("div");
div.innerHTML = "<!--[if IE]><i></i><![endif]-->";
global._isIE = (div.getElementsByTagName("i").length > 0);
} catch(err) { }
})(window);
@creationix
creationix / superhack.js
Created November 23, 2010 01:09
A probably evil hack to get working super in any function.
// Add a handy super call for all objects
MyBaseClass.prototype.super = function () {
var parent = this.__proto__.__proto__;
var caller = arguments.callee.caller;
var fn;
if (caller.prototype === this.__proto__) {
fn = parent.constructor;
} else {
// This is probably quite slow, but it doesn't seem to affect
// performance too much in real tests.
@creationix
creationix / _README.markdown
Created November 29, 2010 19:50
Rectify Challenge

Rectify

Takes a grid and returns an optimal set of rectangles that fills that grid

For example, the following grid:

[[1,1,0,1,1],
 [1,1,1,1,1],
 [0,1,1,1,0]]