Skip to content

Instantly share code, notes, and snippets.

View stephencelis's full-sized avatar

Stephen Celis stephencelis

View GitHub Profile
@stephencelis
stephencelis / open
Created April 26, 2009 20:01
`open' with stdin
#!/bin/sh
# A better open: with stdin.
if tty -s
then
/usr/bin/open $@
else
while read input
do
/usr/bin/open $input
done
@stephencelis
stephencelis / Gemfile
Created November 15, 2009 17:39
Rails 3.0.pre Gemfile
# Bare bones Gemfile for Rails 3.0.pre.
#
# Throw in a directory for a new application, `gem bundle && bin/rails . -s`.
gem "rails", "3.0.pre", :git => "git://github.com/rails/rails.git"
gem "arel", :git => "git://github.com/rails/arel.git"
gem "rack-mount", :git => "git://github.com/rails/rack-mount.git"
#!/usr/bin/env ruby
require "optparse"
require "erb"
module Script
class Nginx
TEMP_PATH = "tmp/nginx.conf"
def initialize
@host = "0.0.0.0"
@stephencelis
stephencelis / label_with_block.rb
Created December 20, 2009 22:23
label_with_block
# 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
@stephencelis
stephencelis / minifacture.rb
Last active September 17, 2016 18:33
factory_girl for minitest
# factory_girl for minitest
#
# Factory.define :user do |f|
# f.login 'johndoe%d' # Sequence.
# f.email '%{login}@example.com' # Interpolate.
# f.password f.password_confirmation('foobar') # Chain.
# end
#
# Factory.define :post do |f|
# f.user { Factory :user } # Blocks, if you must.
@stephencelis
stephencelis / minidress.rb
Created January 10, 2010 16:18
More "proper" than a miniskirt (http://gist.github.com/273579).
# 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
@stephencelis
stephencelis / validates_is.rb
Created January 12, 2010 14:13
validates :something, validator: fallback
# 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
@stephencelis
stephencelis / asset_expansions.rb
Created January 15, 2010 03:40
CDN JavaScript assets
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 / app.rb
Created January 19, 2010 03:54
App update
# 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"
@stephencelis
stephencelis / gist:286436
Created January 26, 2010 01:06 — forked from qrush/gist:286431
_why's ~/.screenrc
# .( 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