Skip to content

Instantly share code, notes, and snippets.

View tobych's full-sized avatar

Toby Champion tobych

  • Bainbridge Island, WA
  • 21:18 (UTC -07:00)
  • LinkedIn in/tobych
View GitHub Profile
# Get a list of IDs for all ways in the gdf
way_ids = gdf_bike.loc['way'].index.tolist()
# get a bbox, as per features_from_point()
bbox = ox.utils_geo.bbox_from_point(center, 5000)
# get a polygon we can use to query Overpass, as per features_from_bbox()
polygon = ox.utils_geo.bbox_to_poly(bbox)
# build results generator
response_jsons = ox._overpass._download_overpass_features(polygon, tags_bike)
# get the elements, assuming the generator only yielded one response
elements = next(response_jsons)['elements']
@tobych
tobych / checke2e.py
Last active December 21, 2015 21:59
Monkey patch to work around Django #13843
# https://gist.github.com/tobych/6372218
# Monkey patch to work around https://code.djangoproject.com/ticket/13843
import django
from functools import wraps
def discard_exceptions(f):
@wraps(f)
def wrapper(*args, **kwds):
try:
@tobych
tobych / checke2e.py
Created August 28, 2013 21:55
Towards monkey patching my way around https://code.djangoproject.com/ticket/13843
def patched__del__(self):
if self.ptr: lgeos.finishGEOS_r(self.ptr)
import django
django.contrib.gis.geos.prototypes.threadsafe.GEOSContextHandle.__del__ = patched__del__
@tobych
tobych / crew.html
Last active December 20, 2015 16:19
Applying Bootstrap label class based on custom attribute
<span class="statusLabel" data-status="{{ status.name }}">{{ status.name }}</span>
...
<script type="text/javascript">
$('.statusLabel').addClass(function() {
var classes = {
"Never seen": 'label',
"OK": "label label-success",
"Relocated": "label label-warning",
"Missing": "label label-danger"
}
class TruckResource(ModelResource):
class Meta:
queryset = Truck.objects.all()
list_allowed_methods = ['get']
detail_allowed_methods = ['get']
filtering = {'owner': ALL_WITH_RELATIONS, 'truck_number': ALL}