Skip to content

Instantly share code, notes, and snippets.

View mattjmorrison's full-sized avatar

Matthew J Morrison mattjmorrison

View GitHub Profile
@mattjmorrison
mattjmorrison / mixin.py
Created September 22, 2011 00:32
Python Mixin Recipe
# http://littletutorials.com/2008/06/23/inheritance-not-for-code-reuse/
def mixin(mixin_cls):
def mixin_decorator(cls):
if not hasattr(cls, '__mixed__'):
cls.__mixed__ = []
for name, val in mixin_cls.__dict__.items():
if not name.startswith('__') and not name.endswith('__'):
if not hasattr(cls, name):
setattr(cls, name, val)
@mattjmorrison
mattjmorrison / crop_and_resize.py
Created April 20, 2011 19:03
Resize and Crop images with Python and PIL
from PIL import Image, ImageChops
def trim(im, border):
bg = Image.new(im.mode, im.size, border)
diff = ImageChops.difference(im, bg)
bbox = diff.getbbox()
if bbox:
return im.crop(bbox)
def create_thumbnail(path, size):
@mattjmorrison
mattjmorrison / .vimrc
Last active August 1, 2020 14:28
Vimfiler Config
set nocompatible
if !1 | finish | endif
if has('vim_starting')
set nocompatible " Be iMproved
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
let neobundle_readme=expand($HOME.'/.vim/bundle/neobundle.vim/README.md')
if !filereadable(neobundle_readme)
silent !curl https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh | sh
endif
@mattjmorrison
mattjmorrison / .gitignore
Last active January 3, 2019 15:33
Tool Instructions
.vagrant/
*.swp
@mattjmorrison
mattjmorrison / test_django_q.py
Created April 28, 2011 19:35
How to mock django's Q object
@patch('quote_options.models.LiabilityLimit.objects.filter')
@patch('quote.models.Q')
def should_filter_with_q_object_in_get_liability_limits(self, q_object, limit_filter):
manager_instance = Mock(spec=quote_models.LiabilityManager())
policy = mock.Mock()
q_instance = mock.Mock()
q_or_method = mock.Mock()
q_or_method.return_value = q_instance
q_instance.__or__ = q_or_method
@mattjmorrison
mattjmorrison / setup.sh
Created December 4, 2013 05:39
New imtapps macbook setup
curl https://raw.github.com/toranb/osx-workstation/master/installer | bash
git clone https://github.com/JarrodCTaylor/imt_dotfiles.git
cd ~/imt_dotfiles/Mac
bash symlink.sh
@mattjmorrison
mattjmorrison / .zshrc
Created November 30, 2013 14:27
.zshrc
#!/bin/zsh
# vim: set foldmarker=<<,>> foldlevel=1 foldmethod=marker:
#===================================================================================
# .__
# ________ _____| |_________ ____
# \___ / / ___/ | \_ __ \_/ ___\
# / / \___ \| Y \ | \/\ \___
# /_____ \/____ >___| /__| \___ >
# \/ \/ \/ \/
#===================================================================================
echo "Loading Aliases"
alias ls='ls -FHG'
alias ll='ls -lh'
alias la='ls -la'
alias l='ls'
alias lls='ll -Sr'
alias less='less -imJMW'
alias update='brew update && brew upgrade'
alias upgrade='brew upgrade'
alias clean='brew doctor'
@mattjmorrison
mattjmorrison / emacs-bindings.plugin.zsh
Last active December 29, 2015 15:39
zsh emacs key bindings
echo "Loading Emacs Bindings"
bindkey '^b' backward-word
bindkey '^f' forward-word
bindkey '^R' history-incremental-search-backward
bindkey '^R' history-incremental-pattern-search-backward
bindkey '^?' backward-delete-char
bindkey '^H' backward-delete-char
@mattjmorrison
mattjmorrison / aliases.plugin.zsh
Last active December 29, 2015 15:39
IMT zsh aliases
echo "Loading Aliases"
alias ls='ls -FHG'
alias ll='ls -lh'
alias la='ls -la'
alias l='ls'
alias lls='ll -Sr'
alias less='less -imJMW'
alias update='brew update && brew upgrade'
alias upgrade='brew upgrade'
alias clean='brew doctor'