Skip to content

Instantly share code, notes, and snippets.

View shawntan's full-sized avatar

Shawn Tan shawntan

View GitHub Profile
@shawntan
shawntan / bashrc
Created February 13, 2011 04:09
my .bashrc
# /etc/bash/bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Test for an interactive shell. There is no need to set anything
@shawntan
shawntan / cors_scraper.rb
Created February 13, 2011 13:38
Scrapes module info from CORS and converts it into iCal. Not working right
#!/usr/bin/ruby
#
require 'mechanize'
require 'icalendar'
include Icalendar
def create_datetime(day_str,time_str)
if(time_str.length<4)
time_str = "0"+time_str
@shawntan
shawntan / slideshow.js
Created February 15, 2011 15:59
Creates a slideshow from a PicasaWeb account
var results = 5;
var slideshow_height;
var slideshow_width;
var wait_secs = 8;
var time_to_fade = 1000.0;
var picasa_url = "http://picasaweb.google.com/data/feed/api/user/"+
"rovers@mayflowerscout.org"+"?"+
"alt=json-in-script"+"&"+
"callback=slideshowRender"+"&"+
"kind=album"+"&"+
@shawntan
shawntan / event.js
Created February 15, 2011 16:00
Populates a div with events from a Google calendar.
var entries = 4;
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var re = /(-)?(\d{4})-(\d{2})-(\d{2})(T(\d{2}):(\d{2}):(\d{2})(\.\d+)?)?(([\+-])((\d{2}):(\d{2})))?/;
var cal_url = "http://www.google.com/calendar/feeds/"+
"mayflowerscout.org_slg49dbs6rt290ihtrq9oo8hm8@group.calendar.google.com/"+
"public/full?"+
"alt=json-in-script&"+
"callback=showEvents&"+
"orderby=starttime&"+
"max-results="+entries+"&"+
@shawntan
shawntan / .bashrc
Created May 11, 2011 13:43
Configuration files
# /etc/bash/bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
@shawntan
shawntan / parser.c
Created September 5, 2011 16:20
Interpreter
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*Symbol linked list*/
typedef struct Symbol{
char* identifier;
int value;
struct Symbol* next;
} Symbol;
@shawntan
shawntan / .math.pl.swp
Created September 13, 2011 16:11
See the parse tree rotation portion at the bottom.
%rotate(rotate(beside(rotate(beside(rotate(rotate(rotate(A))),rotate(rotate(A)))),rotate(beside(Expr,rotate(A))))))
tile(N,A,O):- spinit(N,A,Expr),montage(Expr,O).
spinit(0,A,A).
spinit(N,A,rotate(rotate(rotate(beside(rotate(beside(rotate(rotate(rotate(A))),rotate(rotate(A)))),rotate(beside(Expr,rotate(A)))))))):-
M is N-1,spinit(M,A,Expr),!.
ma(X=Expr;Exprs) :-
montage(Expr,X),
ma(Exprs),!.
fractal(X=Formula,N,L):-frac(X,Formula,N,Formula,L),!.
frac(_,_,0,_,L):-write('forward'),write('('),write(L),write(')'),writeln('').
frac(G,X;Xs,N,Formula,L):-frac(G,X,N,Formula,L),frac(G,Xs,N,Formula,L).
frac(G,G,N,Formula,L):-N1 is N-1,frac(G,Formula,N1,Formula,L).
frac(_,left(D),_,_,_):-write('left('),write(D),write(')'),writeln('').
frac(_,right(D),_,_,_):-write('right('),write(D),write(')'),writeln('').
@shawntan
shawntan / Distribution.java
Created October 10, 2011 13:55
Calculates probability distribution for agent doing Right,Right,Right,Up,Up
import java.text.DecimalFormat;
public class Distribution {
static char map[][] = {
{0,0,0,0},
{0,1,0,0},
{0,0,0,0}
};
//i is row