Skip to content

Instantly share code, notes, and snippets.

View samtsai's full-sized avatar
🏠
Working from home

Sam Tsai samtsai

🏠
Working from home
View GitHub Profile
@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
@tkersey
tkersey / Undo a commit and redo
Created October 8, 2010 22:36
Git: undo a commit and redo
http://stackoverflow.com/questions/927358/git-undo-last-commit
Undo a commit and redo
$ git commit ...
$ git reset --soft HEAD^ (1)
$ edit (2)
$ git commit -a -c ORIG_HEAD (3)
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset".
@cburgmer
cburgmer / validator-steps.py
Created April 17, 2011 13:52
Using Selenium to validate XHTML markup using lettuce
# -*- coding: utf-8 -*-
import re
from lettuce import world, step, before
from lettuce_webdriver.util import find_field
from lettuce_webdriver import webdriver # We need this to register "I visit..."
from nose.tools import assert_true
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
@before.all
@fwielstra
fwielstra / api.js
Created June 14, 2011 14:46
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@jumski
jumski / backbone_sync_hack.coffee
Created August 5, 2011 17:10
BackboneJS sync hack to namespace params when saving/updating model
###
Usage:
* add model.name property that will be used as a namespace in the json request
* put this code before your Backbone app code
* use toJSON() as usual (so there is no namespacing in your templates)
* your model's data will be sent under model.name key when calling save()
###
# save reference to Backbone.sync
Backbone.oldSync = Backbone.sync
@wsargent
wsargent / gist:1258640
Created October 3, 2011 07:46
Setting up a base vagrant box for Oracle
Install instructions for 10.2:
http://download.oracle.com/docs/cd/B19306_01/relnotes.102/b15666/toc.htm
http://download.oracle.com/docs/cd/B19306_01/install.102/b15667/toc.htm
[Required files]
10201_database_linux_x86_64.cpio.gz
10201_companion_linux_x86_64.cpio.gz
p6810189_10204_Linux-x86-64.zip
@jswartwood
jswartwood / index.html
Created January 6, 2012 14:30
Hiccup?
<!DOCTYPE html>
<html>
<body>
<p>These should output "last", "ok", then "all" for 10 promises and then another 10.</p>
<div id="out"></div>
<script type="text/javascript" src="https://raw.github.com/briancavalier/when.js/dev/when.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
@phatblat
phatblat / heroku-node-init.sh
Created January 31, 2012 22:28
Bash script to initialize an OS X box for local development of node app on heroku
#!/bin/bash
NODE_VERSION=0.4.7
NPM_VERSION=1.0.94
# Save script's current directory
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#cd "${DIR}"
#
@jswartwood
jswartwood / Run in LOCAL terminal...
Created February 19, 2012 01:53
Automatic Git deploys on Dreamhost
# Replace any brackets with real values
# Try to ssh in to DREAMHOST (ensure it no longer asks for a PW); you may want to restart Terminal
ssh [user]@[host]
cd ~
mkdir [mydomain_com].git
cd [mydomain_com].git
git init --bare
vi hooks/post-receive
# Enter the code from the "post-receive" file (in this gist); save + quit