Skip to content

Instantly share code, notes, and snippets.

@shazow
shazow / meta.py
Created March 6, 2013 23:20
My latest SQLAlchemy model base class.
"""SQLAlchemy Metadata and Session object"""
import datetime
import json
import time
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
__all__ = ['Session', 'metadata', 'Model', 'SchemaEncoder']
@shazow
shazow / settings.py
Last active December 14, 2015 09:59
Django settings.py query logging
# ...
LOGGING = {
# ...
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
# ...
},
@shazow
shazow / autobackup.sh
Last active December 11, 2015 05:18
Database autobackup script.
#!/bin/bash
# Backup all the things, and delete old backups. (Perfect for a nightly cron job.)
# How many old backups should we keep?
NUM_OLD_BACKUPS=5
# Which databases should we worry about?
DATABASE_PREFIX="foo"
##
@shazow
shazow / develop.screenrc
Created January 5, 2013 23:35
Open development daemons in split gnu screen.
startup_message off
hardstatus alwayslastline
hardstatus string "%= %{r} Quit by hitting: qq"
escape q;
bind q quit
screen -t "Serve HTTP" 1 make serve
screen -t "Serve CSS" 2 make css_watch
@shazow
shazow / v1
Last active June 6, 2017 06:57
post-receive hook to push-deploy with git
#!/bin/bash
# post-receive hook to push-deploy multiple branches using a git repo.
#
# Deploy by pushing $DEPLOY_BRANCH
# Rollback by force-pushing a new reference to $OVERRIDE_TAG
#
# 1. Setup your git repo:
#
# git init --bare
#
@shazow
shazow / gist:4227021
Created December 6, 2012 18:48
Closure scopes in JavaScript.
(function() {
// This is a new closure. If things that happen here don't have side-effects on outside scope,
// then whatever happens here will not be visible outside of it.
(function() {
// You can make closures inside of closure (inside of closures). Wee.
})();
})();
def brandon_rhodes():
"""Complete the foo of the 1st argument.
Completing the foo is always difficult, you know?
But this function does it, else raises ValueError.
"""
pass
@shazow
shazow / gist:3928595
Last active November 18, 2022 14:24
Makefile which handles Python requirements.txt and *.egg-info (with optional virtualenv checking).
REQUIREMENTS_FILE=requirements.txt
REQUIREMENTS_OUT=requirements.txt.log
SETUP_OUT=*.egg-info
all: setup requirements
requirements: $(REQUIREMENTS_OUT)
$(REQUIREMENTS_OUT): $(REQUIREMENTS_FILE)
pip install -r $(REQUIREMENTS_FILE) | tee $(REQUIREMENTS_OUT)
@shazow
shazow / Makefile
Created September 21, 2012 04:37
pip install requirements only when they've changed.
requirements: requirements.txt.out
requirements.txt.out: requirements.txt
pip install -r requirements.txt | tee requirements.txt.out
@shazow
shazow / test_util.py
Created June 10, 2012 19:49
split_first
class TestUtil(TestCase):
def test_split_first(self):
test_cases = [
(
('abcd', ['b']),
('a', 'cd')
),
(
('abcd', ['c', 'b']),
('a', 'cd')),