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
#!/usr/bin/env python | |
# A tiny appscript example in Python. | |
import appscript | |
appscript.app("iTunes").current_track.artist.get() |
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, sys | |
import site | |
# put virtualenv on pythonpath | |
site.addsitedir('/path/to/project/ve/lib/python2.5/site-packages') | |
# redirect prints to apache log | |
sys.stdout = sys.stderr | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' |
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 Adafruit_BBIO.PWM as PWM | |
servo_pin = "P8_13" | |
duty_min = 2.5 | |
duty_max = 13.1 | |
duty_span = duty_max - duty_min | |
PWM.start(servo_pin, duty_span * 0.5, 60.0) | |
while True: |
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
def github(query, url): | |
url = "https://github.com/%s/issues" % url | |
# Direct to issue number | |
try: | |
redirect("%s/%s" % (url, int(query))) | |
except ValueError: | |
# New ticket | |
if query == "new": | |
redirect("%s/new" % url) | |
# Issue list |
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
# GIVEN: | |
# `counties` is a dict with each key being the slug of a county, | |
# containing a sub-dict with keys including vote counts and stuff. | |
# each candidate's vote count is stored in a key that is the candidate's | |
# name as a slug | |
# find vote leader for each county and store it in a 'leader' key for that county | |
for county_slug in counties.iterkeys(): | |
vals = [(candidate, counties[county_slug][candidate]) for candidate in CANDIDATES] | |
vals.sort(key=lambda c: c[1], reverse=True) |
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 SomeForm(forms.Form): | |
name = forms.CharField(max_length=200) | |
def __init__(self, *args, **kwargs): | |
super(SomeForm, self).__init__(*args, **kwargs) | |
self.fields["name"].max_length = 300 | |
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 QuerySetDoubleIteration(Exception): | |
"A QuerySet was iterated over twice, you probably want to list() it." | |
pass | |
# "Skinny" here means we use iterator by default, rather than | |
# ballooning in memory. | |
class SkinnyManager(Manager): | |
def get_query_set(self): | |
return SkinnyQuerySet(self.model, using=self._db) |
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
// Add to 'Default (OSX).sublime-keymap' | |
// Reverse selected lines. | |
[ | |
{ "keys": ["super+shift+r"], "command": "permute_lines", "args": {"operation": "reverse"} } | |
] |
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
""" | |
This fabric script automates the creation of a virtual environment and a Django | |
project. The result will be virtual environtment with the name of the project. | |
The folder namer where the project code will be placed is specified in | |
SOURCE_DIRECTORY_NAME, a static root folder will be created and settings.py | |
will be updated. | |
""" | |
try: | |
from fabric.api import env, run, local | |
from fabric.context_managers import lcd, prefix |
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
""" | |
jQuery templates use constructs like: | |
{{if condition}} print something{{/if}} | |
Or like: | |
{% if condition %} print {%=object.something %}{% endif %} | |
This, of course, completely screws up Django templates, |
OlderNewer