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 Integer | |
def attempts error_class = StandardError, &block | |
fail "Block is required." unless block_given? | |
1.upto self do |i| | |
begin | |
return yield i | |
rescue error_class => e | |
raise e if i == self | |
next |
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 "json" | |
require "time" | |
require "optparse" | |
# require "pry" | |
# require "awesome_print" | |
ApacheLog = Struct.new :line do | |
IP_ADDR_PATTERN = %q((\d{1,3}\.){3}\d{1,3}) | |
FIELDS = %i(xforward_for ip remotelog remoteuser _time _request status bytes _referer _ua) |
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 "logger" | |
class PLogger | |
def initialize *args | |
@stdout = Logger.new STDOUT | |
@log = Logger.new *args | |
end | |
%w(debug info warn error fatal).each do |level| | |
define_method(level) do |*args| |
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 "benchmark" | |
N = 10000000 | |
Benchmark.benchmark Benchmark::CAPTION, 20, nil, "total", "average" do |bm| | |
results = {} | |
candidates = { | |
"some_candidate" => ->(i){"do something".capitalize}, | |
"another_candidate" => ->(i){"do something".sub(/\A\w/) {|match| match.upcase}}, |
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
s3.buckets.inject(0) do |account_total, bucket| | |
account_total + bucket.objects.inject(0) do |bucket_total, object| | |
bucket_total + object.content_length | |
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
File.open "./list_of_objects_in_some_bucket.txt", "w" do |file| | |
s3.buckets["some_bucket"].objects.each do |object| | |
file.puts object.key | |
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
block_device_mappings = ("b".."n").map do |name| | |
{ | |
device_name: "/dev/sd#{name}", | |
ebs: { | |
volume_size: 10, | |
delete_on_termination: true, | |
} | |
} | |
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
# attributes/default.rb | |
default.php.version = "5.5.15" | |
default.php.directives = { | |
"date.timezone" => "Asia/Tokyo", | |
"memory_limit" => "128M", | |
"post_max_size" => "64M", | |
"upload_max_filesize" => "16M", | |
"output_handler" => "mb_output_handler", |
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
bash "build php-memcache" do | |
action :run | |
not_if "php -m | grep memcache" | |
code <<-EOS | |
cd #{Chef::Config[:file_cache_path]} | |
pecl download memcache | |
tar -zxvf `ls . | grep memcache` | |
rm -f memcache-*.tgz package.xml | |
cd `ls . | grep memcache` |
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
ruby_block "add %D to LogFormat" do | |
path = "/etc/httpd/conf/httpd.conf" | |
content = File.read path | |
notifies :restart, "service[httpd]" | |
not_if do | |
content.match /^LogFormat.*%D.*combined$/ | |
end | |
block do |
OlderNewer