Skip to content

Instantly share code, notes, and snippets.

View unbracketed's full-sized avatar

Brian Luft unbracketed

View GitHub Profile
@unbracketed
unbracketed / twitter_golden_ratios.py
Created May 29, 2010 06:17
A quick and dirty script that aggregates Twitter account golden ratios using Redis to store data.
import redis
import time
import twitter
twitter = twitter.Twitter()
R = redis.Redis()
while True:
for tweet in twitter.statuses.public_timeline():
from flask import Module, request, redirect, url_for, render_template, abort
from formalchemy import FieldSet
from example import db
from example import Service, User, Forum, Category, Topic, Post
mod = Module(__name__)
models = {
import redis
from django.conf import settings
from django.core.signals import request_finished
try:
from eventlet.corolocal import local
except ImportError:
from threading import local
@SmileyChris
SmileyChris / postactivate
Created December 8, 2010 20:33
~/.virtualenvs/postactivate: switch to working directory initially if it exists, and allow switiching between the env root and the working directory by typing "cd"
WORKDIR=$HOME/work/`basename $VIRTUAL_ENV`
cd () {
if (( $# == 0 )); then
if [ -d $WORKDIR ] && [ `pwd` != $WORKDIR ]; then
builtin cd $WORKDIR
else
builtin cd $VIRTUAL_ENV
fi
else
# This all assumes you have the process running in
# a terminal screen and you're on Linux-like system.
# First off, suspend the process and background it
ctrl-z # suspend the process
bg # restart/continue the process in the background
# Now create files to log to. They can be called anything,
# Personally I would end the in .log. E.g. could be
# /var/logs/myprocess-stdout.log,
@unbracketed
unbracketed / dump_and_restore_DBs.sh
Created February 23, 2011 18:20
Recipes for dumping and restoring different databases, using different compression formats
#Dump
mysqldump db | gzip -c > db.sql.gz
pg_dump db | gzip -c > db.sql.gz
#use gzip --fast
#Restore
gunzip < db.sql.gz | mysql db
bunzip2 < db.sql.bz2 | mysql db
@unbracketed
unbracketed / RFDV-pip-findlinks-cache.sh
Created April 1, 2011 23:45
Python packages that I like to start every new virtualenv with
"""
Patches the database wrapper and template engine to throw an exception if a query is executed inside of a template.
In your urls.py, enable it like so:
>>> import monkey
>>> monkey.patch_templates()
"""
import logging
:+1:
:-1:
:airplane:
:art:
:bear:
:beer:
:bike:
:bomb:
:book:
:bulb:
@unbracketed
unbracketed / mysql-column-search.sql
Created September 1, 2011 06:12
mysql find all uses of column name
--http://stackoverflow.com/questions/193780/how-to-find-all-the-tables-in-mysql-with-specific-column-names-in-them
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('columnA','ColumnB')
AND TABLE_SCHEMA='YourDatabase';