Skip to content

Instantly share code, notes, and snippets.

View philipn's full-sized avatar

Philip Neustrom philipn

View GitHub Profile

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: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:004396d336bc2bece97f
Created August 14, 2014 08:51
localwiki varnish config
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend cloudmade {
# cloudmade tiles
#.host = "c.tile.cloudmade.com";
.host = "54.230.151.226";
@philipn
philipn / gist:20f24bea0b58575f7668
Created May 15, 2014 00:51
Test (doesn't work any longer) export to static html from LocalWiki
import slumber
import requests
import os
import lxml.html
import urllib
from urlparse import urljoin
from utils import all, quote_fs
SITE = 'https://trianglewiki.org'
@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(',')
@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: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]: