This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------- getting started ---------- | |
# gem install clockwork | |
# nohup clockwork clock.rb & | |
# ---------- stop process ---------- | |
# ps -x | grep clock | |
# kill [id] | |
require 'clockwork' | |
require 'net/http' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NullObjectExample | |
require 'naught' | |
NullObject = Naught.build | |
def null_object | |
null = NullObject.new | |
null.foo # => nil | |
null.bar # => nil | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RenderObserver < Rails::Railtie | |
@rendered = Set.new([]) | |
config.after_initialize do | |
ActiveSupport::Notifications.subscribe "render_template.action_view" do |*args| | |
data = args.extract_options! | |
unless @rendered.include?(data[:identifier]) | |
puts "#{data[:identifier]}" | |
@rendered.add(data[:identifier]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def print_enable_combinarion(from, to) | |
s = ['+', '-', '*', '/', ''] | |
(from..to).each do |num| | |
a = num.to_s.split("") | |
[a[0]].product(s, [a[1]], s, [a[2]], s, [a[3]]) do |c| | |
next if abort?(str = c.join) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
ROOT_NUM = [4, 9, 16, 25, 36, 49, 64] | |
def ichigo | |
@result = [] | |
(2..(ROOT_NUM[-1] / 2)).each { |i| search_pair(1, (2..i).to_a, [1]) } | |
p @result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def pair2one(num) | |
@count = 0 | |
countup(0, num) # 男子が先頭の場合を計上. | |
countup(1, num) # 女子が先頭の場合を計上. | |
puts @count | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module M1 | |
end | |
module M2 | |
include M1 | |
end | |
module M3 | |
prepend M1 | |
include M2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def step_count(a, b, n) | |
if a + b >= n | |
@count += 1 if a + b == n | |
return | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def cut_bar(bar, m) | |
t = m | |
rt_bar = bar.dup | |
bar.each_with_index do |b, i| | |
if b > 1 | |
t -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 処理時間計測の自作ライブラリ -- | |
require './process_measure.rb' | |
# ------------------------------ | |
def reverse_card_open(card_num) | |
cards = Array.new(card_num, false) | |
1.upto(card_num) do |i| | |
i.step(card_num, i+1) do |j| | |
cards[j] = !cards[j] |
NewerOlder