This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFMCGT2Lz0LKndS26QHocSa7bJ/8kabu1JQbYJQ8sGd0Y1RbOLnJZiibM0uE0mvSTeXyxuNJyyPe7nvSR4aNfq5bn7dA8ek7Siy1449kA22nwI/GM62fYfIDwAt6GJSvacCKaZWokQ/kiZ9UG9anE+RXR1GSDgE42CPfcT0VFDu83TQ0/55qEfmMWimFqoZG/dCUGarTmNta+irEy4JL0VNQ2B59IDW/WskmgP6EuGBUoCiuOy95SiFS5t/SQrRebpDTtLiSvb+4lbL2BmAUQnuPoYPgLbj62w5n/E9qWbYCck/00TGSjvQfZeSXJYDYlEpbVMGx7p0C3S89+KB26/ [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load cms_tags sekizai_tags %} | |
<!doctype html> | |
<head> | |
<title>{{ request.current_page.get_title }}</title> | |
{% render_block "css" %} | |
</head> | |
<body> | |
{% cms_toolbar %} | |
{% placeholder "main" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |