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
def int(name) | |
eval <<-EOS | |
public | |
def #{name}=(value) | |
raise '#{name} is required' if value == nil | |
raise 'Type is mismatch' unless value.is_a? Integer | |
@#{name} = value | |
end | |
EOS | |
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
config = Rails.application.config.database_configuration[Rails.env].dup | |
config['pool'] = 20 | |
ActiveRecord::Base.establish_connection(config) | |
ActiveRecord::Base.connection_pool.size |
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
# 面接官から「ここに1ページだけ破れた小説があります。破れていないページの番号を合計すると4000です。破れたページは何ページ目かを答えなさい。」と言われたら、何と答えますか? - Quora | |
# https://jp.quora.com/%E9%9D%A2%E6%8E%A5%E5%AE%98%E3%81%8B%E3%82%89-%E3%81%93%E3%81%93%E3%81%AB1%E3%83%9A%E3%83%BC%E3%82%B8%E3%81%A0%E3%81%91%E7%A0%B4%E3%82%8C%E3%81%9F%E5%B0%8F%E8%AA%AC%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99- | |
i = 1 | |
sum = 0 | |
loop do | |
sum += i | |
if sum > 4000 | |
diff = sum - 4000 | |
puts "Total: #{i} / broken: #{(diff/2).to_i},#{(diff/2).to_i + 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
(0..15).each do |i| | |
print "\e[38;5;#{i}m#{"%3d" % i}\u2588 " | |
puts "" if i % 8 == 7 | |
end | |
puts "" | |
(16..231).each do |i| | |
print "\e[38;5;#{i}m#{"%3d" % i}\u2588 " | |
puts "" if (i - 16) % 6 == 5 | |
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
#!/bin/sh | |
mkfifo .pipe | |
function res { | |
echo 'HTTP/1.1 200 OK' | |
echo "Host: `hostname`" | |
echo "Date: `date -R`" | |
echo "Content-Type: text/plain" | |
echo "Content-Length: 5" | |
echo '' | |
echo 'hello' |
OlderNewer