Skip to content

Instantly share code, notes, and snippets.

@mbylstra
mbylstra / scratchpad.py
Last active March 5, 2019 23:14
Django scratchpad file. A standalone Django script with the django environment loaded.Place in the root of your Django project. Assumes your settings.py is in a folder named 'main'.
import os
import sys
project_dir = os.path.realpath(__file__)
sys.path.append(project_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'main.settings'
import django
from django.conf import settings
django.setup()
@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
@mbylstra
mbylstra / gist:aae6eac98d162a5cc9c2
Last active September 20, 2016 06:32
python mixin inheritance
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# MixinParent
# |
# Mixin A
# └--┐ |
# B
@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()))
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;