Skip to content

Instantly share code, notes, and snippets.

View cshoe's full-sized avatar
🚵

Chris Schomaker cshoe

🚵
View GitHub Profile
importer = ImpImporter('full/path/to/module/dir/')
loader = importer.find_module(<module name without .py>)
m = loader.load_module(<module name without .py>)
@cshoe
cshoe / gist:2772000
Created May 22, 2012 22:15
Python Logging DictConfig
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'basic': {
'format': '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s',
}
},
'handlers': {
'console': {
@cshoe
cshoe / logging.py
Created May 23, 2012 20:55
Python dictConfig Logging
DEV_LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'basic': {
'format': '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s',
}
},
'handlers': {
'console': {
@cshoe
cshoe / untracked.py
Created January 9, 2013 21:12
untracked.py
from .local import *
DEBUG = True
TEMPLATE_DEBUG = False
DJANGO_DEBUG_TOOLBAR = False
if DJANGO_DEBUG_TOOLBAR:
def extend_tuple(tuple_to_modify, *args):
# Use this function to simply add elements to an existing tuple
return tuple([item for item in tuple_to_modify] + [arg for arg in args])
@cshoe
cshoe / tag_delete_test.py
Last active December 10, 2015 23:59
Delete Tag Test
import json
import oauth2
# FILL THESE OUT
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
# has to be an access token, not a request token
TOKEN = ''
@cshoe
cshoe / or_experiment.py
Created January 14, 2013 16:49
Proving that Python only evaluates to the first `True` value in an or statement.
def first_function(return_value):
"""Returns `return_value`.
"""
print 'Running FIRST function'
return return_value
def second_function(return_value):
"""Returns `return_value`.
def main():
# this is the dict that we want to trim down.
# basically we want to collapse `foo` into a list for a common `id`
bloated_map = [{'foo': 2, 'id': 160},
{'foo': 314, 'id': 160},
{'foo': 314, 'id': 161},
{'foo': 2, 'id': 161}]
# this gives us a list of unique ids
id_list = set([x['id'] for x in bloated_map])
@cshoe
cshoe / cache_count.py
Created January 25, 2013 20:09
Throttling with cache
def inc_and_get_request_count(token):
"""Increment the request count for `token` and return the new count.
"""
cache_key = COUNT_CACH_TEMPLATE.format(token)
try:
count = cache.incr(cache_key)
except ValueError:
# key doesn't exist in cache. insert it, start it at 1
count = 1
In [1]: from django.core.cache import cache
In [2]: key = 'blah'
In [3]: cache.incr('blah')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-154660d05ec4> in <module>()
----> 1 cache.incr('blah')
@cshoe
cshoe / gist:5092303
Last active December 14, 2015 13:19
Thoughts on samhuntphoto.com

Homepage

Seems a bit happhazard. Of all the photos on the site, I'd say the vodka one is one of the least strong. I'm curious as to why you picked it.

The mouse over copywrite thing is unneccessary. Just put "All Images Copywrite Sam Hunt" somewhere in the footer. Better typography needed but here's the idea: http://i.imgur.com/XpMDEMN.png.

Navigation