Skip to content

Instantly share code, notes, and snippets.

Michael Bylstra mbylstra

Block or report user

Report or block mbylstra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mbylstra
mbylstra / gist:803de31188705dc658b0
Last active Aug 29, 2015
git: tell me which commits are in branch_b but not branch_a
View gist:803de31188705dc658b0
git log branch_a ^branch_b --no-merges
View log uncaught exceptions.py
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 Dec 20, 2013
get a progress bar for large mysql imports and dumps
View gist:8050451
pv sqlfile.sql | mysql dbname
View print Exception stack trace
import traceback
try:
#some code
except Exception, e:
print ''.join(traceback.format_exception(*sys.exc_info()))
@mbylstra
mbylstra / gist:7727307
Created Dec 1, 2013
kill those wayward uwsgi processes that don't want to die with just killall
View gist:7727307
killall -SIGKILL uwsgi
View mysql command line stuff
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 Dec 23, 2015
create a utf8 mysql database
View create_utf8_mysql_db
CREATE DATABASE some_db DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
@mbylstra
mbylstra / disable_mysql_foreign_key_checks
Created Sep 18, 2013
temporarily disable mysql foreign key checks, so you can do something dodgy:
View disable_mysql_foreign_key_checks
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 Dec 23, 2015
convert a python date to a mysql date string
View py_datetime_to_mysql.py
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())
View safe_print.py
#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')
You can’t perform that action at this time.