Skip to content

Instantly share code, notes, and snippets.

@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"
@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 / 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
"""Closing the loop
http://code.google.com/codejam/contest/dashboard?c=837485#s=p0
"""
def nmax(l,n):
"""Find sum of n highest numbers from list l
"""
if l and n <= len(l):
temp = l[:]
temp.sort()
temp.reverse()
"""Find the largest palindrome made from the product of two 3-digit numbers."""
from itertools import combinations as cnr
print max([ x*y for (x,y) in cnr(range(100,999),2) if str(x*y) == str(x*y)[::-1]])
@rainzoo
rainzoo / Hello.m
Created July 5, 2012 19:04
Compile and run Objective C program on Ubuntu 11.04
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@autoreleasepool {
NSLog(@"Hello World");
}
}
@rainzoo
rainzoo / gist:3116988
Created July 15, 2012 13:47
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@rainzoo
rainzoo / index.html
Created August 10, 2012 13:51 — forked from mbostock/.block
Circular Layout (Raindrops)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Raindrops</title>
<script type="text/javascript" src="https://github.com/mbostock/d3/raw/v1.4.0/d3.js"></script>
<style type="text/css">
body {
background: #012;
@rainzoo
rainzoo / NumberToWords.scala
Last active December 10, 2015 19:29
Convert numbers to words, numbers up to thousands.
object NumberToWords {
val units = List("one", "two", "three", "four",
"five", "six", "seven", "eight", "nine")
val teens = List("ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
val tens = List("twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety")
def main(args: Array[String]) {
@rainzoo
rainzoo / uinique_values.py
Created January 26, 2013 16:01
Extract unique combinations of columns (number 1 to 4) in a tab separated file.
with open('sample.txt') as fi:
dct = {}
header = fi.readline()
"""Couldn't figure what this row is for
"""
rec1 = fi.readline()
for line in fi.readlines():
x = line.split()[1:5]
key = ",".join(x)
dct[key] = dct.get(key, 0) + 1