Skip to content

Instantly share code, notes, and snippets.

@punund
punund / .rvmrc
Created November 16, 2011 22:52
.rvmrc common template
_RUBY=ruby-1.9.3
_PROJECT=dia-x
export rvm_gem_options="--no-rdoc --no-ri"
if [[ -s "${rvm_path:-$HOME/.rvm}/environments/$_RUBY@$_PROJECT" ]]
then
. "${rvm_path:-$HOME/.rvm}/environments/$_RUBY@$_PROJECT"
else
rvm --create use "$_RUBY@$_PROJECT"
@punund
punund / author.rb
Created June 19, 2011 15:45
Generation of alphanumeric person handle
#
# This automatically creates a "handle" upon creation of person's record.
#
# "John Doe"'s handle shall look like "DO<x>J", where <x> is a minimal necessary number of digits,
# so we have to look up the existing handles first. We exclude zeros (to avoid confusion with Os)
# and ones (to exclude jealousy "to be the first"), so we conveniently employ octal digits and add
# two subsequently. We also have to do the best effort to normalize last names (drop diacritics,
# honorifics, Celtic and Dutch name prefixes, sr/jr suffixes, etc. to maximize variance.
#
# See this in action at http://dia-x.info/authors
@punund
punund / fen_controller.rb
Created June 19, 2011 13:59
Dynamic creation of chess diagrams
#
# responds to requests with Forsyth-Edwards notation in URL with an image:
# http://dia-x.info/fen/2S5/1bQKpR2/4s3/2bkpP2/Sr1p2r1/1P1R3B/1B2s3/8
#
class FenController < ApplicationController
include Magick
@punund
punund / gist:1034276
Created June 19, 2011 13:31
Proper exception handling in Rails 3
# coding: utf-8
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from Exception, :with => :handle_exceptions
private
def handle_exceptions(e)
case e
when CanCan::AccessDenied