Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Celis stephencelis

View GitHub Profile
View open-uri-cache.rb
require 'open-uri'
require 'digest/md5'
class << OpenURI
CACHE_DIR = Rails.root.join 'tmp', 'cache', 'open-uri'
CACHE_DIR.mkdir unless CACHE_DIR.exist?
alias cache_original_open_uri open_uri
def open_uri name, *rest, &block
snap = Digest::MD5.hexdigest name.to_s
@stephencelis
stephencelis / Gemfile
Created Dec 21, 2010
CoffeeScript template handler for Rails 3.
View Gemfile
gem 'coffee-script'
gem 'rails_assets', :git => 'git://github.com/wycats/rails_assets.git'
View chinos.rb
# encoding: utf-8
#
# Smarter than SmartyPants? For plain text.
module Chinos
extend self
def educate(text)
educate_quotes educate_ellipses(educate_dashes(text))
end
@stephencelis
stephencelis / .gvimrc
Created Jan 26, 2010
MacVim meets WriteRoom
View .gvimrc
" MacVim meets WriteRoom.
if has("autocmd")
augroup txt
au!
autocmd GUIEnter *.txt set nolist
autocmd GUIEnter *.txt set columns=80
autocmd GUIEnter *.txt set noruler
autocmd GUIEnter *.txt set nonumber
autocmd GUIEnter *.txt set linebreak
@stephencelis
stephencelis / gist:286436
Created Jan 26, 2010 — forked from qrush/gist:286431
_why's ~/.screenrc
View gist:286436
# .( screenrc ). for _why :: * supports xterm/rxvt titles
# * default encoding is utf-8 (i use urxvt with this)
setenv LC_CTYPE en_US.UTF-8
defutf8 on
autodetach on
crlf off
#deflogin off
hardcopy_append on
View app.rb
# Define application-level configuration using a simple DSL.
#
# class App < Configuration
# config.key = "value"
# config.lazy = lambda { |load| load }
# end
#
# App.key # => "value"
# App.key? # => true
# App.lazy("load") # => "load"
View asset_expansions.rb
ActionView::Helpers::AssetTagHelper.register_javascript_expansion({
html5shiv: "http://html5shiv.googlecode.com/svn/trunk/html5.js",
ie7js: "http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js",
ie8js: "http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js",
jquery: "http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"
})
@stephencelis
stephencelis / validates_is.rb
Created Jan 12, 2010
validates :something, validator: fallback
View validates_is.rb
# Adds a fallback <tt>:is</tt> option to +validates+.
#
# # validates :preferences, class: Hash
# class ClassValidator < ActiveModel::EachValidator
# def validate_each(record, attribute, value)
# record[attribute].is_a?(options[:is]) ||
# record.errors.add attribute, options[:message] ||
# record.errors.generate_message(attribute, :class)
# end
# end
View minidress.rb
# More "proper" than a miniskirt (http://gist.github.com/273579).
class Minidress
@@factories = {}
class << self
def define(name, &block)
@@factories[name.to_s] = block
end
def build(name, attrs = {})
new(name.to_s.classify.constantize.new, &@@factories[name.to_s]).record
View label_with_block.rb
# config/initializers/label_with_block.rb
class ActionView::Helpers::FormBuilder #:nodoc:
def label_with_block(method, *args, &block)
if block_given?
options = args.extract_options!
text = @template.capture(&block)
@template.concat label_without_block(method, text, options)
else
label_without_block(method, *args)
end