Skip to content

Instantly share code, notes, and snippets.

@mudge
mudge / gist:263139
Created December 24, 2009 10:43
Polymorphic has_many :through in Rails 2.3
# A polymorphic has_many :through relationship in Rails 2.3
# based on Josh Susser's "The other side of polymorphic :through associations"
# http://blog.hasmanythrough.com/2006/4/3/polymorphic-through
class Authorship < ActiveRecord::Base
belongs_to :author
belongs_to :publication, :polymorphic => true
end
class Author < ActiveRecord::Base
has_many :authorships
@mudge
mudge / gist:289659
Created January 29, 2010 11:22
Provide a list of commonly-used tags to populate a text field.
/*
* Provide links to commonly-used tags that can be clicked by a user to
* populate a text field with comma-separated tags (ensuring that no
* duplicates are entered).
*
* This assumes that the text field has an ID of `tag_string` and the links
* have the class `tag`, e.g.
*
* <input type="text" name="tag_string" id="tag_string" />
* <ul>
require 'openssl'
require 'base64'
def encrypt_rsa_and_base64_encode(message, public_key_filename)
# Use open mode 'rb' for Windows compatibility.
public_key = OpenSSL::PKey::RSA.new(File.open(public_key_filename, 'rb') { |f| f.read })
Base64.encode64(public_key.public_encrypt(message))
end
@mudge
mudge / gist:313429
Created February 24, 2010 13:41
Update & Release workflow for development with git.
# Inspired by Rein Heinrich's "Hack && Ship"
# http://reinh.com/blog/2008/08/27/hack-and-and-ship.html
#
# Run these from a shell to add them to your ~/.gitconfig
git config --global alias.update 'merge --no-ff master'
git config --global alias.release '!CURRENT=$(git symbolic-ref HEAD) && git checkout master && git merge --no-ff --no-commit $CURRENT'
# Then your workflow will be something like this:
# 1. Create a new branch to work on
git checkout -b new_feature
" Simulate FuzzyFinder TextMate using only FuzzyFinder
" http://www.vim.org/scripts/script.php?script_id=1984
map <leader>t :FufFile **/<CR>
map <leader>b :FufBuffer<CR>
URxvt*background: #FFFFFF
URxvt*foregound: #222222
URxvt*font: xft:Inconsolata:pixelsize=14
URxvt*boldFont: xft:Inconsolata:bold:pixelsize=14
URxvt*saveLines: 12000
URxvt*scrollBar: false
URxvt*scrollstyle: rxvt
URxvt*perl-ext-common: default,matcher,tabbed
URxvt*urlLauncher: google-chrome
URxvt*matcher.button: 1
@mudge
mudge / gist:428455
Created June 7, 2010 09:29
Namespaces with Nokogiri::Builder
# Dealing with namespaces in Nokogiri.
#
# First thing you must do is abandon what you're used to with Builder,
# namespaces aren't just attributes on an element, they uniquely identify
# what sort of element you are building and, as such, you are better off
# specifying them manually.
#
# The key here is accessing the Nokogiri::XML::Element being built with
# b.parent, then you can set the namespace (distinguished by an element
# with a prefix such as "soap12:Envelope") or add a default namespace
@mudge
mudge / gist:455652
Created June 28, 2010 09:45
Compiling Git 1.7.1 on a Joyent Accelerator v2.1.4
wget http://kernel.org/pub/software/scm/git/git-1.7.4.tar.bz2
tar xvjf git-1.7.4.tar.bz2
cd git-1.7.4
./configure --prefix=/opt/git-1.7.4 --with-openssl=/opt/local --with-curl=/opt/local --with-expat=/opt/local --with-iconv=/opt/local --with-perl=/opt/local/bin/perl --with-python=/opt/local/bin/python --with-zlib=/opt/local --enable-pthreads=-pthreads
make
make test
make install
@mudge
mudge / gist:455810
Created June 28, 2010 13:09
Compiling Ruby 1.9.2 preview 3 on a Joyent Accelerator v2.1.4
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-preview3.tar.bz2
./configure --prefix=/opt/ruby-1.9.2 CFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib -R/opt/local/lib"
make
make test
make install
@mudge
mudge / application_helper.rb
Created September 14, 2010 18:50
JRuby class for using pegdown as the Rails Markdown processor.
require 'markdown'
module ApplicationHelper
def markdown(text)
if text.present?
Markdown.new(text).to_html
else
text
end
end