Skip to content

Instantly share code, notes, and snippets.

@icyleaf
icyleaf / ar_migrate.rb
Last active June 6, 2024 20:06
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
@gabetax
gabetax / rspec-expect-stand-alone-matchers.md
Last active December 20, 2015 16:18
rspec expect-syntax, stand-alone operators, and you

rspec expect syntax and stand-alone operator matches

I recently started a new project using rspec's newer (and soon to be default) expect syntax, and encountered this error:

expect(5).to == 5
ArgumentError: The expect syntax does not support operator matchers, so you must pass a matcher to `#to`

"Why'd they take out operator matches? I've grown quite accustomed to them!", I thought. Digging around, the source of this change started in pull request 119 citing issue 138 as one of the root causes. Here's what's actually happening:

@wearethefoos
wearethefoos / varnish3.rb
Created February 23, 2012 10:48 — forked from hmsk/varnish3.rb
Install Varnish-3.0.2 on OSX with homebrew
require 'formula'
class Varnish3 <Formula
url 'http://repo.varnish-cache.org/source/varnish-3.0.2.tar.gz'
homepage 'http://www.varnish-cache.org/'
md5 'c8eae0aabbe66b6daabdf3a1f58cd47a'
depends_on 'pkg-config' => :build
depends_on 'pcre' => :build
@sukeerthiadiga
sukeerthiadiga / gist:1026599
Created June 15, 2011 06:39
Renames all *.rhtml views to .html.erb, .rjs to .js.rjs, .rxml to .xml.builder and .haml
namespace 'views' do
desc 'Renames all *.rhtml views to .html.erb, .rjs to .js.rjs, .rxml to .xml.builder, and .haml to .html.haml'
task 'rename' do
Dir.glob('app/views/**/*.rhtml').each do |file|
puts `git mv #{file} #{file.gsub(/\.rhtml$/, '.html.erb')}`
end
Dir.glob('app/views/**/[^_]*.rxml').each do |file|
puts `git mv #{file} #{file.gsub(/\.rxml$/, '.xml.builder')}`
end
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end