Skip to content

Instantly share code, notes, and snippets.

View shawntan's full-sized avatar

Shawn Tan shawntan

View GitHub Profile
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@shawntan
shawntan / .vimrc
Created February 10, 2012 03:25
.vimrc
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <[email protected]>
" Last change: 2008 Dec 17
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
find . \( ! -regex '.*/\..*' \) -and -iname '*~' -exec rm {} \;
#
# /etc/makepkg.conf
#
#########################################################################
# SOURCE ACQUISITION
#########################################################################
#
#-- The download utilities that makepkg should use to acquire sources
# Format: 'protocol::agent'
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import random,nltk,string,itertools
from nltk.corpus import stopwords
from nltk.corpus import movie_reviews
from nltk.corpus.reader.plaintext import CategorizedPlaintextCorpusReader
from nltk.stem.porter import PorterStemmer
web_words = ['www','http','ftp','com','html','org']
eng_stopwords = stopwords.words('english')
stemmer = PorterStemmer()
@shawntan
shawntan / gist:3234285
Created August 2, 2012 06:06
Using Gnuplot with parameters.
#!/bin/bash
args=("$@")
GRAPHS="\"< sed 's/^/$#\t/g' '${args[$i]}'\" using 2:1 title \"Posts\" with lp"
for ((i=1; i < ${#}; i++)) {
j=`echo $# - $i | bc`
GRAPHS="$GRAPHS, \"< sed 's/^/$j\t/g' '${args[$i]}'\" using 2:1 title \"${args[$i]}\" with lp"
}
:-lib(ic).
:-lib(branch_and_bound).
search(Students,Projects,Ranks,Capacity,Assignments,Cost) :-
minimize(
(
delete(_,Projects,Projects1),
delete(_,Projects1,RemainingProjects),
writeln(RemainingProjects),
@shawntan
shawntan / config.py
Created September 24, 2012 16:19
Configuration file to object
import ConfigParser
from collections import namedtuple
sections = ['dirs']
def subconf(section):
Conf = namedtuple(section,(k for k,_ in c.items(section)))
conf = Conf(**dict(c.items(section)))
return conf
c = ConfigParser.RawConfigParser(allow_no_value=True)
c.readfp(open('config','r'))
PConf = namedtuple('Configuration',sections)
'''
Created on Sep 24, 2012
@author: shawn
'''
import __builtin__
_open = __builtin__.open
def marked_open(*params):
global _open
print "Opening file with marked_open", params[1]
@shawntan
shawntan / pickled_globals.py
Created September 25, 2012 16:18
Accessing pickled files as attributes of an object
import cPickle as pickle
class pickled_globals(object):
def __init__(self,pg_dir):
self.pg_dir = pg_dir
def __getattr__(self, attr_name):
"""
Loads the file from pg_dir into an object,
then caches the object in memory.
"""
obj = pickle.load(open('%s/%s'%(self.pg_dir,attr_name),'rb'))