Skip to content

Instantly share code, notes, and snippets.

View DenisCarriere's full-sized avatar
🎯
Focusing

Denis DenisCarriere

🎯
Focusing
View GitHub Profile
@DenisCarriere
DenisCarriere / pydie.py
Created February 23, 2014 05:47
PyDie example
>>> import pydie
>>> pydie.roll('3d1')
3
import re
# Input
string = '3d6+2'
# Regex Pattern
pattern = re.compile(r'(?P<multiplier>\d+)d(?P<die>\d+)m?(?P<math>\D)?(?P<modifier>\d+)?')
match = pattern.match(string)
# Attributes
@DenisCarriere
DenisCarriere / geocoder_places.py
Last active August 29, 2015 13:57
Geocoder Places
import geocoder
places = geocoder.places('Kabul, Afghanistan', keyword='Embassy')
for place in places:
print place.json
print place.latlng
import coordinate
# MGRS to LatLng
c = coordinate.get('41R QQ 123 123')
print c.latlng
# LatLng to MGRS
c = coordinate.get('41.123, -78.123')
print c.mgrs
import csv
with open(join('us-data', 'codes.txt')) as f:
rows = list(csv.DictReader(f, dialect='excel-tab'))
codes = dict([(row['Postal Code'].lower(), row['State']) for row in rows])
@DenisCarriere
DenisCarriere / OSM Query.html
Last active August 29, 2015 14:07
OSM Query User Name
<osm-script output="json" timeout="25">
<!-- gather results -->
<union>
<query type="way">
<has-kv k="addr:housenumber"/>
<user name="DenisCarriere"/>
<has-kv k="source" v="survey"/>
</query>
</union>
<!-- print results -->
@DenisCarriere
DenisCarriere / OpenCage.py
Last active August 29, 2015 14:12
Using OpenCage Geocoder with Python
# To Install:
# $ pip install geocoder
>>> import geocoder
>>> g = geocoder.opencage("New York City", key="YOUR API KEY")
>>> g.latlng
[40.7305991, -73.9865812]
>>> g.json
{"status": "OK", "locality": "New York City", ...}
# pip install geocoder
# param: short_name (Default is True)
# param: method (Default is 'Geocode')
> import geocoder
> g = geocoder.google('41.34168 -8.71202', method='reverse', short_name=False)
'<[OK] Google - Reverse [IC1, 4480, Portugal]>'
> g.latlng
[41.344931, -8.7123075]
> g.country
'Portugal'
@DenisCarriere
DenisCarriere / ottawa_geocode.py
Created January 11, 2015 00:04
City of Ottawa Geocode
import requests
url = 'http://maps.ottawa.ca/ArcGIS/rest/services/compositeLocator/GeocodeServer/findAddressCandidates'
params = {
'SingleLine': '190 Forward Avenue',
'f': 'json',
'outSR': 4326,
}
r = requests.get(url, params=params)
@DenisCarriere
DenisCarriere / Read_CSV.py
Created February 18, 2015 12:59
Reading CSV file
import csv
"""
filename.csv
============
first,second
hello,world
"""
# Standard CSV Reading