Skip to content

Instantly share code, notes, and snippets.

View philipn's full-sized avatar

Philip Neustrom philipn

View GitHub Profile
@philipn
philipn / gist:5274197
Last active October 20, 2022 02:37
Running Ubuntu on a Macbook Air

Running Ubuntu on a Macbook Air

You don't have to be a slave to OS X! Here's a guide to a sane dual-booting setup with Ubuntu 12.10 on your shiny MacBook Air. This is written and tested for a MacBook Air 5,2 (Mid 2012), but likely works the same with any modern Macbook.

Install according to instructions at this URL:

@philipn
philipn / gist:cc873d7311f12eac0f68
Last active April 19, 2022 08:39
Using i18n LANGUAGE_CODE(s) with django-compressor offline compression
"""
A replacement for the django-compressor `compress` management command that renders all
templates with each `LANGUAGE_CODE` available in your `settings.LANGUAGES`.
Useful for making static-i18n work with django-compressor, among other things.
"""
import os
from os.path import join
import json
@philipn
philipn / gist:1148693
Created August 16, 2011 08:59
GeoTIFFs -> One Big GeoTIFF
"""
Likely not useful to anyone else, but just putting it out there.
This script will take a directory of GeoTIFFs and merge them together without issues.
This script simply decompresses the files, runs nearblack to remove pseudo-black borders caused by compression, and then uses gdalwarp to stitch the files together.
The script is designed to use the minimal amount of disk space possible -- it cleans up each file after decompression and continually merges with a master image.
"""
import os
@philipn
philipn / gist:1138957
Created August 11, 2011 05:25
GeoTIFF metadata / ftp download
"""
This likely isn't useful to anybody else. But it's an example of how to
adapt python's ftplib to grab just the first few kb of a given file.
In this case, all we need is the first few kb to get the metadata from a
GeoTIFF file.
"""
import ftplib
@philipn
philipn / gist:8659192
Created January 27, 2014 23:07
Mixin to allow limiting of fields, per-request, in django-rest-framework
class AllowFieldLimitingMixin(object):
"""
A mixin for a generic APIView that will allow the serialized fields to be
limited to a set of comma-separated values, specified via the `fields`
query parameter. This will only apply to GET requests.
"""
_serializer_class_for_fields = {}
def get_serializer_class_for_fields(self, serializer_class, fields):
fields = fields.strip().split(',')

Keybase proof

I hereby claim:

  • I am philipn on github.
  • I am philipn (https://keybase.io/philipn) on keybase.
  • I have a public key whose fingerprint is 996B 2D31 DBDC 8734 9019 3199 1319 9280 9EB7 3975

To claim this, I am signing this object:

@philipn
philipn / gist:5241282
Last active December 15, 2015 09:49
Custom CSS upgrade for LocalWiki platform v0.5

If you've customized your CSS or otherwise altered your site/base.html template you'll want to do the following:

Back up your old base.html template:

sudo cp /usr/share/localwiki/templates/site/base.html ~/base.html.bak

Now just remove the base.html template:

sudo rm /usr/share/localwiki/templates/site/base.html
# This is an example .wsgi file for serving up localwiki inside of a
# custom virtualenv.
#
#############################################################
# CHANGE THIS LINE to the absolute path of the virtualenv:
#############################################################
VIRTUAL_ENV_PATH = '/home/philip/projects/py_envs/localwiki'
import os
import sys
@philipn
philipn / gist:3260364
Created August 4, 2012 22:31
tastypie gis queryset methods
the distance method takes a geom argument:
Map.objects.distance(geom).order_by('distance') -->
/api/map/?objects.distance=<geom>&order_by=distance
the area method takes no arguments:
Map.objects.area().order_by('area') -->
def filter_value_to_python(self, value, field_name, filters=None,
filter_expr=None, filter_type=None):
"""
Turn the string ``value`` into a python object.
"""
# Simple values
if value in ['true', 'True', True]:
return True
elif value in ['false', 'False', False]: