Skip to content

Instantly share code, notes, and snippets.

@rainzoo
rainzoo / occurrence.py
Created March 28, 2011 04:25
Find occurrence of an item in a list using Functional, Library & Imperative approach
"""Find occurrence of an item in a list using Functional, Library & Imperative approach and compare the time.
"""
import time
def runtime(func, *args):
t=time.clock()
func(*args)
s=time.clock()-t
return s
@rainzoo
rainzoo / bouncy.py
Created March 28, 2011 04:20
Solution to Project Euler problems
"""Problem 112 http://bit.ly/dSvkG8
"""
#increasing number
def isInc(n):
s = str(n)
for i,x in enumerate(s):
if i:
if s[i] < s[i-1]:
return False
return True
@rainzoo
rainzoo / geocode.py
Created March 27, 2011 20:12
Latitude and Longitude of the address using Google Maps Gecoding API
import urllib2 as u
import json
def GeoCode(address):
"""Returns Latitude and Longitude of the address using
Google Maps Gecoding API
"""
api = "http://maps.googleapis.com/maps/api/geocode/json?address="
address = str(address.replace(" ","+"))
url = api + address + "&sensor=false"