Skip to content

Instantly share code, notes, and snippets.

View signed0's full-sized avatar

Nathan Villaescusa signed0

View GitHub Profile
["Life isn’t about getting and having, it’s about giving and being.", "Kevin Kruse"]
["Whatever the mind of man can conceive and believe, it can achieve.", "Napoleon Hill"]
["Strive not to be a success, but rather to be of value.", "Albert Einstein"]
["Two roads diverged in a wood, and I—I took the one less traveled by, And that has made all the difference.", "Robert Frost"]
["I attribute my success to this: I never gave or took any excuse.", "Florence Nightingale"]
["You miss 100% of the shots you don’t take.", "Wayne Gretzky"]
["I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.", "Michael Jordan"]
["The most difficult thing is the decision to act, the rest is merely tenacity.", "Amelia Earhart"]
["Every strike brings me closer to the next home run.", "Babe Ruth"]
["Definiteness of purpose is the starting point of all achievement.", "W.
@signed0
signed0 / gist:2031157
Created March 13, 2012 19:53
Google Polyline encoder & decoder
'''Provides utility functions for encoding and decoding linestrings using the
Google encoded polyline algorithm.
'''
def encode_coords(coords):
'''Encodes a polyline using Google's polyline algorithm
See http://code.google.com/apis/maps/documentation/polylinealgorithm.html
for more information.
@signed0
signed0 / gist:2252148
Created March 30, 2012 15:03
Douglas Peucker
from math import sqrt
from itertools import islice, chain
def subtract_coords(a, b):
'''Returns a - b'''
return (a[0] - b[0], a[1] - b[1])
def dot_product(a, b):
return a[0] * b[0] + a[1] * b[1]
@signed0
signed0 / hubot.conf
Created December 9, 2013 22:21
Upstart config file for Hubot using IRC
description "Hubot IRC bot"
# This will make Hubot start on system boot
start on filesystem or runlevel [2345]
stop on runlevel [!2345]
# Path to Hubot installation
env HUBOT_DIR='/opt/hubot/'
env HUBOT='bin/hubot'
env LOGFILE='/dev/null'
@signed0
signed0 / git_user_date_range.py
Last active December 16, 2015 15:38
Determine the first and last commit date for each user in a git repo.
import datetime
from collections import defaultdict
import subprocess
def main():
git_log = subprocess.check_output(['git', 'log', "--pretty=format:%an\t%ct"])
users = defaultdict(list)
for line in git_log.split('\n'):
name, commit_time = line.strip().split('\t')
from collections import defaultdict
from itertools import islice
def make_change(target, denominations):
"""Returns fewest coins needed to make up the target value
>>> make_change(100, [25, 10, 5, 1])
[(25, 4)]
>>> make_change(30, [25])
@signed0
signed0 / gist:2423962
Created April 19, 2012 20:32
Haversine Distance
'''See http://en.wikipedia.org/wiki/Haversine_formula for more details'''
from math import sin, cos, sqrt, asin, radians
RADIUS_EARTH_M = 6371200.0 #The Earth's mean radius in meters
def haversine_distance(a, b):
'''Operates on two lat,lngs and returns the distance in meters'''
lng1, lat1 = map(radians, a) #lng, lat to radians
@signed0
signed0 / gist:2240930
Created March 29, 2012 17:57
Splits a list of items into chunks of length n
from itertools import islice
def batch(items, n):
'''Splits a list of items into chunks of length n'''
i = iter(items)
while True:
items = tuple(islice(i, n))
if len(items) == 0:
@signed0
signed0 / gist:1830094
Created February 14, 2012 20:28
Human readable time fields
from datetime import datetime
def datetime_format(value):
'''Provides pretty datetime strings
The amount of information will change depending on how long ago the value is from now
If the value is today then just the time will be returned
If the value is this year then the year will be left off
'''
now = datetime.utcnow()
@signed0
signed0 / gist:1829916
Created February 14, 2012 20:20
Human readable date range
def daterange(v0, v1):
assert v0 <= v1
if v0 == v1:
return v0.strftime('%b %d, %Y')
if v0.year == v1.year:
if v0.month == v1.month:
parts = (v0.strftime('%b %d'),
v1.strftime('%d'),