Skip to content

Instantly share code, notes, and snippets.

View JunichiIto's full-sized avatar

Junichi Ito JunichiIto

View GitHub Profile
@JunichiIto
JunichiIto / rails_helper.rb
Created June 22, 2015 09:34
Sample DatabaseCleaner setting
# gem 'database_cleaner', '~> 1.4'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
require 'spec_helper'
class Foo
def self.bar(*args)
raise 'Should be stubbed.'
end
end
describe 'Large args' do
example do
require 'spec_helper'
class Foo
def self.bar(*args)
puts "foo"
"bar"
end
end
describe Foo do
@JunichiIto
JunichiIto / gist:2233293
Created March 29, 2012 04:28
Query using EXISTS
-- The alternative query for the List 6.
-- This query can be executed against SQL Server.
-- http://gihyo.jp/dev/serial/01/sql_lifesaving/0005?page=4
SELECT s.sup,
s.city,
s.area
FROM Suppliers s
WHERE s.ship_flg = '可'
AND EXISTS
(SELECT *
require 'rspec'
class Person
def hello(name)
puts "Hello, #{name}"
end
end
describe do
example do
# 重み付け抽選クラス(Lottery)の仕様。
#
# new(size)
# インスタンスを作成する。
# [PARAM] size: 最大の当選者数
#
# add(member, weight)
# 応募者を追加する。
# [PARAM] member: 応募者
# [PARAM] weight: 1以上の整数で指定する当選確率の重み。大きいほど当選しやすい。
require 'spec_helper'
describe Spree::Product do
let(:product) {FactoryGirl.create(:product)}
let(:variant) {product.master}
describe '#no_expires' do
let(:expired_products) {Spree::Product.no_expires}
before do

Rubyもくもく会 2013/07/20

先週、僕は東灘区民センターで開催された今月の西脇.rb & 東灘.rbのもくもく会に参加しました。

もくもく会って何?

もくもく会は3月から開催されていて今回で5回目です。僕が参加するのはこれで4回目です。形式はこんな風にシンプルです。参加者がそれぞれこれからやることを発表します(プログラムの開発が多いですが、何かの調査になる場合もあります)。次に2~3時間それをやって、それが終わったらやったことを発表します。発表の際は質疑応答やコードレビューもあります。

大半のプログラミング勉強会は研究会形式であったり、プレゼンテーションを聞く形式であったりすることが多いですが、このやり方はそれらと全く異なっています。もくもく会が重視していることは実際に手を動かして学ぶことと、他の参加者からフィードバックをもらうことです。こういった技術や知識は本を読んでも手に入りません。

@JunichiIto
JunichiIto / gist:7743429
Created December 2, 2013 01:19
Another implementation of signer_keys_and_uids in http://robots.thoughtbot.com/iteration-as-an-anti-pattern/ .
def signer_keys_and_uids
Hash[singers.map{|singer| [singer.key_id, singer.uids]}]
end
@JunichiIto
JunichiIto / gist:7799880
Created December 5, 2013 03:59
An example code for not and reverse_order.
Contractor.where.not(name: nil).order(:created_at).reverse_order.to_sql
# => "SELECT \"contractors\".* FROM \"contractors\" WHERE (\"contractors\".\"name\" IS NOT NULL) ORDER BY \"contractors\".\"created_at\" DESC"