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
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: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
@mbylstra
mbylstra / gist:1409f46992c81b6f0e6e
Created Aug 22, 2014
recursively sort python files by number of lines of code
View gist:1409f46992c81b6f0e6e
find . -name '*.py' | xargs wc -l | sort -k1 -rg | less
@mbylstra
mbylstra / gist:415501b38544d1e6db02
Created Aug 27, 2014
show me nginx access.log 500's with surrounding 10 lines.
View gist:415501b38544d1e6db02
awk '{ print $9, $7}' access.log | grep -C 10 '^500'
@mbylstra
mbylstra / gist:9412f80ffcaad3d76474
Created Oct 5, 2014
remove all .pyc files recursively
View gist:9412f80ffcaad3d76474
find . -name "*.pyc" -exec rm '{}' ';'
@mbylstra
mbylstra / django_manage_daemon.yml
Created Oct 8, 2014
An Ansible playbook for daemonising long running django manage.py commands using runit
View django_manage_daemon.yml
---
- hosts: django
user: root
vars:
- runit_app_dir: /etc/sv
- runit_enabled_dir: /etc/service
- dj_manage_daemons:
- slug: "unique_name_slug_1"
@mbylstra
mbylstra / gist:c33077198227115ae590
Created Mar 18, 2015
turn on/off psql pager (annoying for \dt)
@mbylstra
mbylstra / gist:813d1a9c25cf671bb1a4
Created Mar 18, 2015
linux: temporarily change timezone for ls command
View gist:813d1a9c25cf671bb1a4
env TZ=Australia/Melbourne ls -al
@mbylstra
mbylstra / gist:385fa8cbf22e58b3aa62
Last active Dec 3, 2015
django 1.7+ standalone script
View gist:385fa8cbf22e58b3aa62
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
django.setup()
################################################################################
@mbylstra
mbylstra / djr_simple_api_view
Last active Dec 19, 2015
If you just want to use Django Rest Framework for authentication and just want to convert a dictionary to json.
View djr_simple_api_view
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
from rest_framework.views import APIView
class SimpleView(APIView):
renderer_classes = (JSONRenderer,)
permission_classes = (IsAuthenticated,)
def get(self, request):
content = {'testing': 123}
You can’t perform that action at this time.