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/initializers/aws-sdk.rb | |
# configure your credential at ~/.aws/credential | |
# [kdan] | |
# aws_access_key_id=your_access_key_id | |
# aws_secret_access_key=your_secret_access_key | |
if File.exist? File.expand_path('~/.aws/credentials') | |
Aws.config.update( | |
credentials: Aws::SharedCredentials.new(profile_name: 'kdan'), | |
) | |
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
module A | |
def init_ddb_client | |
Aws::DynamoDB::Client.new | |
end | |
def query params | |
client = init_ddb_client # Exception here | |
# loop for counting | |
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
# Ruby內除了nil以及false以外皆為真值 | |
obj = 0 | |
obj = '' | |
obj = {} | |
puts obj ? true : false | |
# true |
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
videos = Hash.new do |h,k| | |
h[k] = "https://www.youtube.com/watch?v=#{k.to_s}" | |
end | |
%w(vVyf_TqWVzI cZFPVAOrdXQ 5tQ4xHMR3iU).each { |id| videos[id] } | |
puts videos | |
# { | |
# "vVyf_TqWVzI"=>"https://www.youtube.com/watch?v=vVyf_TqWVzI", | |
# "cZFPVAOrdXQ"=>"https://www.youtube.com/watch?v=cZFPVAOrdXQ", | |
# "5tQ4xHMR3iU"=>"https://www.youtube.com/watch?v=5tQ4xHMR3iU" | |
# } |
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
deep_hash = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) } | |
deep_hash[:a][:b][:c][:d] = 'Hello World' | |
puts deep_hash | |
# {:a=>{:b=>{:c=>{:d=>"Hello World"}}}} |