Linuxのコマンド入出力

Linuxのコマンド入出力

linuxのコマンドには1つの入口と2つの出口が存在する

入口

標準入力

コマンドラインに文字を入力すること

出口

コマンドラインに表示される文字

標準出力標準エラー出力の違い

ex: rmコマンドでオプションなしでaディレクトリを消そうとした時

rm: cannot remove ‘a’: Is a directory

XDG Base Directory Specification

XDG Base Directory Specificationって何

デスクトップ環境における標準的なフォルダー構造を規定した仕様

XDG Base Directory - ArchWiki

kledgeb.blogspot.com

目的

煩雑になるデータを、標準的な仕様を設けることによって一貫性のある方法を提供し、整理する。

XDG Base DIrectory Specificationが規定するフォルダー

#### $XDG_DATA_HOME アプリのデータを置くフォルダーのパス.

let, const , var

目的

宣言方法一覧

  • const
  • let
  • var

const

1度しか代入できない変数(定数)
スコープの制約がある

実行

{
  const a = 1;
  console.log(a);
}

実行結果

1

実行

{
    const a = 1;
    a = 2;
    console.log(a);
}

実行結果

再代入を実施するとエラーが発生する

VM498:3 Uncaught TypeError: Assignment to constant variable.
    at <anonymous>:3:7

実行

{
  const a = 1;
}
console.log(a);

実行結果

スコープ外では宣言していないためエラーが発生する

VM191:1 Uncaught ReferenceError: a is not defined
    at <anonymous>:1:13

let

再代入可能
スコープの制約がある

実行

{
  let b = 1;
  b = 2;
  console.log(b);
}

実行結果

再代入され1ではなく2になる

2

実行

{
  let b = 1;
}
console.log(b);

実行結果

スコープ外なのでエラーが発生する

VM346:1 Uncaught ReferenceError: b is not defined
    at <anonymous>:1:13

var

再代入可能
スコープの制約がない
(使用は非推奨)

実行

{
  let c = 1;
  c = 2;
  console.log(c);
}

実行結果

2

実行

{
  let c = 1;
}
console.log(c);

実行結果

1

変数名の命名規則

目的

変数名の命名規則

一覧

キャメルケース スネークケース ケバブケース
user infometion userInfomation user_information user-infomation
pen pineapple apple pen penPineappleApplePen pen_pineapple_apple_pen pen-pineapple-apple-pen

感想

ケバブケースは個人的にあまり見ないように感じた。 文字数が増えないのでキャメルケースが個人的に好き。

Hammerspoonによって画面分割

目的

PC上のwindowを画面上下左右に寄せたい

Hammerspoonとは

www.hammerspoon.org

macOS上でLuaというプログラミング言語を落ちいてscriptを実行することができるソフトウェアです windowの画面分割も実施できshiftitの代替案として上がっています

github.com

参考

手順

1. Hammerspoonのダウンロード

Hammerspoon

公式サイトのHow do I install it?の項目に沿って実施 githubリポジトリよりインストールしたいversionのHammerspoonのzipをダウンロード、その後アプリケーションフォルダへドラッグする。

2. Hammerspoonの設定

  1. ダウンロードしたHammerspoonを起動
  2. メニューバーアイコン > Preferences..
  3. を選択し「Launch Hammerspoon at login」をチェックする
  4. 「Enable Accesibility」を押して、Macの設定からHammerspoonにアクセス権を与える
  5. .hammerspoon/init.luaを開き下記の設定を書き込んで保存
  6. メニューバー(PC画面の一番上に表示されている領域)のHammerspoonを押しReload configを押す
hs.window.animationDuration = 0
units = {
  right50       = { x = 0.50, y = 0.00, w = 0.50, h = 1.00 },
  left50        = { x = 0.00, y = 0.00, w = 0.50, h = 1.00 },
  top50         = { x = 0.00, y = 0.00, w = 1.00, h = 0.50 },
  bot50         = { x = 0.00, y = 0.50, w = 1.00, h = 0.50 },
  maximum       = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 }
}

mash = { 'shift', 'ctrl' }
hs.hotkey.bind(mash, 'right', function() hs.window.focusedWindow():move(units.right50,    nil, true) end)
hs.hotkey.bind(mash, 'left', function() hs.window.focusedWindow():move(units.left50,     nil, true) end)
hs.hotkey.bind(mash, 'up', function() hs.window.focusedWindow():move(units.top50,      nil, true) end)
hs.hotkey.bind(mash, 'down', function() hs.window.focusedWindow():move(units.bot50,      nil, true) end)
hs.hotkey.bind(mash, 'm', function() hs.window.focusedWindow():move(units.maximum,  nil, true) end)
  • 'shift' 'control' <上下左右の何かしらのボタン> : 各矢印キー側にwindowが画面の50%で表示される
  • 'shift' 'control' 'm' : 選択しているwindowが画面全体のサイズになる

vimで検索時のハイライトの設定

目的

  • terminalで検索する時にハイライトを出したい
  • 逐次的にハイライトも出したい

設定方法

1 .vimrcを開く

# .vimrc*1を開く
$  vim .vimrc

*1 .vimrc : vimの設定ファイル

2 設定を書き込む

//snip...
"*2 hl : ハイライト(high light)
" search : 検索 
set hlsearch

" inc : インクリメント(increment)
" search : 検索
set incsearch
//snip...

*2 " (ダブルクォーテーション) : vimでのコメントアウト

SpringBoot : @RequestMappingと@GetMappingの違い

### 目的 @RequestMappingや、@GetMappingが記述されているけど違いがわからない

結論

@RequestMapping

GET, POST, PUT, DELETE をするURI全ての前段階のMappingを記述する

@GetMapping

HTTPリクエストのGETを行うURI

/**
* コントローラクラスであることの宣言
*/

@RestController

/**
* リクエストURLに対しての処理メソッド定義
*/

@RequestMapping("/messages")

public class MessageController {

/**
* 他クラス呼び出し
*/

@Autowired

private MessageService messageService;

/**
* RequestmappingのGet拡張(全件取得)
*/

@GetMapping

public Collection<Message> getMessages() {

return messageService.getMessages();

}

/**
* RequestmappingのGet拡張(idごとの取得)
*
* @throws NotFoundException
*/

@GetMapping("/{id}")

public Optional<Message> getMessageById(@PathVariable String id) throws NotFoundException {

  return messageService.getMessageById(id);

}

/**
* RequestmappingのPost拡張(登録)
*/

@PostMapping

public Message postMessage(@RequestBody @Validated Message message) {

  return messageService.createMessage(message);

}

/**
* RequestmappingのDelete拡張(idごとの削除)
*
* @throws NotFoundException
*/

@DeleteMapping("/{id}")

public Optional<Message> deleteMessageById(@PathVariable String id) throws NotFoundException {

  return messageService.deleteMessageById(id);

}

/**
* RequestmappingのPut拡張(idごとの更新)
*
* @throws NotFoundException
*/

@PutMapping("/{id}")

public Optional<Message> updateMessageById(@PathVariable String id,

@RequestBody MessageUpdatePayload messageUpdatePayload) throws NotFoundException {

  return messageService.updateMessageById(id, messageUpdatePayload);

}

}