Skip to content

Instantly share code, notes, and snippets.

@mrowl
mrowl / enum_int_type.py
Created January 19, 2011 17:31
This defines a new enum type using the sqlalchemy type decorator. Data is stored with the sqlalchemy SmallInteger type while strings are used with the model. Preferable to the varchar (too large) or native enum (pain on postgres).
import sqlalchemy as sa
class EnumIntType(sa.types.TypeDecorator):
impl = sa.types.SmallInteger
values = None
def __init__(self, values=None):
sa.types.TypeDecorator.__init__(self)
self.values = values
@mrowl
mrowl / dynamic_roles.rb
Created January 24, 2011 18:00
Add functions to a rails activerecord model dynamically for testing role membership
class User < ActiveRecord::Base
#available roles for users
ROLES = ['uber', 'admin', 'mod']
#generates methods like user.admin? for testing whether the user belongs to
#the proper role
ROLES.each do |role_name|
self.send(:define_method, "#{role_name}?".to_sym) { self.role == role_name }
end
@mrowl
mrowl / about.md
Created August 12, 2011 03:13 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@mrowl
mrowl / chromium_opener.sh
Created August 17, 2011 01:49
Chromium url opener for xmonad
#!/bin/bash
#
#Converts the input url to utf-8 from ISO-8859 (xmonad's prompt format), then
#opens the url with chromium, which seems to require utf-8 urls.
query=`echo ${1} | iconv -f ISO-8859-1 -t UTF-8`
echo "${0} ${query}" >> /tmp/search_log.txt
chromium ${query}
@mrowl
mrowl / env_run.sh
Created August 18, 2011 04:04
Script for running sandboxed apps from outside the virtualenv environment. Useful when managing apps with supervisor.
#!/bin/bash
# Runs any command (the args) in the virtualenv environment where this script resides.
# You need to change the ACTIVATE_PATH variable
# depending on where your virtualenv activate file is relative to this script.
# The WORKING_DIR var controls the directory from which the command will be run.
# I put this in a bin folder at the top level of my app.
# my virtualenv structure:
# /my_env
# /my_env/bin ( with the venv activate script )
# /my_env/my_app
@mrowl
mrowl / receive_head.sh
Created August 18, 2011 23:08
Fetch html headers sans content
curl -s -D - -o /dev/null http://www.google.com
@mrowl
mrowl / config.rb
Created September 2, 2011 20:18
Generating Tornado style static urls in Sass
require 'digest/md5'
module Sass::Script::Functions
# Returns a url for static media (e.g. an icon) consistent with those
# generated by the static_url method in Tornado templates. The method
# takes an md5 hash of the given file and attaches the first five chars to
# the 'v' GET param in the url (i.e. it appends "?v=<hash_slice>").
# Assumes you use a somewhat conventional Tornado layout:
# myapp/myapp - your code
import putio
import logging
from flexget import validator
from flexget.plugin import register_plugin
log = logging.getLogger('putio')
class PutIOPlugin(object):
"""
Plugin to add and fetch your torrents on put.io
@mrowl
mrowl / ThingsAdapter.java
Created February 28, 2015 16:57
Shim between RecyclerView.Adapter and ParseAdapter
public class ThingsAdapter extends RecyclerView.Adapter<ThingsAdapter.ViewHolder> {
private ParseQueryAdapter<ParseObject> parseAdapter;
private ViewGroup parseParent;
private ThingsAdapter thingsAdapter = this;
public ThingsAdapter(Context context, ViewGroup parentIn) {
parseParent = parentIn;