Skip to content

Instantly share code, notes, and snippets.

View dmpayton's full-sized avatar
🦄
Doin' all the things.

Derek Payton dmpayton

🦄
Doin' all the things.
View GitHub Profile
@dmpayton
dmpayton / mongoengine_middleware.py
Created January 18, 2011 04:37
Django middleware to ensure that a separate mongoengine connection is made per thread.
import mongoengine
from django.conf import settings
from django.core.exceptions import MiddlewareNotUsed
class MongoEngineConnectionMiddleware(object):
''' Ensure that a separate mongoengine connection is made per thread.
See: http://groups.google.com/group/mongoengine-users/browse_thread/thread/1aa3f9d65627c04
Assumes the following is your Django settings. Tweak as needed.
MONGODB = {
@dmpayton
dmpayton / gunicorn_middleware.py
Created January 20, 2011 20:03
I recently ditched runserver for gunicorn as my dev server. This middleware spits out request info as it comes in to make life a bit easier.
import sys
from datetime import datetime
from django.conf import settings
try:
from threading import local
except ImportError:
from django.utils._threading_local import local
_thread_locals = local()
@dmpayton
dmpayton / console.html
Created May 14, 2011 00:59
console.log
<!DOCTYPE html>
<html>
<head>
<title>console test.</title>
<script type="text/javascript">
// Fake out console.log so that certain browsers don't trip out.
function fauxConsole() { return {log: function(){ return }} }
var console = console || fauxConsole();
// Now you can use console.log without throwing errors.
@dmpayton
dmpayton / gist:1214764
Created September 13, 2011 19:11
django-celery + redis settings
## Store the core redis info in a dict so we can easily use redis-py later on:
## r = redis.StrictRedis(**settings.REDIS)
REDIS = {
'host': 'localhost',
'port': 6379,
'db': 0, ## General use goes to DB 0
'password': None,
'socket_timeout': None,
'connection_pool': None,
'charset': 'utf-8',
from libqtile.widgets.base import _TextBox
from libqtile import hook, bar, manager
class _StatusWidget(_TextBox):
''' Status Widget Base Class
'''
defaults = manager.Defaults(
## Required defaults
('font', 'Arial', 'Font'),
@dmpayton
dmpayton / gist:3670234
Created September 7, 2012 22:21
Qtile crash exception
2012-09-07 18:10:04,415 ERROR _xpoll:1086 Got an exception in poll loop
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/qtile-0.5-py2.7.egg/libqtile/manager.py", line 1082, in _xpoll
r = h(e)
File "/usr/local/lib/python2.7/dist-packages/qtile-0.5-py2.7.egg/libqtile/manager.py", line 1325, in handle_MapRequest
c = self.manage(w)
File "/usr/local/lib/python2.7/dist-packages/qtile-0.5-py2.7.egg/libqtile/manager.py", line 981, in manage
hook.fire("client_new", c)
File "/usr/local/lib/python2.7/dist-packages/qtile-0.5-py2.7.egg/libqtile/hook.py", line 185, in fire
i(*args, **kwargs)
@dmpayton
dmpayton / gist:6042465
Created July 19, 2013 21:26
openssh-server wants to install python-requests and python-urllib3
$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
ncurses-term python-requests python-urllib3 ssh-import-id
Suggested packages:
rssh molly-guard monkeysphere openssh-blacklist openssh-blacklist-extra
The following NEW packages will be installed:
ncurses-term openssh-server python-requests python-urllib3 ssh-import-id
@dmpayton
dmpayton / app.hy
Last active December 31, 2015 22:19
Parsing human datetime strings as a service [Hy + Flask]
(import [datetime [datetime]])
(import [flask [Flask request]])
(import [parsedatetime [parsedatetime]])
(import [time])
(setv app (Flask __name__))
(setv cal (parsedatetime.Calendar))
(with-decorator (app.route "/")
(defn parse [] (do
@dmpayton
dmpayton / notes.md
Last active August 29, 2015 13:57
django-balanced - rocket surgery
@dmpayton
dmpayton / food_reminder.py
Created April 21, 2014 22:32
Food Reminder
#!/usr/bin/env python
"""
Sends an SMS reminder to eat food at 10a, 1p, 4p, 7p, and 10p.
cron: 0 10,13,16,19,22 * * * /path/to/food_reminder.py
"""
from twilio.rest import TwilioRestClient