This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'markdown' | |
module ApplicationHelper | |
def markdown(text) | |
if text.present? | |
Markdown.new(text).to_html | |
else | |
text | |
end | |
end |