Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Villaescusa signed0

View GitHub Profile
View quotes.json
["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 / hubot.conf
Created Dec 9, 2013
Upstart config file for Hubot using IRC
View hubot.conf
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 Dec 16, 2015
Determine the first and last commit date for each user in a git repo.
View git_user_date_range.py
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')
View change_making.py
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 Apr 19, 2012
Haversine Distance
View gist:2423962
'''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:2252148
Created Mar 30, 2012
Douglas Peucker
View gist:2252148
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 / gist:2240930
Created Mar 29, 2012
Splits a list of items into chunks of length n
View gist:2240930
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:2031157
Created Mar 13, 2012
Google Polyline encoder & decoder
View gist:2031157
'''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:1830094
Created Feb 14, 2012
Human readable time fields
View gist:1830094
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 Feb 14, 2012
Human readable date range
View gist:1829916
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'),