Skip to content

Instantly share code, notes, and snippets.

@omarish
omarish / gist:1107935
Created July 26, 2011 20:31
Use a custom firefox profile in Selenium RC2
#!/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)
@omarish
omarish / handler.py
Created March 28, 2011 01:37
Parse any JSON data structure into suitable javascript objects.
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)
@omarish
omarish / node.py
Created March 26, 2011 20:33
Simple JSON-Friendly Python Tree
We couldn’t find that file to show.
@omarish
omarish / screen.rc
Created March 25, 2011 23:56
My Default screen.rc file for a django project. just run screen -c screen.rc and get to work!
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
@omarish
omarish / googl.py
Created March 24, 2011 21:46
Shorten a URL using goo.gl
#!/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']
@omarish
omarish / cumsum.js
Created December 16, 2010 23:47
simple cumulative sum in javascript.
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];
}
@omarish
omarish / csv2json.py
Created November 11, 2010 00:52
Easily convert a CSV file to JSON.
#!/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")