Skip to content

Instantly share code, notes, and snippets.

@tswicegood
tswicegood / foo.py
Created May 25, 2013 20:58
Caption this Python
setattr(self, field, getattr(utils, '%s%s' % (prefix, field))(self))
@tswicegood
tswicegood / gist:5644776
Last active December 17, 2015 17:19
Example of how lambdas can generally be refactored into something more readable.
# using lambdas
def signed_in_both_chambers(self, **kwargs):
signed = lambda a: 'Signed in the %s' % a
return (self.filter(models.Q(bill_type='SB') | models.Q(bill_type='HB'))
.filter(actions__description=signed('House'))
.filter(actions__description=signed('Senate')))
# refactored into these methods
def has_action(self, action):
"""Filter QuerySet by a given action"""
@tswicegood
tswicegood / gist:5483232
Created April 29, 2013 17:29
Quick script for scraping the current rankins from the GEN public choice awards.
"""
Quick script for scraping the current rankins from the GEN public choice
awards.
"""
from pyquery import PyQuery as pq
import requests
URL = "https://app.wizehive.com/voting/dja2013/13447/%d"
entries = []
@tswicegood
tswicegood / README.md
Last active December 15, 2015 11:58 — forked from SeanJA/README.md

Set Up

You will need Sija's version of the garb gem, so add this line to your Gemfile (you will need git installed for this):

gem 'garb', :git => 'git://github.com/Sija/garb.git'

Then run the gem bundler: bundle install

Set your google username

@tswicegood
tswicegood / bump_django.py
Last active December 13, 2015 23:19
Simple scripts for creating a new bugfix release that bumps the top allowed version of Django and handling the tagging and uploading of a release. These are meant to be used on Armstrong, and assume that they're being executed in the parent directory of each of the components.
"""
Script for bumping a Django version from one to the next minor version
"""
import os
import sys
import envoy
def main():
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index ae792a3..c18907c 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -595,7 +595,10 @@ def create_many_related_manager(superclass, rel):
Returns the correct value for this relationship's foreign key. This
might be something else than pk value when to_field is used.
"""
- fk = self.through._meta.get_field(field_name)
+ try:
@tswicegood
tswicegood / gist:4628160
Last active December 11, 2015 16:29
Something to think about...
[15:21:38] <knowtheory> that guy, sometimes more trouble than he's worth.
[15:26:04] <tswicegood> knowtheory: lots of us programmer types are like that :-D
[15:26:56] <knowtheory> tswicegood: yeah, figuring out ways to work constructively seems important
[15:27:22] <tswicegood> not just important, imperative
[15:27:59] <tswicegood> otherwise: http://j.mp/V9mRV4 :-/
[15:28:38] <knowtheory> Yeah the interesting part is that some issues in programming are ultimately ones of philosophy or perspective
[15:28:56] <knowtheory> which are not technical issues to argue over, but ones that can only be hashed out by dealing with the intent of others
[15:29:12] <knowtheory> and communicating that seems to be a challenge w/ some folks
[15:29:29] <knowtheory> Yeah that thread is part of my diminished faith in humanity this week
[15:29:43] <knowtheory> (although not for the reason that HN seemed to be pissed off)
.
|____app
|____build
| |______init__.py
| |______main__.py
| |____convert.py
| |____extract.py
| |____retrieve.py
| |____save.py
|____data
# Add Current python path
export PATH=/usr/local/Cellar/python/2.7.3/bin:$PATH
export PATH=/usr/local/share/python:$PATH
@tswicegood
tswicegood / JavaScript.sublime-settings
Created September 30, 2012 16:00
My JavaScript syntax settings in ST2
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"detect_indentation": false,
"use_tab_stops": true
}