Skip to content

Instantly share code, notes, and snippets.

View specialunderwear's full-sized avatar

Voxin Muyli specialunderwear

View GitHub Profile
# this file is in a package named verboten
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseForbidden
from django.template import RequestContext, loader
from django.db import models
from django.conf import settings
class LanguagePermissions(models.Model):
"""Only used to define permissions"""
@specialunderwear
specialunderwear / staticfiles.py
Created August 23, 2011 14:58
Use django collectstatic with apps that have 'media' folders instead of 'static' folders. Also make run server serve files in the MEDIA_ROOT automatically, even if it is inside STATIC_ROOT.
import os
from django.conf import settings
from django.contrib.staticfiles.finders import BaseFinder, AppDirectoriesFinder
from django.contrib.staticfiles.storage import AppStaticStorage
from django.core.files.storage import FileSystemStorage
from django.utils._os import safe_join
class AppMediaStorage(AppStaticStorage):
@specialunderwear
specialunderwear / inspect.py
Created August 30, 2011 14:33
template tags for inspecting variables inside templates
from django import template
register = template.Library()
@register.simple_tag
def props(obj):
result = []
for key in dir(obj):
try:
result.append("%s -> %s<br/>" % (key, getattr(obj, key)))
except Exception as e:
@specialunderwear
specialunderwear / babel.sh
Created September 15, 2011 08:58
Install all utf8 locales on ubuntu
#! /bin/sh
cd /usr/share/locales
./install-language-pack eo
./install-language-pack ia
./install-language-pack ie
./install-language-pack io
./install-language-pack vo
./install-language-pack ca
@specialunderwear
specialunderwear / meta.py
Created November 1, 2011 15:19
metaclass for google.appengine.ext.db.Model with i18n properties.
from copy import deepcopy
from google.appengine.ext import db
import settings
class I18nModelMetaClass(db.PropertiedClass):
"""
Metaclass for adding language specific attributes to a
AuthorizationRef authorizationRef;
OSStatus status;
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
kAuthorizationFlagDefaults, &authorizationRef);
// suppose we've got the new hosts file in an NSString called new_hosts_file
NSString *overwrite_hosts = [NSString stringWithFormat:@"echo %s > /private/etc/hosts", new_hosts_file];
char *args[] = {[overwrite_hosts cstring]};
status = AuthorizationExecuteWithPrivileges(authorizationRef, "/bin/sh",
kAuthorizationFlagDefaults, args, NULL);
@specialunderwear
specialunderwear / README.rst
Created January 12, 2012 14:48
virtualenvwrapper postactivate hook with buildout shortcuts

Quickly navigate your buildout.

Requires virtualenv and virtualenvwrapper.

cdco # cd to buildout root
cds voxin # (will autocomplete with tab and will cd into the project named voxin in the src dir)
buildout # will run buildout, but from the buildout root.
@specialunderwear
specialunderwear / one2.js
Created January 29, 2012 23:37
new scope
> var one = 1;
> var two = new one;
> two;
1
> one = 2;
> two;
1
> one;
2
@specialunderwear
specialunderwear / newfunction.js
Created January 29, 2012 23:46
next function
> var next = function(input) {
> return input + 1;
> }
> var three = new next;
> three;
[Function]
> three(2);
3
@specialunderwear
specialunderwear / threeconstructor.js
Created January 29, 2012 23:57
three as a constructor
> var three = new next(2);
> three;
3