Skip to content

Instantly share code, notes, and snippets.

View bkeating's full-sized avatar
🤙
Gettin’ SUM & CALCin’ out

Benjamin Keating bkeating

🤙
Gettin’ SUM & CALCin’ out
View GitHub Profile
@mkhl
mkhl / py-appscript.py
Created November 24, 2008 08:34
Appscript ⁄ ScriptingBridge
#!/usr/bin/env python
# A tiny appscript example in Python.
import appscript
appscript.app("iTunes").current_track.artist.get()
@lincolnloop
lincolnloop / django.wsgi
Created March 13, 2009 03:22
Django mod_wsgi scripts
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'
@Annath
Annath / servo.py
Last active September 25, 2015 08:46
Quick servo code for the Beaglebone Black using the Adafruit BBIO python library and a Parallax Standard servo
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:
@bitprophet
bitprophet / gist:1189894
Created September 2, 2011 20:56
Partial Cony settings file
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
@mtigas
mtigas / gist:1961114
Created March 2, 2012 20:36
lambda assisted elections magic
# 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)
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
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)
@ryanlabouve
ryanlabouve / gist:2322528
Created April 6, 2012 19:56
Sublime text keybinding for reversing selecting lines
// Add to 'Default (OSX).sublime-keymap'
// Reverse selected lines.
[
{ "keys": ["super+shift+r"], "command": "permute_lines", "args": {"operation": "reverse"} }
]
@IlianIliev
IlianIliev / fabfile.py
Created May 28, 2012 11:04
Fabric script that eases the creation of new Django Project
"""
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
"""
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,