Skip to content

Instantly share code, notes, and snippets.

View tchajed's full-sized avatar

Tej Chajed tchajed

View GitHub Profile
@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])
@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 / 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 / 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 / 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 / man.fish
Last active August 19, 2016 15:34 — forked from supermarin/.env
Colored `man` pages on OS X
# Fish users
# Save this file as ~/.config/fish/functions/man.fish
function man
env \
LESS_TERMCAP_mb=\e"[1;31m" \
LESS_TERMCAP_md=\e"[1;31m" \
LESS_TERMCAP_me=\e"[0m" \
LESS_TERMCAP_se=\e"[0m" \
LESS_TERMCAP_so=\e"[1;44;33m" \
@tchajed
tchajed / RecordUpdater.v
Last active July 23, 2018 19:53
Small library for creating record updaters in Coq
Definition Reader E T := E -> T.
Definition get {E} : Reader E E := fun e => e.
Definition pure {E T} (x:T) : Reader E T := fun _ => x.
Definition ap {E A B} (f: Reader E (A -> B)) : Reader E A -> Reader E B :=
fun x => fun e => f e (x e).
Infix "<*>" := (ap) (at level 11, left associativity).

Keybase proof

I hereby claim:

  • I am tchajed on github.
  • I am tchajed (https://keybase.io/tchajed) on keybase.
  • I have a public key ASBxd3t8HGdTAbKbOqOp5jrcJk3pusQbgsd5umQdsV0NTgo

To claim this, I am signing this object:

@tchajed
tchajed / svimrc
Last active September 17, 2019 12:20
let blacklists = ["https://mail.google.com/*", "https://docs.google.com/document/*]
let newtab = "https://www.google.com"
@tchajed
tchajed / args.sh
Last active June 1, 2022 18:47
Starting a bash script
#!/bin/bash
# basic manual argument parsing
usage() {
echo "Usage: $0 [--foo FOO] [-v]" 1>&2
}
foo=""
verbose=false