This file contains hidden or 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
"""Script to format the conversation text copied from skype window for better readability. | |
""" | |
import sys | |
import re | |
import web | |
re_timeline = re.compile("^([^/]* )?((?:\d\d/\d\d/\d\d )?\d\d?:\d\d [AP]M) *$") | |
def parse_text(text): | |
lines = text.strip().splitlines() |
This file contains hidden or 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 json | |
import urllib | |
def jsonget(url): | |
text = urllib.urlopen(url).read() | |
return json.loads(text) | |
def get_edition(key): | |
url = "http://openlibrary.org" + key + ".json" |
This file contains hidden or 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
"""Prototype of liveweb proxy. | |
""" | |
def get_recent_crawl_location(url): | |
"""Looks at memcache to find the location of the recent crawl of the given URL. | |
""" | |
return memcache_client.get(md5sum(url)) | |
def fetch(url): | |
"""Fetches a url from liveweb. |
This file contains hidden or 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
Liveweb is a http proxy. | |
Request: | |
GET http://www.example.com/foo.html HTTP/1.1 | |
Header1: Value1 | |
Header2: Value2 | |
Response: | |
This file contains hidden or 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
"""I suspect that there is a race condition in datetime module. | |
When I ran the following code in a multi-threading application: | |
datetime.datetime.strptime('20120509100335', "%Y%m%d%H%M%S") | |
I've noticed the following error in the log. | |
Traceback (most recent call last): | |
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner |
This file contains hidden or 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 threading | |
def count(): | |
i = 0 | |
while True: | |
i += 1 | |
yield i | |
class Counter: | |
def __init__(self): |
This file contains hidden or 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 sys | |
# Uses httplib2 by default. | |
# Pass "--requests" command-line arg to use requests. | |
if "--requests" in sys.argv: | |
import requests | |
requests.get("https://auth.hasgeek.com/").content | |
else: | |
import httplib2 |
This file contains hidden or 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
#lang racket | |
; Tail-recursive implementation of map | |
(define (map f xs) | |
(define (map-iter xs result) | |
(if (null? xs) | |
(reverse result) | |
(map-iter (cdr xs) (cons (f (car xs)) result)))) | |
(map-iter xs '())) |
This file contains hidden or 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
# BSNL | |
# Primary DNS Server: 218.248.245.1 | |
# Secondary DNS Server: 218.248.255.141 | |
# | |
# In this case the secondary DNS server looks unhealthy. | |
# Taking too long to respond or failing to respond. | |
$ time dig @218.248.255.141 archive.org | |
; <<>> DiG 9.6-ESV-R4-P3 <<>> @218.248.255.141 archive.org |