Skip to content

Instantly share code, notes, and snippets.

@mittenchops
mittenchops / addweeks.py
Created August 5, 2013 18:54
Add weeks to time in MMM DDth YYYY format.
from dateutil import parser
from datetime import timedelta
date = "Mar 11th 2013"
def addweeks(date,week=0):
x = parser.parse(date)
new = x + timedelta(weeks=week)
return(new.strftime("%b %d %Y"))
@mittenchops
mittenchops / inkscapeSVG2PNGafolder.sh
Created August 7, 2013 22:01
For each SVG in a directory, makes a faithful PNG copy.
for i in *.svg; do inkscape -f "$i" -e "$i.png"; done
@mittenchops
mittenchops / histgistinpython.py
Last active December 20, 2015 20:18
Simple gist to remind me of how to do a histogram in python. If you want to plot with highrise, you should use the xs, and ys.
X = [0.82, 7.19, 4.15, 7.14, 2.5, 0, 2.04, 0, 4.55, 1.98, 0, 0.5, 1.56, 2.55, 0.4, 0]
r = range(0,11)
ys, xs, pathes = plt.hist(X, bins=r)
plt.ylabel("count")
plt.xticks(r, r)
plt.show()
@mittenchops
mittenchops / colorstates.js
Created August 14, 2013 18:47
Straight javascript to color the open source wikipedia svg USA map with classes for a choropleth: https://commons.wikimedia.org/wiki/File:Blank_US_Map.svg from http://stackoverflow.com/questions/8638621/jquery-svg-why-cant-i-addclass
# javascript
var element = document.getElementById("MI");
element.setAttribute("class", "s5");
# css
.s5 {
fill: #00FA19;
}
@mittenchops
mittenchops / openworkers.py
Last active December 22, 2015 04:39
Open worker processes
from subprocess import Popen
maxworkers = 10
workers=[]
for i in range(0,maxworkers):
workers.append(Popen('python work.py', shell=True))
# OR
def makeworker():
@mittenchops
mittenchops / screensplitter.sh
Created September 3, 2013 01:23
Using screen for multiple bots
screen
C-a S
C-a TAB
C-a c
@mittenchops
mittenchops / loadshp2mongo.py
Last active April 9, 2019 06:13
Loading shapefiles into mongodb. This all actually comes from here: http://geospatialpython.com/ But this is wrapped up a little nicer.
# http://geospatialpython.com/
import json, pymongo, shapefile
from json import dumps
database = 'geo'
connection = pymongo.MongoClient()
db = getattr(connection,database)
def renamesh2json(x):
d = x.split(".")
@mittenchops
mittenchops / realdiff.sh
Created September 7, 2013 16:10
Usefully diffing files on the command line
diff -u file1 file2 | colordiff | less -R
@mittenchops
mittenchops / geojson2mongo.py
Last active December 22, 2015 16:29
Load GeoJSON, posted here to for SO and mongoDB mailing list references
import json, pymongo, shapefile, sys, ijson
from ijson import common
from ijson.backends import yajl
def floaten(event):
if event[1] == 'number':
return (event[0], event[1], float(event[2]))
else:
return event
@mittenchops
mittenchops / strtype.py
Created October 4, 2013 14:33
Match unicode and string in python
from types import StringTypes
if not isinstance(a,StringTypes): raise