Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
@ojii
ojii / autobild.sh
Created September 14, 2011 04:19
autobild.sh
#!/bin/sh
#
# Copyright (c) 2011, Jonas Obrist
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
@ojii
ojii / chainable_manager.py
Created August 22, 2011 09:01
ChainableManager for Django
# -*- coding: utf-8 -*-
from django.db import models
from django.db.models.query import QuerySet
class ChainableManager(models.Manager):
"""
class MyChainableManager(ChainableManager):
def active(self):
@ojii
ojii / macbook air
Last active September 26, 2015 18:07
my public key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFMCGT2Lz0LKndS26QHocSa7bJ/8kabu1JQbYJQ8sGd0Y1RbOLnJZiibM0uE0mvSTeXyxuNJyyPe7nvSR4aNfq5bn7dA8ek7Siy1449kA22nwI/GM62fYfIDwAt6GJSvacCKaZWokQ/kiZ9UG9anE+RXR1GSDgE42CPfcT0VFDu83TQ0/55qEfmMWimFqoZG/dCUGarTmNta+irEy4JL0VNQ2B59IDW/WskmgP6EuGBUoCiuOy95SiFS5t/SQrRebpDTtLiSvb+4lbL2BmAUQnuPoYPgLbj62w5n/E9qWbYCck/00TGSjvQfZeSXJYDYlEpbVMGx7p0C3S89+KB26/ [email protected]
@ojii
ojii / example.html
Created August 4, 2011 18:48
django-cms 2.2 tutorial app files
{% load cms_tags sekizai_tags %}
<!doctype html>
<head>
<title>{{ request.current_page.get_title }}</title>
{% render_block "css" %}
</head>
<body>
{% cms_toolbar %}
{% placeholder "main" %}
import os
from fnmatch import fnmatch
import random
def get_random_file(folder, *extensions):
"""
get_random_file('/foo/bar', '*.jpg')
"""
files = [os.path.join(folder, fname) for fname in os.listdir(folder)]
pictures = [fpath for fpath in files if any([fnmatch(fpath, ext) for ext in extensions])]
@ojii
ojii / isthestoreopen.py
Created July 20, 2011 13:27
Is the Apple store open? (Linux User Version)
import requests
import time
store_open = False
while not store_open:
response = requests.get('http://store.apple.com/')
if "We'll be back soon" not in response.content:
break
print "Meh."
class AwesomeAdmin(ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
form_class = super(AwesomeAdmin, self).get_form(request, obj, **kwargs)
form_class.request = request
return form_class
@ojii
ojii / new_placeholder_tag.py
Created May 24, 2011 13:32
new_placeholder_tag.py
from cms.templatetags.cms_tags import Placeholder, PlaceholderOptions
from classytags.helpers import AsTag
from classytags.arguments import Argument, MultiValueArgument
from django import template
register = template.Library()
class NewPlaceholder(AsTag, Placeholder):
name = 'new_placeholder'
options = PlaceholderOptions(
@ojii
ojii / get_xml.php
Created May 18, 2011 09:06
PHP vs python requests
function get_xml( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "some-user-agent", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 60, // timeout on connect
@ojii
ojii / gist:964472
Created May 10, 2011 13:33
django request factory login
from django.conf import settings
from django.utils.importlib import import_module
from django.contrib.auth import SESSION_KEY, BACKEND_SESSION_KEY
def request_factory_login(factory, user, backend='django.contrib.backends.ModelBackend'):
engine = import_module(settings.SESSION_ENGINE)
factory.session = engine.SessionStore()
request.session[SESSION_KEY] = user.id
request.session[BACKEND_SESSION_KEY] = backend
factory.session.save()