Skip to content

Instantly share code, notes, and snippets.

@slinkp
slinkp / sched_icalendar.py
Created May 30, 2012 19:06
Convert PyGotham schedule into iCal format
"""
Parse the pygotham json schedule and make ical output
for use w/ google calendar, etc.
NOTE if you are going to serve the result, apparently google cal won't parse
it unless the header Content-Type: text/calendar is set!
Really useful for testing output: http://icalvalid.cloudapp.net
and http://severinghaus.org/projects/icv/
"""
@slinkp
slinkp / gist:2502476
Created April 26, 2012 19:45
another version of
if geom.srs is None:
geom.srid = 4326
geom = geom.transform(4326, True)
if hasattr(geom, 'geos'):
geom = geom.geos
@slinkp
slinkp / geom_tests.py
Created April 26, 2012 16:59
Geometry conversion test
from ebpub.utils.geodjango import ensure_valid
from ebpub.utils.geodjango import flatten_geomcollection
def convert1(geom, srid=4326):
# Karen's version
geom = geom.transform(srid, True)
if hasattr(geom, 'geos'):
geom = geom.geos
return geom
@slinkp
slinkp / iphone_notes_converter.py
Created March 29, 2012 16:25
iPhone Notes extractor
"""
This takes the sqlite 'notes' database from an iphone and dumps it to
flat text files in the current directory, preserving modification
times.
Uses 'lynx' (separate program) to dump html to plain text.
"""
import sqlite3
import datetime
@slinkp
slinkp / foo.diff
Created March 19, 2012 18:03
No more geomcollections
diff --git a/ebpub/ebpub/db/migrations/0005_newsitem_location_trigger.py b/ebpub/ebpub/db/migrations/0005_newsitem_location_trigger.py
index 53fd108..721a133 100644
--- a/ebpub/ebpub/db/migrations/0005_newsitem_location_trigger.py
+++ b/ebpub/ebpub/db/migrations/0005_newsitem_location_trigger.py
@@ -33,38 +33,16 @@ class Migration(DataMigration):
DELETE FROM db_newsitemlocation WHERE news_item_id = OLD.id; --
END IF; --
IF (NEW.location IS NOT NULL) THEN
- IF (GeometryType(NEW.location) = 'GEOMETRYCOLLECTION') THEN
- FOR i IN 1..ST_NumGeometries(NEW.location) LOOP
@slinkp
slinkp / oauth_views.py
Created November 10, 2011 21:14
Hack to avoid showing a confirmation form with django-oauth-plus
def oauth_authorize_without_confirmation(request, request_token, callback_url, params):
"""
This version uses some hackery to pretend the user has confirmed.
"""
params = request.GET.copy()
params['authorize_access'] = True
# request.POST claims to be immutable, but of course there's a way.
# Presumably I could just look up the HTTPRequest constructor...
request._set_post(params)
@slinkp
slinkp / cd2ogg.py
Created October 27, 2011 16:41
Script that rips a CD, and encodes to both ogg and flac, attempting to set metadata too.
#!/usr/bin/env python
"""
Rip a CD and encode the results to ogg.
Try to tag the ogg files, too.
And flac.
"""
# Stdlib imports
import glob
@slinkp
slinkp / olwidget.patch
Created August 5, 2011 21:11
Patch that adds support for arbitrary OpenLayers constructors to olwidget
diff --git a/doc-src/olwidget.js.rst b/doc-src/olwidget.js.rst
index 4a5ff97..dd8504b 100644
--- a/doc-src/olwidget.js.rst
+++ b/doc-src/olwidget.js.rst
@@ -306,7 +306,30 @@ General map display
``'ve.shaded'``, ``'ve.aerial'``, ``'ve.hybrid'``, ``'wms.map'``,
``'wms.nasa'``, ``'yahoo.map'``, and ``'cloudmade.<num>'`` (where ``<num>``
is the number for a cloudmade style). A blank map can be obtained using
- ``'wms.blank'``. Additional providers or options can be manually added
+ ``'wms.blank'``.
@slinkp
slinkp / poly_3.wkt
Created June 3, 2011 20:04
an example multipolygon with 3 geometries
MULTIPOLYGON (((-71.0577100000000002 42.3567770000000010, -71.0578089999999918 42.3560179999999988, -71.0578469999999953 42.3558499999999967, -71.0578699999999941 42.3557890000000015, -71.0584619999999916 42.3560919999999967, -71.0585849999999937 42.3559809999999999, -71.0589190000000031 42.3557399999999973, -71.0590569999999957 42.3559270000000012, -71.0594200000000029 42.3563989999999961, -71.0591620000000006 42.3566259999999986, -71.0589169999999939 42.3568429999999978, -71.0587369999999936 42.3569880000000012, -71.0582349999999963 42.3568319999999972, -71.0579929999999962 42.3567889999999991, -71.0577100000000002 42.3567770000000010)), ((-71.0510450000000020 42.3633329999999972, -71.0510000000000019 42.3625839999999982, -71.0516030000000001 42.3630409999999955, -71.0516470000000027 42.3631099999999989, -71.0517779999999988 42.3629419999999968, -71.0518979999999942 42.3628050000000016, -71.0510629999999992 42.3622480000000010, -71.0511010000000027 42.3621739999999960, -71.0512009999999918 42.36206599999999
@slinkp
slinkp / multi_layer_map.html
Created June 1, 2011 17:51
example of using my extra context hook in django-olwidget to add custom base layers
<div id="{{ id }}"></div>
{{ layer_html|join:"" }}
<script type="text/javascript">
var olwidget_map_{{id}} = new olwidget.Map("{{ id }}", [
{{ layer_js|join:"," }}
],
{{ map_opts|safe }}
);
var extra_layers = {{ extra_base_layers|default:"[]"|safe }};
for (var i=0, len=extra_layers.length; i < len; ++i) {