This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import csv | |
try: import simplejson as json | |
except: import json | |
from optparse import OptionParser | |
def main(): | |
usage = "usage: csv2json: %prog [options] arg" | |
parser = OptionParser() | |
parser.add_option("-i","--input",dest="input",help="input csv file") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cumsum = []; | |
j = [0,1,2,3,4]; | |
for(var a=0;a<j.length;a++) { | |
if(a==0) cumsum[a] = j[0]; | |
else cumsum[a] = cumsum[a-1] + j[a]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from urllib2 import urlopen, Request | |
from urllib import quote | |
from simplejson import loads | |
def shorten(url): | |
u = urlopen(Request('http://goo.gl/api/url', 'url=%s' % quote(url), {'User-Agent':'toolbar'})) | |
a = loads(u.read()) | |
return a['short_url'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hardstatus on | |
hardstatus alwayslastline | |
hardstatus string "%{.bW}%w%{.rW}%n %t^{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a " | |
startup_message off | |
defscrollback 5000 | |
altscreen on | |
autodetach on | |
sessionname mendel | |
bind ' ' windowlist -b | |
vbell off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time, math | |
def dt_handler(obj): | |
if isinstance(obj, datetime) or isinstance(obj, date): | |
v = math.floor(time.mktime(obj.timetuple())) | |
return "DATE(%d)" % v | |
else: return repr(obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from selenium import webdriver | |
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile | |
profile = FirefoxProfile( | |
profile_directory='/path/to/profile/directory/default/' | |
) | |
driver = webdriver.Firefox(firefox_profile=profile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
A1 = 'd64a84456adc959f56de6af685d0dadd' # "hard", according to google | |
B1 = '8d8a1b73876ca678cc3afa372e5199de' | |
import hashlib | |
m = hashlib.md5() | |
m.update('problems') | |
B2 = m.hexdigest() | |
print B2 == B1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import random | |
import string | |
import operator | |
from collections import defaultdict | |
class Client: | |
def __init__(self, body=None): | |
""" Initialize a client. An optional body can be passed as ``body``, | |
otherwise a random string with 100 letters will be created. """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import time | |
class timer: | |
def __enter__(self): | |
self.start = datetime.now() | |
return self | |
def __exit__(self, type, value, traceback): | |
self.end = datetime.now() |
OlderNewer