Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
@ojii
ojii / justonce.sh
Created April 8, 2011 08:01
Run a single command in a virtualenv (using virtualenvwrapper)
function justonce(){
E_BADARGS=65
if [ $# -lt 2 ]
then
echo "Usage: `justonce <envname> <command>`"
exit $E_BADARGS
fi
workon $1
shift
from classytags.arguments import Argument
from classytags.core import Options
from classytags.helpers import InclusionTag
from django import template
from django.conf import settings
register = template.Library()
class Disqus(InclusionTag):
options = Options(
@ojii
ojii / to_french.py
Created March 30, 2011 09:16
A script that translates any language into French!
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import random
mappings = {
'a': [u'à', u'â'],
'c': [u'ç'],
'e': [u'é', u'è', u'ê'],
}
@ojii
ojii / to_swiss_german.py
Created March 30, 2011 09:10
A python script that translates German to Swiss German
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import random
mappings = {
'a': u'ä',
'o': u'ö',
'u': u'ü',
'k': 'ch',
@ojii
ojii / wtf.py
Created March 30, 2011 08:15
wtf.py
from django import template
from pprint import pformat
register = template.Library()
@register
def wtf(obj):
return pformat(obj)
@ojii
ojii / __init__.py
Created March 28, 2011 14:11
__init__.py
# nothing here
import re
from django.conf import settings
from django.http import HttpResponseRedirect
DEFAULT = 'http://www.getfirefox.com'
class IE6CountdownMiddleware(object):
"""
Do *very* simple user agent scanning and redirect anyone accessing your site
@ojii
ojii / embedable_plugin.py
Created February 25, 2011 10:06
The bit inside the 'cmsplugin' tag is actually a link plugin!
class LinkPlugin(CMSPluginBase):
def get_embed_content(self, instance, parent_instance):
ctx = Context()
return render_to_string(self.render_template, self.render(ctx, instance, None))
##############################################################################
#
# Copyright (c) 2006 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
@ojii
ojii / very_dangerous_script.py
Created February 3, 2011 16:12
DONT USE THIS IF YOU DONT KNOW EXACTLY WHAT IT DOES AND HOW IT DOES IT!
'''
WARNINGS: THIS SCRIPT COMES WITHOUT ANY WARRANTY AND RUNNING IT IS DONE SO AT YOUR OWN RISK!
'''
from cms.models import Page
def setup():
from django.contrib.auth.models import User
from cms.utils.permissions import set_current_user
set_current_user(User.objects.get(id=1))
def check_no_moderator():