Ruby => 正規表現検索、置換①
# 文字列 string = 'cccbbbaaaddd' # 正規表現 pattern = 'a.*' # 検索 string.match(pattern) # => #<MatchData "aaaddd"> string.match(pattern).to_s # => "aaaddd" string.match(pattern).to_s[-1] # => "d" string.match(pattern).to_s[0] # => "a" string.match(pattern).pre_match # => "cccbbb" string.match(pattern).pre_match[0] # => "c" string.match(pattern).pre_match[-1] # => "b" string.match(pattern).post_match # => "" string.match(pattern).post_match[0] # => "nil" string.match(pattern).post_match[-1] # => "nil" "aaaarrrrssssbbbbcccc".match("[a-z && [^ab]]+").to_s # => "rrrrssss" "hello world".match(/(\w)\1/) # => #<MatchData "ll" 1:"l"> # 上と同じ ?<name> で名前つけて、k<name>で取り出す "hello world".match(/?<name>(\w)\k<name>/) # => #<MatchData "ll" 1:"l"> "pipipiworld".match(/(\w+)\1\1/) # => #<MatchData "pipipi" 1:"pi"> # 置換 string.gsub(/#{pattern}/) {"222"} # => "cccbbb222" "aaaarrrrssssbbbbcccc".gsub(/[a-z && [^ab]]+/) {"AAAA"} # => "aaaaAAAAbbbbAAAA" "hello world".gsub(/(\w)\1/) {"AAAA"} # => "heAAAAo world" "pipipiworld".gsub(/(\w+)\1\1/) {"super mario "} # => "super mario world"
Ruby => 日付時刻
require "date" # 2017/8/19 start_date = Date.new(2017,8,19) => #<Date: 2017-08-19 ((2457985j,0s,0n),+0s,2299161j)> #today end_date = Date.today => #<Date: 2017-11-03 ((2458061j,0s,0n),+0s,2299161j)> # diff (end_date - start_date).to_i => 76 # to_s end_date.to_s => "2017-11-03" start_date.to_s => "2017-08-19" # yyyy_MMdd_HHmmss end_date.strftime('%Y_%m%d_%H%M%S') => "2017_1103_000000" start_date.strftime('%Y_%m%d_%H%M%S') => "2017_0819_000000"
Windows Powershell => 引数にブロックを与える
関数定義での引数を[scriptblock]型に指定しておき、 関数内では"&"を使って呼び出します。 関数呼び出しの際には引数にブロック{} を記述し、中にコマンドを記載します。
# if-elseからメッセージ出力する共通関数 function message ([scriptblock]$condition,[string]$ok_message,[string]$ng_message) { if (& $condition) { "$ok_message" >> xxxx.log } else { "$ng_message" >> xxxx.log } } # メッセージ出力関数呼び出し $a = 4 message {$a -lt 4} "$a は4より小さい" "$a は4以上" # $a は4以上 $a = 3 message {$a -lt 4} "$a は4より小さい" "$a は4以上" # $a は4より小さい $a = "abc" message {"$a" -match "a"} "$a はaを含む" "$a はaを含まない" # abc はaを含む $a = "bcd" message {"$a" -match "a"} "$a はaを含む" "$a はaを含まない" # abc はaを含まない
Ruby => infinite enumeration
triangle = Enumerator.new do |yielder| number = 0 count = 1 loop do number += count count += 1 yielder.yield number end end triangle.next() =>1 triangle.next() =>3 triangle.next() =>6 triangle.next() =>10 triangle.next() =>15
AWS => awscli設定、動作確認
勉強メモみたいな感じになってきた。 まあコツコツやっていこうと思う。
# awscli インストール pip install awscli # バージョン確認 aws --version # 設定 aws configure # セキュリティグループ作成 aws ec2 create-security-group --group-name testgroup --description testgroup # ポート解放 aws ec2 authorize-security-group-ingress --group-id hogehoge --protocol tcp --port 22 --cidr 0.0.0.0/0 # EC2 ログイン用キーペア作成 aws ec2 create-key-pair --key-name testkey # インスタンス起動 aws ec2 run-instances --image-id hogehoge --instance-type t2.micro \ --security-group-ids hogehoge --key-name testkey --subnet-id hogehoge # EIP 取得 aws ec2 allocate-address # EIP 割り当て aws ec2 associate-address --allocation-id hogehoge --instance-id fugafuga
AWS => EC2初期設定
AWS超絶基礎復習
EC2(Elastic Compute Cloud)
ストレージ(ルートデバイスタイプ)
EBSボリュームタイプ
- General Purpose
- 用途:ルートボリューム・中小規模のDB
- SSD 1GiB〜16TiB
- 1TiB 以下: 3,000 IOPS
- 1TiB 以上: 最大 10,000 IOPS
- 3.334TiB 以上: 10,000 IOPS
- Provisioned
- 用途:高負荷のDB
- SSD 10GiB〜16TiB
- 667GiB 以上: 20,000 IOPS
- Magnetic
- 用途:読み書き速度・アクセス頻度が低い場合、コストを下げたい場合
- SSD 1GiB〜1TiB
- 平均 100 IOPS
キーペア
- マネジメントコンソールからダウンロードする
- SSH/RDPで利用
セキュリティグループ
- アウトバウンド
- デフォルトで全許可
- インバウンド
- デフォルトで全拒否
- 必要なポートを開ける
- 送信元IP指定も可能
ネットワーク
- VPCを指定
サブネット
- 選択したVPC内のサブネットを指定
自動割り当てパブリックIP
- グローバルIPの有無
- デフォルトは有効で、付与される
IAMロール
- 割り当てるIAMロールを指定可能
シャットダウン動作
- インスタンスをシャットダウンした際に、削除するか、停止するか docs.aws.amazon.com
削除保護の有効化
モニタリングの有効化
- 通常5分のところを1分間隔で監視できる(有料)
テナンシー
- HWを共有するか占有するか
ネットワークインターフェイス
- Elastic Network Interface
- 複数指定しても帯域が拡張されるわけでは無い
ストレージ
- Provisioned IOPS (IO1) / 汎用SSD(GP2) / マグネティック
タグ
yamazoonブログ開始
「イシューからはじめよ」を勧めてもらって読んだ。
- 本を読んだ結果から取り入れることを、簡単に列挙する
このブログは、学んだ技術をアウトプットするために、新しく書いていきます。
ハイライトもできるので、はてなブログ にしました。
words = [] while true word=gets.chomp break if word.empty? words<<word end puts words.sort