Skip to content

Instantly share code, notes, and snippets.

@shreyansb
shreyansb / gist:1003952
Created June 2, 2011 04:56
an hourly reminder to look away from the screen.
55 * * * * /usr/local/bin/growlnotify -m "take a quick break. look away" --image "/Users/shreyans/Pictures/wallpaper/langkawi_beach_small.jpg" --wait > /dev/null 2>&1
@shreyansb
shreyansb / gist:1154210
Created August 18, 2011 14:50
git branch and cleanliness status in the bash prompt
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
parse_git_branch() {
git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
PROMPT_COMMAND='CurDir=`pwd|sed -e "s!$HOME!~!"|sed -E "s!([^/])[^/]+/!\1/!g"`'
PS1='[\u@\h $CurDir $(parse_git_branch)]\$ '
@shreyansb
shreyansb / linksys_router_connections.py
Created September 18, 2011 05:53
Get a list of MAC addresses that have connected to your router. Most recent first.
import os
import re
import datetime
def get_connections():
curl_cmd = "curl -s -u username:password http://192.168.1.1/Log_View.asp | grep 'received REQUEST'"
# TODO replace with subprocess.Popen()
resp = os.popen4(curl_cmd)[1].read()
resp = resp.split('\n')
connections = []
@shreyansb
shreyansb / RequestSigner.py
Created September 19, 2011 19:12
Sign and verify requests
import hmac
import base64
import hashlib
# simplejson is available at: http://pypi.python.org/pypi/simplejson/
import simplejson as json
class RequestSigner(object):
def verify_and_load_signed_request(self, signed_request, secret):
"""Verify the signature, and return decoded data from a signed_request value"""
try:
@shreyansb
shreyansb / call_via_facetime.py
Created September 23, 2011 18:00
make a facetime call using python
import os; import appscript; import time
os.popen('open facetime://6461234567')
appscript.app('FaceTime').activate(); time.sleep(2); appscript.app('System Events').keystroke('\r')
@shreyansb
shreyansb / terminals_webscraper.py
Created September 28, 2011 17:51 — forked from ashaegupta/terminals_webscraper.py
Scrapes web for airline arrival terminals
import urllib2
from BeautifulSoup import BeautifulSoup
airport_list = ["jfk", "ewr", "lga"]
def getAllTerminals():
terminals = {}
for airport in airport_list:
terms = klass._getTerminals(airport)
@shreyansb
shreyansb / gist:1281825
Created October 12, 2011 16:58
converting between datetime objects and timestamps
import time
import datetime
def datetime_to_timestamp(datetime_ob):
return time.mktime(datetime_ob.timetuple())
def datetime_from_timestamp(timestamp):
return datetime.datetime.fromtimestamp(timestamp)
@classmethod
def get_matches_for_status_matched(klass, ride_doc):
ride=[]
# first ensure status is matched
if ride_doc.get(Ride.A_STATUS) != 2: return ride
# get the match ride and user info
match_ride_id = ride_doc.get(Ride.A_MATCH_ID)
if not match_ride_id: return ride
@shreyansb
shreyansb / gist:1299071
Created October 19, 2011 17:42
intro to screen
# create screen. can optionally specify the process to run in it here,
# or can do that when the screen has started
$ screen -S firstscreen
# run a process in it
(inscreen)$ processone
# get out of the screen: 'ctrl-a + d' ('d' for detach)
> ctrl-a + d
[detached from 24550.firstscreen]
@shreyansb
shreyansb / gist:1308278
Created October 24, 2011 03:08
interactive python tip
>>> import math
>>> math.pi / 3
1.0471975511965976
>>> angle = _
>>> math.cos(angle)
0.50000000000000011
>>> _
0.50000000000000011