Skip to content

Instantly share code, notes, and snippets.

@arukoh
arukoh / dump_step_definitions.rb
Created May 26, 2013 06:44
Cucumber Tips。 ステップ定義をJSONファイルにダンプ。
# encoding: utf-8
#!/usr/bin/env ruby
require "./runtime"
unless ARGV.include?("--dotcucumber")
STDERR.puts "Must be specified option --dotcucumber OUTPUT_DIR"
exit 1
end
runtime = Runtime.new(ARGV.dup)
runtime.write_stepdefs_json
@arukoh
arukoh / find_step_definition.rb
Created May 26, 2013 06:50
Cucumber Tips。 フィーチャのシナリオステップ名にマッピングされている「ステップ定義」を検索する。
# encoding: utf-8
#!/usr/bin/env ruby
require "./runtime"
if ARGV.empty?
STDERR.puts "Must be specified STEP_NAME"
exit 1
end
step_name = ARGV.shift
runtime = Runtime.new(ARGV.dup)
@arukoh
arukoh / route53_change_record.sh
Created June 2, 2013 05:37
Route 53の指定レコードを変更するシェルスクリプト。
#!/bin/sh
if [ $# -lt 3 ]; then
CMDNAME=`basename $0`
cat <<__EOT__
Delete and then add a record to a zone.
New record value is set current public-ipv4 or public-hostname to get from ec2 meta-data.
Usage: $CMDNAME [hosted_zone_id] [name] [type] [ttl] [comment]
type is supported A and CNAME.
ttl and comment are optional.
@arukoh
arukoh / route53_add_record.sh
Created June 2, 2013 08:53
Route 53へレコードを追加するシェルスクリプト。
#!/bin/sh
if [ $# -lt 3 ]; then
CMDNAME=`basename $0`
cat <<__EOT__
Add a record to a zone.
New record value is set current public-ipv4 or public-hostname to get from ec2 meta-data.
Usage: $CMDNAME [hosted_zone_id] [name] [type] [ttl] [comment]
type is supported A and CNAME.
ttl and comment are optional.
@arukoh
arukoh / migrate.rb
Created March 31, 2014 02:53
MongoDBからAmazon SimpleDBへデータのお引越し
require "resolv"
require "./mongodb"
require "./simpledb"
RECORD_LIMIT = 2000
unless ARGV.size >= 3
puts <<USAGE
Usage: #{File.basename(__FILE__)} [FROM] [TO]
FROM : start date
@arukoh
arukoh / omniauth.rb
Created March 31, 2014 02:58
Omniauth Mockサンプル
# see also: https://github.com/intridea/omniauth/wiki/Integration-Testing
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
provider: "facebook",
uid: "12345",
info: { name: "Mock User" },
credentials: { token: "1234567890", expires_at: Time.now + 60.days },
extra: { raw_info: { id: "12345", name: "Mock User", } }
})
@arukoh
arukoh / base.rb
Created March 31, 2014 03:09
Thorでコマンドラインツール
# lib/sample/command/base.rb
module Sample
module Command
class Base < Thor
def self.banner(task, namespace = false, subcommand = true)
super
end
@arukoh
arukoh / create_snaphost_own_instance.sh
Created March 31, 2014 04:39
EC2インスタンスのスナップショット作成スクリプト。
#!/bin/sh
[ -z "$JAVA_HOME" ] && export JAVA_HOME=/usr/lib/jvm/jre
[ -z "$EC2_HOME" ] && export EC2_HOME=/opt/aws/apitools/ec2
[ -z "$AWS_PATH" ] && export AWS_PATH=/opt/aws && export PATH="${PATH}:${AWS_PATH}/bin"
AWS_REGION=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's/[a-z]$//'`
INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
KERNEL_ID=`curl -s http://169.254.169.254/latest/meta-data/kernel-id`
OPTS="--aws-access-key ${AWS_ACCESS_KEY_ID} --aws-secret-key ${AWS_SECRET_ACCESS_KEY} --region ${AWS_REGION}"
@arukoh
arukoh / elb_instannces_status.rb
Created March 31, 2014 04:54
ELBに紐付くインスタンスの状態一覧を表示するスクリプト。
require "aws-sdk"
['us-east-1', 'ap-northeast-1'].each do |region|
AWS::ELB.new(region: region).load_balancers.each do |elb|
elb.client.describe_instance_health(load_balancer_name: elb.name)[:instance_states].each do |h|
puts "#{region}\t#{elb.name}\t#{h[:instance_id]}\t#{h[:state]}\t#{h[:description]}\t#{h[:reason_code]}"
end
end
end
@arukoh
arukoh / ami_list.rb
Created March 31, 2014 04:58
自分のAMI一覧を表示するスクリプト。
require "aws-sdk"
ACCOUNT_NUMBER = ENV['ACCOUNT_NUMBER'}
REGION_NAME = ENV['REGION_NAME']
AMI_DESCRIPTION = ENV['AMI_DESCRIPTION_FILTER']
ec2 = AWS::EC2.new(region: REGION_NAME)
images = ec2.images.filter('owner-id', ACCOUNT_NUMBER).filter('description', AMI_DESCRIPTION)
sorted = images.to_a.sort{|a, b| b.description <=> a.description }
sorted.each do |image|