Skip to content

Instantly share code, notes, and snippets.

View veryhappythings's full-sized avatar
👋
Hello!

Mac Chapman veryhappythings

👋
Hello!
View GitHub Profile
@veryhappythings
veryhappythings / Python_sax_template.py
Created April 20, 2009 16:15
As basic as a python SAX parser can get.
import sys, string
from xml.sax import saxutils, handler, make_parser
class ContentGenerator(handler.ContentHandler):
def __init__(self, out = sys.stdout):
handler.ContentHandler.__init__(self)
@veryhappythings
veryhappythings / iterative_kember.py
Created May 7, 2009 16:44
A brute force way to find the Kember Identity.
# A brute force way to find the Kember Identity.
# By Mac, @veryhappythings, on a boring afternoon.
# If you want, you can run it with the last attempt as an argument and it'll start there.
import hashlib
import sys
def iterative():
last_attempt = len(sys.argv) > 1 and int(sys.argv[1]) or 0
try:
@veryhappythings
veryhappythings / tm-vat_convert.py
Created May 11, 2009 09:52
TextMate command to convert VAT from 17.5% to 15%
#!/usr/bin/env python
import os
import sys
try:
sys.stdout.write('%.2f' % ((float(os.environ.get('TM_SELECTED_TEXT')) / 1.175) * 1.15))
except:
sys.stdout.write(os.environ.get('TM_SELECTED_TEXT'))
@veryhappythings
veryhappythings / bash_git_prompt.sh
Created May 11, 2009 19:35
I can't remember where I found this, so I just gist'ed it. Not my work.
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
@veryhappythings
veryhappythings / search_twitter.rb
Created May 19, 2009 13:28
Searching Twitter for things.
# ruby search_twitter.rb <username> <search string>
require 'rubygems'
require 'twitter'
Twitter::Search.new(ARGV[1]).from(ARGV[0]).each { |r| puts '--------------------------------', r.text }
@veryhappythings
veryhappythings / pomo_timer.rb
Created June 1, 2009 22:24
A simple timer for the pomodoro technique, written using Shoes.
# http://www.pomodorotechnique.com/
Shoes.app :width => 200, :height => 150, :resizable => false, :title => 'Pomo!' do
def update_time!
@timer_display.text = '%02d:%02d' % [@seconds / 60, @seconds % 60]
end
background whitesmoke
paused = true
@seconds = 0.0
@veryhappythings
veryhappythings / sort_dicts_of_dicts.py
Created June 26, 2009 10:14
An example of sorting dicts of dicts for my blog
from operator import itemgetter
files = {
'first' : {'filename': 'first.xml', 'priority': 0},
'second': {'filename': 'second.xml', 'priority': 4},
'third' : {'filename': 'third.xml', 'priority': 0},
'fourth': {'filename': 'fourth.xml', 'priority': 3},
'fifth' : {'filename': 'fifth.xml', 'priority': 6},
}
@veryhappythings
veryhappythings / healthii_twitterverse.rb
Created July 30, 2009 17:03
A little script for a friends project - scans the twitterverse and tells you how everyone's feeling today.
require 'rubygems'
require 'twitter'
HEALTHII_TAG_REGEX = /#healthii\((\d{4}):?(.*)?\)/
BUSYNESS, STRESS, HEALTH, ENGAGEMENT = 0, 1, 2, 3
def mean(numbers)
numbers.inject {|sum, n| sum + n } / numbers.length.to_f
end
@veryhappythings
veryhappythings / pretty_print_tm.py
Created August 18, 2009 14:27
Pretty print command for textmate. Works in extremely limited situations!
#!/usr/bin/env python
import json
import os
import pprint
import sys
input = os.environ.get('TM_SELECTED_TEXT')
input = input.replace("'", '"')
sys.stdout.write(pprint.pformat(json.loads(input)))
@veryhappythings
veryhappythings / django-template_for.py
Created August 20, 2009 07:29
Get the template for a view in django.
# Maybe I'm missing the point, but coming from a bit of
# rails experience I find that it's a pain that views
# have to be told which template to render to.
# This method is a way, but probably not the right way,
# to derive a template name from an object.
# It expects to be called from a view, by the way.
import inspect
def template_for(obj, content_type='html'):
return '{app}/{obj}_{func_name}.{content_type}'.format(app=obj._meta.app_label,