Skip to content

Instantly share code, notes, and snippets.

- @users.each do |user|
= user.profile // select * from profile
@ukstudio
ukstudio / rails.fish
Created April 11, 2017 10:54
wrapper function
function rails
docker-compose config --services >/dev/null ^/dev/null
switch $status
case 0
docker-compose exec app rails $argv
case '*'
if test -d bin
bin/rails $argv
else
set -l rails_cmd (which rails)
@ukstudio
ukstudio / test.rb
Last active March 21, 2016 13:20
rspec power assert
require 'rspec'
require 'minitest'
require 'minitest-power_assert'
module Minitest
module Assertions
prepend Minitest::PowerAssert::Assertions
end
end
describe User do
describe '#nanrakano_method' do
subject { described_class.new.nanrakano_method(args) }
context 'context a'
context 'context b'
# many many context ...
context 'context z' do
namespace :db do
desc "Redo target timestamp newer migration."
task :redo_timestamp => :environment do
timestamp = ENV['TIMESTAMP']
files = Dir.glob("db/migrate/*.rb").map {|file|
md = file.split(File::SEPARATOR).last.match(/(^\d+)_\w+\.rb/)
[md[0], md[1].to_i]
}.select{|match| match[1] > timestamp.to_i }.map{|match| match[0]}
ENV['STEP'] = files.size.to_s
Rake::Task['db:migrate:redo'].invoke
@ukstudio
ukstudio / z.txt
Created May 2, 2012 14:34
ゾンビー
HP100%、銃弾70%、ミニマップ、HUD表示なし
アタッカー
突撃兵か工兵のみ
USAS-12,FAMAS,アンダーバレルのM26不可
第二、第三拠点のMCOM破壊で勝利
アタッカーは1人(人数次第で2、3人)
ディフェンス
ナイフのみ
@ukstudio
ukstudio / battle.rb
Created April 11, 2012 08:40
battle.rb
class User
has_one :character
end
class Character
belongs_to :user
has_many :battles
has_many :battle_records
end
@ukstudio
ukstudio / rspec_http_mathers.rb
Created March 5, 2012 03:51
rspec-http-matchers
Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |symbol,code|
matcher_name = symbol.to_s =~ /^not_/ ? symbol : "be_#{symbol}"
RSpec::Matchers.define matcher_name do
match do |response|
response.code.to_i == code
describe Fixnum do
subject { [1,2,3,4] }
specify { subject.all?{|v| v==1} }
it { should_not be_all{|v| v==1 }}
it { should be_any{|v| v==1 } }
it { should be_any(&lambda{|v| v==1 }) }
end
class Foo
@ukstudio
ukstudio / compose.rb
Created February 3, 2012 06:48
compose
# lambda/proc ver
class Proc
def self.compose(f, g)
lambda {|*args| f[g[*args]] }
end
def <<(g)
Proc.compose(self,g)
end