Skip to content

Instantly share code, notes, and snippets.

View unbracketed's full-sized avatar

Brian Luft unbracketed

View GitHub Profile
@unbracketed
unbracketed / export_repo_issues_to_csv.py
Last active August 3, 2023 18:13
Export Issues from Github repo to CSV (API v3)
"""
Exports Issues from a specified repository to a CSV file
Uses basic authentication (Github username + password) to retrieve Issues
from a repository that username has access to. Supports Github API v3.
"""
import csv
import requests
@unbracketed
unbracketed / jsonit-form-response-example.js
Created March 7, 2012 21:29
Ajax form submit handler example using jsonit
function ajaxSubmit(formContext, invokeCustomFunc) {
var form = formContext,
groupErrors = $(formContext).hasClass('group-errors');
$('.error-message', form).html('').hide();
$('.error', form).removeClass('error');
// TODO: show a loader img, to avoid double clicking
@unbracketed
unbracketed / survey.py
Created November 30, 2011 17:21
Think Stats Chapter 1 exercises
import gzip
from collections import namedtuple
PREG_COLS = [
('caseid', 1, 12, int),
('nbrnaliv', 22, 22, int),
('babysex', 56, 56, int),
('birthwgt_lb', 57, 58, int),
('birthwgt_oz', 59, 60, int),
@unbracketed
unbracketed / south_migration_duplicates.py
Created October 3, 2011 18:42
Git post-commit hook checks for duplicate-numbered South migrations
def ensure_no_duped_migrations():
migration_dirs = local('find %s -type d -iname migrations' % ROOT_DIR,
True).split('\n')
for migration_dir in migration_dirs:
full_migration_dir = path.join(ROOT_DIR, migration_dir)
# FIXME: for GNU find, need regextype=posix-extended
dupe_checker = ("find -E %s -iregex '.*/[0-9]{4,}[^/]*\.py' -exec basename {} ';'| cut -d_ -f1 | sort | uniq -d" %
full_migration_dir)
any_match = local(dupe_checker, True)
@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';
@unbracketed
unbracketed / irssi_notify.py
Created June 9, 2011 22:02
irssi notifications
#!/usr/bin/env python
""" irssi desktop notifications.
Connects to a remote irssi log file, looks for your nick,
and displays a desktop notification.
Credit: Graham King
"""
import subprocess
import os
@unbracketed
unbracketed / gen_mptt.py
Created April 28, 2011 15:05
Generate MPTT preorder for in-memory tree
"""
Inserting many items into a django-mptt table can be problematic.
(Importing a large data set for example)
The preorder values (left/right) have to be recalculated with
each insertion so as the size of the table grows INSERTs take
progressively longer each time.
This code snippet demonstrates a case of determining the preorder
values for the hierarchy of directories starting with a root dir.
@unbracketed
unbracketed / RFDV-pip-findlinks-cache.sh
Created April 1, 2011 23:45
Python packages that I like to start every new virtualenv with
@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 / favorite_nix_cmds.sh
Created December 4, 2010 22:14
Keeps track of favorite shell cmds, tricks
#run last command as root
sudo !!
#change to previous dir
cd -
#save current file when you forgot to open with sudo
:w !sudo tee %
#show size of subdirs