Skip to content

Instantly share code, notes, and snippets.

View soobrosa's full-sized avatar

Daniel Molnar soobrosa

View GitHub Profile
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
@soobrosa
soobrosa / gist:9888861
Last active August 29, 2015 13:57
keybase.md
### Keybase proof
I hereby claim:
* I am soobrosa on github.
* I am soobrosa (https://keybase.io/soobrosa) on keybase.
* I have a public key whose fingerprint is 19DA 1DE2 BEBD F91F 3EEA A264 30F5 64DE 4D6E 279F
To claim this, I am signing this object:
@soobrosa
soobrosa / gist:9483812
Created March 11, 2014 11:15
csv transpose
import csv
import sys
infile = sys.argv[1]
outfile = sys.argv[2]
with open(infile) as f:
reader = csv.reader(f)
cols = []
for row in reader:
cols.append(row)
@soobrosa
soobrosa / curlloop
Created November 21, 2013 12:58
curl a sequence of files
for number in `jot - 10 73`; do wget http://qzprod.files.wordpress.com/2013/11/2013-11-mobile-eating-the-world-$number.jpg; done
for number in `jot - 0 9`; do wget http://qzprod.files.wordpress.com/2013/11/2013-11-mobile-eating-the-world-0$number.jpg; done
@soobrosa
soobrosa / clean.py
Created September 25, 2013 10:08
clean text (needs homogenize)
def clean(sentence):
stopchars = ['.', ',', '?', '!', '"', '-']
gain = []
sentence = sentence.lower()
for char in stopchars:
sentence = sentence.replace(char,' ')
words = sentence.split(' ')
for word in words:
if word <> '':
@soobrosa
soobrosa / homogenize.py
Last active December 23, 2015 21:39
homogenize text
# input is unicode
import unicodedata
def homogenize (text):
text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore')
text = text.lower()
return text
@soobrosa
soobrosa / export_miso_history.py
Last active December 21, 2015 19:49
if you ever happen to export your miso history in python
# to export your miso history
# register an app at http://gomiso.com/oauth_clients
# gain your consumer_key and consumer_secret
# grab Gomiso Python from https://github.com/metabaron/Gomiso-Python
# and your ready to go
#
# cc 2013 soobrosa
from gomiso import gomiso
import json
@soobrosa
soobrosa / waterlevel_etl.py
Last active December 18, 2015 07:38
light ETL to reformat webdata from http://www.hydroinfo.hu/Html/archivum/archiv_tabla.html to a TSV with date and value columns
fi = open ('vizallas.txt', 'r')
fo = open ('vizallas.tsv', 'w')
year = ''
for li in fi:
# fixup days not existing in a given month
it = li.strip().replace(' ',' ... ').split(' ')
if len(it) < 2:
@soobrosa
soobrosa / difflibo.py
Created April 11, 2012 13:24
difflib chunk
import difflib
def neighbours(table, entry):
neighbour_list = difflib.get_close_matches(entry, table)
returns = {}
for neighbour in neighbour_list:
returns[neighbour] = difflib.SequenceMatcher(None, entry, neighbour).ratio()
return returns