Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
@ojii
ojii / last_page_on_path.py
Created May 2, 2014 08:04
last page on path
def last_page_on_path(path):
"""
Given a path (eg /a/b/c/d/e/), find the "last" page on that path.
If we have a CMS tree of:
|-a
| |-b
| | |-c

Keybase proof

I hereby claim:

  • I am ojii on github.
  • I am ojii (https://keybase.io/ojii) on keybase.
  • I have a public key whose fingerprint is 8DBD 52C5 761A EF34 D7C4 B2C0 F8E8 E2D9 DAF3 CFFD

To claim this, I am signing this object:

# using https://pypi.python.org/pypi/codequality/0.2-dev
codequality --ignore=cms/migrations/* --ignore=cms/static/cms/js/libs/* --ignore=cms/static/cms/js/jstree/* --ignore=cms/static/cms/js/plugins/jquery.ui.custom.js --ignore=cms/static/cms/js/plugins/jquery.ui.nestedsortable.js cms
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrV6ltrDFKmGdgc1H8vKZTHuBO7H4cpQJleNuTvfG1I1hFD54EnkJbA1O5zzNmGVEOzlF2E/+mCQYm12MFtEf8HTomU7XivSWv207pxi8jR2JteGmKLkx2xN4MbSXjo48WLUXu9GcWaLbVeC4UBPY4R1ThEk9LQEIU79BwqsMtAP306tQhsGf1mZTeCuy53687o20Rdw5UxS4jgya+YQUaRKsFP9RTGORb/fX/AUVbEbe+SEQ8wxsKpn2bnvWSmc1KN3ShuB4J1sDO5QdsVYAoCv9hwwq9/jti5t2XfuNY53/xNvCCougGp5jL74wzVyi3707fr9Gor06Q8rAaIvOF jonas@jonas-ubuntu
@ojii
ojii / app.py
Created May 28, 2013 16:53
shared "clipboard"
# -*- coding: utf-8 -*-
from kivy.support import install_twisted_reactor; install_twisted_reactor()
from twisted.internet import reactor
from twisted.internet import protocol
from twisted.protocols.basic import NetstringReceiver
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
@ojii
ojii / cbv_decorator.py
Created January 27, 2013 05:42
Class based view decorators for Django
def cbv_decorator(decorator):
"""
Turns a normal view decorator into a class-based-view decorator.
Usage:
@cbv_decorator(login_required)
class MyClassBasedView(View):
pass
"""
@ojii
ojii / b64.js
Created November 9, 2012 18:41
Base64 for JS (safe for IDs)
/*
Base64.encode(str):
Returns a string that is guaranteed to be a valid ID and can be decoded into its
original form. No two inputs generate the same output.
Base64.decode(str):
Returns the original string from the output of Base64.encode.
*/
var Base64 = {
characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.",
'encode': function(data) {
@ojii
ojii / bitmask.py
Created November 7, 2012 18:21
persist state
# -*- coding: utf-8 -*-
import sys
import requests
__doc__ = """bitmask.py
Usage:
bitmask.py <varname> <cookiename> [--default=<default>] [--html] [--compress] <mask>...
Options:
@ojii
ojii / Makefile
Last active October 12, 2015 11:28
my django CMS Makefile for testing
ENV_BASE=env
REQUIREMENTS_DIR=test_requirements
define runtests
virtualenv-$1 $(ENV_BASE)-$1-$2
$(ENV_BASE)-$1-$2/bin/pip install $(PIP_FLAGS) -r $(REQUIREMENTS_DIR)/django-$2.txt
$(ENV_BASE)-$1-$2/bin/python runtests.py $(TEST_FLAGS)
endef
all: py25dj13 py25dj14 py26dj13 py26dj14 py26djtrunk py27dj13 py27dj14 py26dj15 py27dj15 py33dj16 py26djtrunk py27djtrunk py33djtrunk
@ojii
ojii / appcfg.py
Created November 2, 2012 17:35
messing with pypy sandboxing
# -*- coding: utf-8 -*-
from helpers import Form, CharField
class ConfigForm(Form):
key = CharField('Twitter Consumer Key', max_length=255, required=True)
secret = CharField('Twitter Consumer Secret', max_length=255, required=True)
def to_settings(self, settings):
data = self.cleaned_data