Skip to content

Instantly share code, notes, and snippets.

View shakemurasan's full-sized avatar
🤔
I wish a splatoon3....

Yasuhiro Matsumura shakemurasan

🤔
I wish a splatoon3....
View GitHub Profile
@shakemurasan
shakemurasan / puzzle2.rb
Created September 17, 2016 08:51
プログラマ脳を鍛える数学パズル:Q2 (別解)
# -- 処理時間計測の自作ライブラリ --
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)
@shakemurasan
shakemurasan / render_observer.rb
Last active February 6, 2017 12:07
Railsでviewがレンダリングされた際、標準出力にそのファイル名を出力するコード
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
class NullObjectExample
require 'naught'
NullObject = Naught.build
def null_object
null = NullObject.new
null.foo # => nil
null.bar # => nil
end
@shakemurasan
shakemurasan / clock.rb
Created August 22, 2017 13:43
clockworkで毎分、指定のURLにアクセスするスクリプト
# ---------- getting started ----------
# gem install clockwork
# nohup clockwork clock.rb &
# ---------- stop process ----------
# ps -x | grep clock
# kill [id]
require 'clockwork'
require 'net/http'