Skip to content

Instantly share code, notes, and snippets.

@mbylstra
mbylstra / gist:803de31188705dc658b0
Last active August 29, 2015 14:05
git: tell me which commits are in branch_b but not branch_a
git log branch_a ^branch_b --no-merges
@mbylstra
mbylstra / log uncaught exceptions.py
Created May 7, 2014 01:11
log uncaught exceptions
import logging
logger = logging.getLogger('some_logger')
def log_uncaught_exceptions(*exc_info):
logger.critical('Unhandled Exception:', exc_info=exc_info)
sys.excepthook = log_uncaught_exceptions
@mbylstra
mbylstra / gist:8050451
Created December 20, 2013 04:35
get a progress bar for large mysql imports and dumps
pv sqlfile.sql | mysql dbname
import traceback
try:
#some code
except Exception, e:
print ''.join(traceback.format_exception(*sys.exc_info()))
@mbylstra
mbylstra / gist:7727307
Created December 1, 2013 00:57
kill those wayward uwsgi processes that don't want to die with just killall
killall -SIGKILL uwsgi
mysql> pager less; # use less for paging
mysql> SELECT * FROM something \G #one field per line (good for wide tables)
@mbylstra
mbylstra / create_utf8_mysql_db
Last active December 23, 2015 23:19
create a utf8 mysql database
CREATE DATABASE some_db DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
@mbylstra
mbylstra / disable_mysql_foreign_key_checks
Created September 18, 2013 23:44
temporarily disable mysql foreign key checks, so you can do something dodgy:
SET foreign_key_checks = 0;
DELETE FROM users where id > 45;
SET foreign_key_checks = 1;
@mbylstra
mbylstra / py_datetime_to_mysql.py
Last active December 23, 2015 04:19
convert a python date to a mysql date string
from django.db import connection
from django.db.backends.mysql.base import DatabaseOperations
def py_datetime_to_mysql(d):
db_ops = DatabaseOperations(connection)
return db_ops.value_to_db_datetime(d)
#eg:
from django.db import connection
py_datetime_to_mysql(datetime.now())
#modified version off http://code.activestate.com/recipes/576602-safe-print/
def sprint(*args, **kwargs):
"""Safely print the given string.
If you want to see the code points for unprintable characters then you
can use `errors="xmlcharrefreplace"`.
"""
errors = kwargs.get('errors', 'replace')