Skip to content

Instantly share code, notes, and snippets.

View amatsuda's full-sized avatar

Akira Matsuda amatsuda

View GitHub Profile
namespace :rails do
namespace :freeze do
desc 'Lock to the current Rails 2-3-stable'
task :rails23 do
rm_rf 'vendor/rails'
`git clone -b 2-3-stable --depth=1 git://github.com/rails/rails.git vendor/rails`
chdir 'vendor/rails' do
latest_revision = `git log -1 --pretty=format:%H`
%w(.git Rakefile cleanlogs.sh pushgems.rb release.rb activemodel).each do |goner|
/opt/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:180:in `fetch_path': SocketError: getaddrinfo:
nodename nor servname provided, or not known (http://rubygems.org/gems/hoptoad_notifier-2.2.6.gem) (Gem::RemoteFetcher::FetchError)
`touch some_file`
f = File.open("some_file",'w')
f.write "Stuff"
`rm some_file`
# Why is there no errors ?
puts f.flush.inspect
puts f.close.inspect
# via: @kirillrdy
#!/usr/bin/env ruby
# taken from tolk
PLURALIZATION_KEYS = ['zero', 'one', 'two', 'few', 'many', 'other']
def pluralization_data?(data)
keys = data.keys.map(&:to_s)
keys.all? {|k| PLURALIZATION_KEYS.include?(k) }
end
def flat_hash(data, prefix = '', result = {})
Error
Permission denied
/home/wiki/hiki/hiki/command.rb:93:in `dispatch'
/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/home/wiki/hiki/hiki/command.rb:89:in `dispatch'
/home/wiki/hiki/hiki.cgi:38
/home/wiki/hiki/hiki/storage.rb:14:in `open_db'
/home/wiki/hiki/hiki.cgi:36
/home/wiki/html/rails/index.rb:5:in `load'
/home/wiki/html/rails/index.rb:5
% cat false.rb
if false
a = 1
end
puts a
puts b
% ruby -v false.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
nil
@amatsuda
amatsuda / gist:942211
Last active September 25, 2015 15:18
KeyRemap4MacBookで右Shiftとか右Cmdを単発で叩いたらアンスコにするやつ
<?xml version="1.0"?>
<root>
<list>
<item>
<name>Handy Underscore</name>
<list>
<item>
<name>Command_R to Command_R</name>
<appendix>(+ When you type Command_R only, send Underscore)</appendix>
<identifier>remap.commandR2commandR_underscore</identifier>
@amatsuda
amatsuda / gist:960252
Created May 7, 2011 06:11
rails g scaffold + --skip on Rails 3.1
% rails -v
Rails 3.1.0.beta1
% ls app/models
user.rb
% rails g scaffold user name:string -s
invoke active_record
create db/migrate/20110507060923_create_users.rb
skip app/models/user.rb
require 'tempfile'
t1 = Tempfile.new 'foo.txt'
t2 = t1.dup
t1 = nil
GC.start
p File.exists?(t2.path)
p t2.read
@amatsuda
amatsuda / Xresult
Created August 17, 2011 09:59
An RSpec matcher for asserting AR query
% rspec spec/models/user_spec.rb
.F.F.
Failures:
1) User
Failure/Error: it { should query :where => {:name => 'bar'} }
expected [:where] to query {:where=>{:name=>"bar"}}
# ./spec/models/user_spec.rb:6