Skip to content

Instantly share code, notes, and snippets.

Avatar

Philip Neustrom philipn

View GitHub Profile
View keybase.md

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 Apr 19, 2022
Using i18n LANGUAGE_CODE(s) with django-compressor offline compression
View gist:cc873d7311f12eac0f68
"""
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 Aug 14, 2014
localwiki varnish config
View gist:004396d336bc2bece97f
# 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
Test (doesn't work any longer) export to static html from LocalWiki
View gist:20f24bea0b58575f7668
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 Jan 27, 2014
Mixin to allow limiting of fields, per-request, in django-rest-framework
View gist:8659192
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 Oct 20, 2022
Running Ubuntu on a Macbook Air
View gist:5274197

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 Dec 15, 2015
Custom CSS upgrade for LocalWiki platform v0.5
View gist:5241282

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
View gist:3328228
# 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 Aug 4, 2012
tastypie gis queryset methods
View gist:3260364
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') -->
View gist:3140557
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]: