Skip to content

Instantly share code, notes, and snippets.

View un33k's full-sized avatar
🎯
Focusing

Val Neekman un33k

🎯
Focusing
View GitHub Profile
sudo apt-get update
sudo apt-get install python-dev python-software-properties
sudo add-apt-repository ppa:pitti/postgresql
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
@un33k
un33k / admin.py
Created October 25, 2011 02:00 — forked from uhop/admin.py
Adding Dojo's rich editor to Django's Admin.
# Example how to add rich editor capabilities to your models in admin.
from django.contrib.admin import site, ModelAdmin
import models
# we define our resources to add to admin pages
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',
#!/bin/sh
POSTGISCONTRIB_PATH=`pg_config --sharedir`/contrib
POSTGIS=$(find $POSTGISCONTRIB_PATH -name 'postgis.sql')
POSTGIS_COMMENTS=$(find $POSTGISCONTRIB_PATH -name 'postgis_comments.sql')
POSTGIS_SPATIAL=$(find $POSTGISCONTRIB_PATH -name 'spatial_ref_sys.sql')
if [ -z "$POSTGIS" ] || [ -z "$POSTGIS_SPATIAL" ]; then
echo " * Not found postgis contrib files."
exit 1
@un33k
un33k / registration_view.py
Created January 26, 2012 04:16 — forked from langri-sha/registration_view.py
Class-based django-registration view
from django.views.generic.edit import FormView
from django.views.generic.base import RedirectView
from registration.models import RegistrationProfile
from forms import RegistrationForm
class AccountRegistrationView(FormView):
template_name = 'authentication/registration_form.html'
form_class = RegistrationForm
@un33k
un33k / app1.search_indexes.py
Created March 9, 2012 18:06 — forked from valyagolev/app1.search_indexes.py
django-haystack is annoying
from search_sites import register_model_for_search
from .models import CoolModel
register_model_for_search(CoolModel)
@un33k
un33k / text.py
Created April 20, 2012 00:12 — forked from joshourisman/text.py
A Django template filter that truncates a string to at most X characters while respecting word boundaries.
from django.template import Library
from django.utils.encoding import force_unicode
from django.utils.functional import allow_lazy
from django.template.defaultfilters import stringfilter
register = Library()
def truncate_chars(s, num):
"""
Template filter to truncate a string to at most num characters respecting word
@un33k
un33k / onlinenow.py
Created June 12, 2012 01:47 — forked from dfalk/onlinenow.py
django online users
from django.core.cache import cache
from django.conf import settings
from django.contrib.auth.models import User
ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15)
ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50)
def get_online_now(self):
return User.objects.filter(id__in=self.online_now_ids or [])
@un33k
un33k / slash_middleware.py
Created July 5, 2012 11:53 — forked from gregplaysguitar/slash_middleware.py
Append OR remove slash in django - like APPEND_SLASH but smarter.
from django import http
from django.utils.http import urlquote
from django.core import urlresolvers
class AppendOrRemoveSlashMiddleware(object):
"""
Like django's built in APPEND_SLASH functionality, but also works in reverse. Eg
will remove the slash if a slash-appended url won't resolve, but its non-slashed
counterpart will.
@un33k
un33k / gist:3886896
Created October 14, 2012 01:28 — forked from EspadaV8/gist:1357237
Script to import Geonames into PostgreSQL taken from http://forum.geonames.org/gforum/posts/list/15/926.page
#!/bin/bash
#===============================================================================
#
# FILE: getgeo.sh
#
# USAGE: ./getgeo.sh
#
# DESCRIPTION: run the script so that the geodata will be downloaded and inserted into your
# database
#
@un33k
un33k / salt-master
Created October 22, 2012 03:22 — forked from justone/salt-master
saltstack on lenny
#!/bin/sh
#
# Salt master
###################################
# LSB header
### BEGIN INIT INFO
# Provides: salt-master
# Required-Start: $remote_fs $network