Skip to content

Instantly share code, notes, and snippets.

View mattjmorrison's full-sized avatar

Matthew J Morrison mattjmorrison

View GitHub Profile
@mattjmorrison
mattjmorrison / example_one.py
Created October 6, 2011 03:54
Python Mixins
import datetime
import json
class Jsonable(object):
def date_handler(self, obj):
return obj.isoformat() if isinstance(obj, (datetime.datetime, datetime.date)) else None
def save_json(self, file_name):
with open(file_name, 'w') as output:
@mattjmorrison
mattjmorrison / README
Created October 11, 2011 16:22
HTML Table Hilighting
Example In action: http://jsfiddle.net/r8wcY/
@mattjmorrison
mattjmorrison / oo.py
Created April 4, 2012 13:05
Python: Roll your own OO
def Module():
module_state = {}
def Class(val):
def get_val():
return val
class_state = {'get_val': get_val}
return class_state
@mattjmorrison
mattjmorrison / fake_oo.js
Created April 4, 2012 13:11
JavaScript: Roll your own OO
jQuery.noConflict();
MyClass = function($){
return function(val){
console.log("Constructing MyClass Instance");
var self = {};
self.getVal = function(){
return self.val;
};
self.val = val;
@mattjmorrison
mattjmorrison / 0_install.sh
Created April 7, 2012 13:22
Python Dependency Management: Part 2
sudo pip install virtualenv
@mattjmorrison
mattjmorrison / first_grade.py
Created April 8, 2012 16:53
Inherit Tests Cases
class FirstGradeMath(object):
def __init__(self, first_number, second_number):
self.first_number = first_number
self.second_number = second_number
def add(self):
return self.first_number + self.second_number
def subtract(self):
@mattjmorrison
mattjmorrison / autoworkon.sh
Created April 15, 2012 23:02
@toranb's Automatically 'workon' a virtualenv
# This makes 3 assumptions
# 1.) the root project directory must have a .git file (this way it won't try to "workon" in every single
# directory on your machine)
# 2.) the virtualenv name for your project must match the root directory name of your project
# 3.) you want it to auto switch virtualenvs for you when you jump between different project directories
# (when you hit another dir w/ a virtualenv that is)
workon_virtualenv() {
if [ -e .git ]; then
current_dir="${PWD##*/}"
@mattjmorrison
mattjmorrison / sample.rb
Created June 22, 2012 00:43
How the crap do I use define_method in a module? -- needs "self.included"
module SampleMod
def self.included(base)
[:one, :two, :three].each do |method_name|
define_method method_name do
puts "inside #{method_name}"
end
end
end
@mattjmorrison
mattjmorrison / Gemfile
Created June 22, 2012 01:58
Dynamic Thor Group
source 'https://rubygems.org'
gem 'thor'
@mattjmorrison
mattjmorrison / default
Created December 3, 2012 13:17
nginx config
server {
listen 80;
}
server {
listen 80;
server_name python.sample.com;
location / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;