Skip to content

Instantly share code, notes, and snippets.

@okitan
okitan / gist:971979
Created May 14, 2011 06:18
楽になったと言えるのか怪しくはあるw
request_json 'POST /users/:user_id/articles' do # request_json is nicer than describe_jsonapi?
let(:user_id) { 1 }
let(:article_id) { 'hello' }
before(:all) { User.make!(:id => :user_id) }
after(:all) { DatabaseCleaner.clean }
context 'when user posts valid article' do
request_json do
Article.make(:user_id => id, :article_id => article_id)
@okitan
okitan / $stdout
Created May 16, 2011 12:51
embedded_object_id=false bugs
FFF
Failures:
1) embedde many object making two grandsons failed childs is one
Failure/Error: Parent.where(:foo => 'foo').first.sons.should have(1).items
expected 1 items, got 2
# ./embedded_object_id_spec.rb:55:in `block (3 levels) in <top (required)>'
2) embedde many object making two grandsons failed grandsons is two
@okitan
okitan / gist:1077307
Created July 12, 2011 02:58
こういうのがいいかな
each_context {
'Aの場合' => { :key => 'a' },
'Bの場合' => { :key => 'b' },
} do
it { ... }
end
__EOF__
{
@okitan
okitan / alias.rb
Created July 20, 2011 00:18
メタプログラミングRuby勉強会
class MyClass
def old_method
"my_method"
end
alias new_method old_method
# alias_method :new_method, :old_method
end
obj = MyClass.new
@okitan
okitan / config.ru
Created October 10, 2011 06:45
api to return error status
$: << '.'
require 'test_app'
use Rack::ContentType
use Rack::ContentLength
run TestApp
@okitan
okitan / 01_policy.md
Created November 4, 2011 22:40
amqp 対策メモ

方針

ErrorHandlingによると, amqp ~> 0.8.0 ならば AMQP::Channel#auto_recovery で再接続が可能

別環境でも障碍の再現がうまくいかなかった場合は,クライアントサイドで対応するしかない

従って,アップグレードするため amqp ~> 0.8.0 にしたいが,現行の amgp = 0.7.1 からのアップグレードに何が必要か考える

@okitan
okitan / backtrace_silencers.rb
Created December 27, 2011 13:04
Rails formatted backtrace on logger (tested in Rails 3.0.10)
Rails.backtrace_cleaner.remove_silencers!
Rails.backtrace_cleaner.add_silencer { |line| line =~ /spec/ }
module ActiveSupport
class BacktraceCleaner
def clean_with_format(backtrace, kind = :silent)
filtered = clean_without_format(backtrace, kind)
splits = filtered.map do |line|
@okitan
okitan / dotfiles.sh
Last active September 29, 2015 07:48
install dotfiles
cd ~
[[ -e dotfiles ]] || git clone git@github.com:okitan/dotfiles.git
# override dotfiles
targets=".emacs.d .gemrc .gitconfig .gitignore .rspec .rvmrc .tmux.conf .vimrc"
for target in $targets; do
[[ -e $target ]] && mv $target $target.old
ln -s ~/dotfiles/$target ~
done
@okitan
okitan / STDOUT
Created May 2, 2012 06:32
caller使ってみた
./fuga.rb
6
describe "named subject" do
subject(:a) { "a" }
subject(:b) { "b" }
it { a.should == "a" }
it { b.should == "b" }
it { should == "a" }
it { subject.should == "a" }
end