This file contains hidden or 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
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| import argparse | |
| import random | |
| mappings = { | |
| 'a': u'ä', | |
| 'o': u'ö', | |
| 'u': u'ü', | |
| 'k': 'ch', |
This file contains hidden or 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
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| import argparse | |
| import random | |
| mappings = { | |
| 'a': [u'à', u'â'], | |
| 'c': [u'ç'], | |
| 'e': [u'é', u'è', u'ê'], | |
| } |
This file contains hidden or 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 justonce(){ | |
| E_BADARGS=65 | |
| if [ $# -lt 2 ] | |
| then | |
| echo "Usage: `justonce <envname> <command>`" | |
| exit $E_BADARGS | |
| fi | |
| workon $1 | |
| shift |
This file contains hidden or 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() |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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])] |