Skip to content

Instantly share code, notes, and snippets.

View DenisCarriere's full-sized avatar
🎯
Focusing

Denis DenisCarriere

🎯
Focusing
View GitHub Profile
@DenisCarriere
DenisCarriere / Google Geocoder
Created January 15, 2014 22:27
Here's how my Geocoder works, the same function applies to 8 providers (Google, Bing, OSM, MapQuest, TomTom, Nokia, ESRI, MaxMind)
import geocoder
g = geocoder.google('Ottawa, Ontario')
g.latlng
[45.4215296, -75.6971930999]
@DenisCarriere
DenisCarriere / crossdomain.py
Created January 20, 2014 05:25
Trying to figure out why this is not working when I deploy it to my Heroku App...?? weird
# -*- coding: utf-8 -*-
from datetime import timedelta
from flask import make_response, request, current_app, Flask, jsonify
from functools import update_wrapper
def crossdomain(origin=None, methods=None, headers=None,
max_age=21600, attach_to_all=True,
automatic_options=True):
@DenisCarriere
DenisCarriere / Toporama.py
Created January 27, 2014 19:15
End result of Toporama Module
import geo
toporama = geo.toporama('Ottawa')
toporama.download()
# Default toporama would be 50K
# geo.toporama(<location>, scale='250K')
# Default location for download would be root of the python script
# toporama.download('download here/')
@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", ...}