Skip to content

Instantly share code, notes, and snippets.

View muraoka-edo's full-sized avatar

muraoka-edo

  • Japan
View GitHub Profile
@muraoka-edo
muraoka-edo / generate_yml_fomatter.rb
Created October 2, 2014 02:51
[Ruby] Serverspec's property genarator(YAML Format)
#!/usr/bin/env ruby
# coding: utf-8
require 'yaml'
require 'csv'
class GeneratorYmlProps
def initialize(hostlst)
@hostlst = hostlst
@property = Hash.new { |hash,key| hash[key] ={} }
@muraoka-edo
muraoka-edo / webrick_tmpl.rb
Created September 29, 2014 06:03
[Ruby] Webrick(ERB)
#!/usr/bin/env ruby
# coding: utf-8
require 'webrick'
config = {
:Port => 10080,
:DocumentRoot => '.',
}
@muraoka-edo
muraoka-edo / write-sample.rb
Created September 29, 2014 02:27
[Ruby] File-sample
# Read(line by line)
File.open 'fname' do |f|
f.each_line do |line|
puts line
end
end
# Read(Slurp)
File.open 'fname' do |f|
puts f.read
@muraoka-edo
muraoka-edo / optparse-sample.rb
Last active August 29, 2015 14:07
[Ruby] optparse template
#!/usr/bin/env ruby
# coding: utf-8
require 'optparse'
params = ARGV.getopts('f:')
prg_name = File.basename(__FILE__)
usage = <<-EOS
-------------------------
Usage: parse [options]
@muraoka-edo
muraoka-edo / __FILE__-sample .md
Last active August 29, 2015 14:07
[Ruby] if $0 == __FILE__

$0と__FILE__

  • '$0': ライブラリとして使用された場合(require)、呼び出し元を表示
  • '__FILE__': 実行中のプログラム名を表示

Example

requireされたときは"#Code"は実行されない。 短いコードなら、テストを書いておくのが良さげ。

@muraoka-edo
muraoka-edo / cap2_upload.rb
Created September 28, 2014 06:16
[Ruby] capistrano2-upload
# collect:upload_files
namespace :collect do
desc 'deploy files'
task :upload_files, roles => :local do
upload_dir= File.expand_path('~/scpfiles')
upload_files = [ "#{upload_dir}/hoge.rb",
"#{upload_dir}/foodir",
]
upload_files.each do |fp|
fname = File.basename(fp)
@muraoka-edo
muraoka-edo / logger-sample.rb
Last active August 29, 2015 14:06
[Ruby] logger
#!/usr/bin/env ruby
# coding: utf-8
require 'logger'
tmpl = 'hogehoge'
# logfile: '/tmp/test.log' logrotate: 'daily'
logger = Logger.new('/tmp/test.log', 'daily')
# logfile: '/tmp/test.log' logrotate: '10Mib/7lotate(1current+6backup)'
@muraoka-edo
muraoka-edo / ruby-growl-sample.rb
Created September 27, 2014 12:44
[Ruby] growl
#!/usr/bin/env ruby
# coding: utf-8
require 'ruby-growl/ruby_logo'
pass = 'himitsu'
title = 'From Ruby'
message = 'Hello Ruby'
g = Growl.new "localhost", "ruby-growl"