Skip to content

Instantly share code, notes, and snippets.

View tchajed's full-sized avatar

Tej Chajed tchajed

View GitHub Profile
@tchajed
tchajed / basic-re.py
Last active August 12, 2016 12:57
Python re examples
import re
# match requires the entire string to match, while search will
# find a partial match
assert re.match("\d+", "123")
assert not re.match("\d+", "hello 123")
assert re.search("\d+", "123")
assert re.search("\d+", "hello 123")
@tchajed
tchajed / lambda-calculus.hs
Last active February 23, 2022 20:42
Parsec parser for the untyped lambda calculus
import Text.ParserCombinators.Parsec
import System.Environment (getArgs)
import Safe
data Expr =
Var Name -- variable
| App Expr Expr -- application
| Lambda Name Expr -- lambda abstraction
deriving
(Eq,Show)
@tchajed
tchajed / coords.py
Last active August 29, 2015 14:23
Parse a CSV file of coordinates in Python
import csv
""" Read a CSV file of points.
Assumes each line of the file is a CSV list of coordinates, which are parsed as
floats.
"""
def read_coords(fname):
with open(fname, 'rb') as f:
points = []
@tchajed
tchajed / chrome_load.js
Created May 25, 2012 16:29
jQuery tricks
// ==UserScript==
// @name jQuery For Chrome (A Cross Browser Example)
// @namespace jQueryForChromeExample
// @include *
// @author Erik Vergobbi Vold
// @description This userscript is meant to be an example on how to use jQuery in a userscript on Google Chrome.
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
@tchajed
tchajed / sessions.js
Created May 17, 2012 03:01
handling sessions in socket.io
// from https://github.com/LearnBoost/Socket.IO/wiki/Migrating-0.6-to-0.7+
// saving the socket id
var sid = socket.id
// sending a message to a particular socket
io.socket(sid).emit("my event", [args])