【AWS】EC2インスタンス内で自身が所属するAvailability Zoneをcurlで取得するAvailability Zoneをcurlで取得 EC2のインスタンスにSSHなどでログインし、OS上で以下を実行。 $ curl -s 169.254.169.254/latest/meta-data/placement/availability-zone ap-northeast-1aAWS 2022-10-10 2022-10-10
【AWS】AWS CLIでParameter Storeから値を取得するParameter Storeから値を取得するコマンド $ aws ssm get-parameter --name キー 以下のようなJSONが返ってくる。 { "Parameter": { "Name": "キー", "Type": "String", "Value": "値", "Version": 1, "LastModifiedDate": "...", "ARN": "...", "DataType": "text" } } 値はParameter.Valueに格納されているので値だけ取り出したければ--queryオプションと--outputオプションを指定して以下のように取得できる。AWS 2022-10-10 2023-04-15
【AWS】AWS CLIでアカウントIDを取得するアカウントID AWSのアカウントIDは右上のメニューから確認できる12桁の数字。 AWS CLIでアカウントIDを取得する aws sts get-caller-identityコマンドで取得できる。AWS 2022-10-10 2022-10-10
lsコマンドで更新日時を秒まで表示するls -lコマンドは標準では秒までの表示 lsコマンドの-lオプションで更新日時が表示される。 $ ls -l total 0 -rw-r--r-- 1 root root 0 Oct 8 12:38 foo.txt 以下の部分。 Linuxの場合 –time-styleオプションで秒まで指定して表示する --time-styleオプションで更新日時のフォーマットを指定できる。 このフォーマットに秒も指定できるので以下の様に指定すれば秒まで表示できる。LINUX 2022-10-08 2023-09-17
IntelliJ IDEA で複数の Maven プロジェクトを1つのウインドウで開く手順IntelliJ IDEAで複数プロジェクトを一度に開きたい モジュール化してMavenプロジェクトを複数作っているときに、それぞれのプロジェクトごとにIntelliJ IDEAのウインドウを開くのは面倒となる。 1つのウインドウで開かないと別モジュールのコードにジャンプできない。JAVA 2022-10-04 2022-10-04
【Android,Kotlin】enable/disableの状態やpressした状態のときにUIの色を変える状態で色を変える AndroidのViewはenable/disableの状態や、pressした状態で色や形などを変更できる。 例としてテキストに対して以下のように作成できる。ANDROID 2022-08-31 2023-03-31
複数回のコマンドの標準出力をまとめて一度にリダイレクトする複数回のコマンドを同じファイルにリダイレクト 以下のようなシェルスクリプトを書いた場合、同じファイルをコマンドの回数だけオープンすることになり 無駄が生じる。 #!/bin/sh echo foo >> a.txt echo bar >> a.txt echo baz >> a.txt shellcheckにかけると以下の違反が検出される。LINUX 2022-08-28 2022-08-28
【Android,Kotlin】端末に保存されたファイルかカメラ撮影から画像選択できるようにするファイル選択orカメラ撮影で画像を選択できるようにしたい こういうやつ。 カメラで撮った写真を使う場合と端末のファイルを利用する場合でそれぞれ単体の実装は以下の記事を参照。 カメラ: 端末で写真を撮って表示する ファイル選択: GetContentで端末に保存された画像ファイルを選択して表示する OpenDocumentで端末内の画像ファイルを選択して表示する 実装 自作ActivityResultContract ボトムシートとしてファイル選択、カメラ撮影から選択できるようにするためのActivityResultContractを作成する。ANDROID 2022-08-27 2023-03-31
【Android,Kotlin】OpenDocumentで端末内の画像ファイルを選択して表示するアプリのイメージ 端末に保存されている画像を選択したい。 関連: 【Android,Kotlin】GetContentで端末に保存された画像ファイルを選択して表示する 実装 レイアウト ImageViewとボタンを設置しておく。 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="300dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/next" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/imageView" /> </androidx.constraintlayout.widget.ConstraintLayout> Fragment/ViewModel フィールドにregisterForActivityResultでActivityResultContracts.OpenDocument()のlauncherを作る。ANDROID 2022-08-23 2023-03-31
【Android,Kotlin】端末で写真を撮って表示するアプリのイメージ カメラアプリで写真を撮って表示したい。 実装 レイアウト ImageViewとボタンを設置しておく。 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="300dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/next" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/imageView" /> </androidx.constraintlayout.widget.ConstraintLayout> cacheフォルダへの書き込みを許可する 外部のカメラアプリがアプリのcacheフォルダへ書き込み、アプリはそれを画面に表示する。ANDROID 2022-08-23 2023-03-31