Skip to content

Instantly share code, notes, and snippets.

View stefanfoulis's full-sized avatar

Stefan Foulis stefanfoulis

View GitHub Profile
@stefanfoulis
stefanfoulis / base64field.py
Created August 5, 2011 06:47
Base64 Encoded Field with south support
#-*- coding: utf-8 -*-
# Work in progress. The South part does not work correctly yet!
import base64
from django.db import models
# Stolen from http://djangosnippets.org/snippets/1669/
class Base64Field(models.TextField):
def contribute_to_class(self, cls, name):
#-*- coding: utf-8 -*-
import zbar
from PIL import Image
def read_barcode(path):
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
pil = Image.open(image).convert('L')
width, height = pil.size
raw = pil.tostring()
@stefanfoulis
stefanfoulis / auth_views.py
Created August 11, 2011 16:44
django: class based authentication view (login)
#-*- coding: utf-8 -*-
import urlparse
from django.contrib.auth import REDIRECT_FIELD_NAME, login
from django.contrib.auth.forms import AuthenticationForm
from django.http import HttpResponseRedirect
from django.utils.decorators import method_decorator
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.generic.edit import FormView
from django.conf import settings
@stefanfoulis
stefanfoulis / __init__.py
Created August 16, 2011 18:00
PEP386 StrictVersion compliant __version__
#-*- coding: utf-8 -*-
__version_info__ = {
'major': 0,
'minor': 1,
'micro': 0,
'releaselevel': 'alpha',
'serial': 1
}
def get_version(short=False):
#-*- coding: utf-8 -*-
"""
Provides an easy way to turn any ascii string into a funky unicode character massacre.
Example usage:
>>> from unicodefy import unicodefy
>>> print unicodefy(u'We are not ASCII')
Wë ãrè ñót ÅŠÇÎÌ
"""
######################
# Windows
######################
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini

Welcome to Drift!

Drift is an always-already versioned, cloud-backed text editor. You can use it to take notes, and save them in the GitHub cloud.

Your gists are always saved locally, and any changes you make will get pushed to GitHub's servers.

To name a gist, touch its name in the toolbar.

You can use the share button at the top-right to copy a link to one of your gists, or view it on the web in Safari.

"""
Just a quick hack to collect all "media" directories in INSTALLED_APPS instead
of only the "static" directories.
add this to your settings:
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"myproject.media_staticfiles_finder.AppDirectoriesFinderAsMedia",
@stefanfoulis
stefanfoulis / server_base.py
Created February 22, 2012 16:43
debug_fileserver.py
#-*- coding: utf-8 -*-
import os
import stat
from django.http import Http404, HttpResponse, HttpResponseNotModified
from django.utils.http import http_date
from django.views.static import was_modified_since
from base import ServerBase
class DefaultServer(ServerBase):
'''
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAstk2DWscjksvanWXwH93ED3rkbqWP1VCnv4x3Vd3kRu4VYU8xwLHQB50Xy3iacBsBtTj6vajCL2AawSYVeZcRW4ptOvr89ZgoHY5K4DytWFYoG1fnzpcfz3A243iOZZLR9CmYn0V3i5k1h3Xn32Q9cC1MxiMCvpUmFLjUfRfXvv8nX1WDX6A6MhT/+D+s/ZcO6i/35qT5cTVazxdl+WznFUsriV4qdiVn+AQRxJH7LeHYWhXAGwwP0lsSc4vMZv57KExWQx7Pt/v7ZO9lSJTm84h5aKmbj8lKVP9wJ0gUVPdcgx3SCs0rTeCvVoQfx7Sh8fSMBvf8drVNmQ/eJNWrQ== stefan@foulis.ch