Skip to content

Instantly share code, notes, and snippets.

View ejamesc's full-sized avatar

Cedric Chin ejamesc

View GitHub Profile
public StoreAndValue eval(Store s, Environment e) {
for (LetDefinition d : definitions) {
int loc = s.newLocation();
e = e.extend(d.variable, loc);
s = s.extend(loc, d.rightHandExpression.eval(s, e).value);
}
return body.eval(s, e);
}
@ejamesc
ejamesc / gist:2036847
Created March 14, 2012 14:28
Tweet Stream
#!/usr/bin/env python
"""Use Twitter's streaming API to grab tweets.
Requires the tweetstream lib as a dependency
"""
import tweetstream
from sgbeat.database import Connection
from details import (
USERNAME,
PASSWORD,
@ejamesc
ejamesc / gist:2017178
Created March 11, 2012 17:22
Exposes escape_string on Tornado's MySQL wrapper
def escape_string(self, string):
"""Exposes the MySQL escape_string function
Escapes the given string for saving into the db
"""
import MySQLdb
return MySQLdb.escape_string(string)
@ejamesc
ejamesc / gist:1937574
Created February 29, 2012 04:05
File Reading Writing in Go
import "os"
// filepath is a string containing the filepath (no duh)
// os.O_RDWR = read write flag, //os.O_CREATE = create if file not exist flag
fl, flErr := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0666)
if flErr != nil {
fmt.Println("File write error:", flErr)
}
defer fl.Close()
// for a string named output, write it
@ejamesc
ejamesc / gist:1697660
Created January 29, 2012 07:22
So far, failed.
import sys
import tweepy
auth1 = tweepy.auth.OAuthHandler('TRiKhYeNtbNpYFFP2IzLNw','L4oxb6sYbO0xnNDPfvb2YzyhssZX3PavKibt8enkuU') #Replace 'Consumer Key' and 'Consumer Secret' with required authorization keys
auth1.set_access_token('391314557-6dCHNYx6jud1MsHY9zr4taBM31RUAVthsFO2ondw','50mDNQfei6gVTatuZYY1uskNvvtBHR2X8MwCggl7Dw') #Key 'Access Token' and 'Access Token Secret' with required authorization keys
api = tweepy.API(auth1)
class StreamListener(tweepy.StreamListener):
def on_status(self, status):
print 'blah'
try:
tweet = status.text
@ejamesc
ejamesc / gist:1578182
Created January 8, 2012 12:25
Buggy Output
2012-01-08 06:11:50-0600 [cors] DEBUG: Crawled (200) <GET https://aces01.nus.edu.sg/cors/jsp/report/ModuleDetailedInfo.jsp?acad_y=2011%2F2012&mod_c=ID1223&sem_c=2> (referer: https://aces01.nus.edu.sg/cors/jsp/report/ModuleInfoListing.jsp)
2012-01-08 06:11:50-0600 [cors] DEBUG: Scraped from <200 https://aces01.nus.edu.sg/cors/jsp/report/ModuleDetailedInfo.jsp?acad_y=2011%2F2012&mod_c=ID1223&sem_c=2>
{'code': u'ID1223',
'desc': 'This module serves to introduce students to the development of thoughts and ideas in industrial and product design. It will enable students to relate recent history in technological advancement and product development to current trends in design. The module will concentrate on the design innovations from the period of the industrial revolution in the 19th century. This was the transitional period from the Arts and Craft movement to the current design and production methods that are dominated by industrial processes.',
'exam': {'date': '2012-05-02', 'time': u'PM'},
'lecture_time_t
@ejamesc
ejamesc / gist:1450495
Created December 9, 2011 06:38
Supervisord conf to daemonize Mongodb
[program:mongodb]
directory=/home/username/webapps/appname
command=/home/username/webapps/mongodb-appname/mongodb-linux-i686-2.0.1/bin/mongod --dbpath /home/username/webapps/mongodb-appname/data --logpath /home/username/webapps/mongodb-appname/log/corsdb.log --logappend --port 34006
@ejamesc
ejamesc / gist:1447649
Created December 8, 2011 17:09
libxml problems in webfaction
cd $HOME
mkdir -p bin lib/python2.6 src tmp
cat > ~/.pydistutils.cfg << EOF
[build_ext]
include_dirs=$HOME/include
library_dirs=$HOME/lib
EOF
export PATH=$HOME/bin:$PATH
export TEMP=$HOME/tmp
export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
@ejamesc
ejamesc / gist:1447330
Created December 8, 2011 15:37
Timetables
{
"tutorial_time_table": [
{"name": "TUTORIAL Class [1]",
"sessions": [
{"starttime": "1000",
"endtime": "1200",
"occurence": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
"day": 2,
"location": "I3/3-47"}
]},
@ejamesc
ejamesc / gist:1447325
Created December 8, 2011 15:36
Single Module
{
'code': 'CH2223',
'mc': '4',
'name': 'Chinese Fiction',
'desc': 'This module is designed to acquaint students with the historical evolution and characteristics of ancient Chinese fiction. It covers different genres of the fictional narrative tradition, zhiguai, zhiren, Tang chuanqi short tale, huaben colloquial short story and full-length xiaoshuo. The course is open to students across the University with an interest in Chinese literary tradition and particularly in Chinese fiction.',
'exam': {'date': '2012-04-30', 'time': 'EVENING'},
'lecture_time_table': [
{'name': 'LECTURE Class [1]',
'sessions': [
{'day': 3,