Nodeインストール手順

概要

Linux環境にNodeをインストールするための手順

手順

  • nvmインストール
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  • コマンドパスを通す
source $HOME/.bashrc
  • Node.jsのバージョン一覧表示
nvm list-remote | grep -E "Latest LTS"
  • Node.jsの最新LTSのインストール
nvm install v16.15.0
  • Nodeのバージョン確認
node -v
#-> v16.15.0
  • Nodeのインストールパスを確認
nvm which 16.15.0
#-> /home/user1/.nvm/versions/node/v16.15.0/bin/node

参考サイト

https://github.com/nvm-sh/nvm

GASでWEBアプリ作成

概要

GASで作成したWEBアプリのサンプル(作成中)

サンプル

HTML

<!DOCTYPE html>
<html lang="ja">
<head>
    <base target="_top">
    <meta charset="utf-8">
    <title>HM File Creator</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
        integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</head>

<body>
    <div class="container-fluid">
        <!-- Content here -->
        <h1>Create function folder</h1>
        <div id="app">
            <div v-if="messages.length">
                <ul class="text-info">
                    <li v-for="message in messages">{{ message }}</li>
                </ul>
            </div>

            <div v-if="errors.length">
                <ul class="text-danger">
                    <li v-for="error in errors">{{ error }}</li>
                </ul>
            </div>

            <select v-model="selectVersionFolder">
                <option v-for="folder in versionFolders" v-bind:value="folder.value">
                    {{ folder.text }}
                </option>
            </select>
            <input v-model="taskName" placeholder="Input task name (e.g. あああああああ)">
            <button @click="createFolder" class="btn btn-primary">Create</button>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                messages: [],
                errors: [],
                taskName: '',
                selectVersionFolder: '',
                versionFolders: [
                    { text: '----', value: '' },
                    { text: 'v6.6', value: 'aaaaa' },
                    { text: 'v6.7', value: 'bbbbb' },
                    { text: 'v6.8', value: 'ccccc' }
                ],
            },
            methods: {
                createFolder: function () {
                    this.messages = []
                    this.errors = []

                    if (!this.selectVersionFolder) {
                        this.errors.push('Version required')
                    }
                    if (!this.taskName) {
                        this.errors.push('Task name required.')
                    }
                    if (this.errors.length > 0) {
                        return false
                    }

                    google.script.run.withSuccessHandler(function (e) {
                        const result = JSON.parse(e)
                        if (result.status == "success") {
                          app.messages.push(result.message)
                        } else {
                          app.errors.push(result.message)
                        }

                    }).withFailureHandler(function () {
                        app.errors.push("Unexpected errors")
                    }).createFolder(this.selectVersionFolder, this.taskName)
                },
            },
        });
    </script>
</body>

</html>

GAS(サーバサイド)

function doGet(e){
  const temp = HtmlService.createTemplateFromFile("index")
  const out = temp.evaluate()
  return out
}

function createFolder(aVersionFolderID, aFunctionName){
  const results = {"status" : "success", "message" : `VersionFolderID is ${aVersionFolderID}. Function name is ${aFunctionName}.`}
  return JSON.stringify(results)

}

Macショートカット

目次

Finder

コマンド・手順 解説
Command + スペース → フォルダ名 Finderを開く
Command + ↓ Finderを開File|Folder を開く
スペース プレビュー (Quick Look)
Command + [ 移動履歴を戻す
Command + ] 移動履歴を進める
Command + {1|2|3|4} 表示切り替え
Command + Option + V 切り貼り
Command + N Finderを追加する
Command + T Finderタブを追加
Control + Tab で移動 Finderタブを移動
Command + W Window|タブを閉じる
Command + Shift + H ホームフォルダを開く
Command + Shift + N 新しいフォルダを作成
  • ターミナルからはopen .でFinderを開くことができる

テキスト編集

コマンド・手順 解説
Control + {A|E} カーソルの前頭・末尾移動
Control + {F|B} カーソルの前後移動
Control + {P|N} カーソルの上下移動
Command + Control + N ファイル移動

スクリーンショット&画像収録

コマンド・手順 解説
Command + Shift + 4 画面のスニペット
Command + Shift + 4 → スペース ウィンドウのスクショ
Command + Shift + 3 画面全体のスクショ
Command + Control + 5 画面録画モード
## `~/Pictures/ScreenShot`に変更する場合
defaults write com.apple.screencapture location ~/Pictures/ScreenShot/;killall SystemUIServer

ターミナル

コマンド・手順 解説
Command+D ウインドウを2つに分割する

アプリケーションの切り替え

コマンド・手順 解説
Control + ↑ ミッションコントロール
Control +↓ アプリケーションコントロール
Control + Command + F フルスクリーンモード

キーボード > Windows風のキー操作

コマンド・手順 解説
Control + U 全角かな
Control + I 全角カナ
Control + O 半角英数字
Control + P 全角英数字

ブラウザ

コマンド・手順 解説
Command+Shift +T ブラウザの閉じたタブを復活
Control + I 全角カナ
Control + O 半角英数字
Control + P 全角英数字

その他

コマンド・手順 解説
Control + Command + Space 絵文字を出す
Control + Command + Q 画面ロック

参考資料

ファイアウォールの設定/CentOS8編

目次

ファイアウォールの設定を確認する

firewall-cmd --list-all

任意のポートを解放する

# 任意のポートを解放
# firewall-cmd --add-port={port番号}/tcp --zone=public --permanent
firewall-cmd --add-port=9999/tcp --zone=public --permanent

# ルールの反映
firewall-cmd --reload

# 疎通確認のためPHPビルドインサーバ起動
# php -S {hostname}:{port番号}
php -S example.com:9999

# ブラウザから`http://example.com:9999にアクセスしてみる

CentOS8+Apache2.4(SSL)+PHP7.4 環境構築手順

目次

事前準備

  • CentOS8.1環境構築

  • SSH+rootへ昇格

sudo -i
  • wget python38 インストール (Let's encrypt用のツールcerbotを利用するために必要)
dnf -y install wget python38
  • 好みに合わせてインストール
dnf -y install mlocate vim

構築手順

dnf -y install httpd mod_ssl
systemctl start httpd
  • PHP7.4(現時点の最新版)
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

dnf -y module install php:remi-7.4

php -v
# --> PHP 7.4.9 が出力
  • Apache用のPHPモジュールインストール
dnf -y module install php74-php
  • Let's Encrypt用ツールcerbotをインストール
cd /tmp
wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto
/usr/local/bin/certbot-auto certonly --webroot -w /var/www/html -d kzyosimo.example.com --email info@example.com

...

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

...

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for kzyosimo.example.com
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges
Subscribe to the EFF mailing list (email: kzyosimo@example.com).

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/kzyosimo.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/kzyosimo.example.com/privkey.pem
   Your cert will expire on 2020-11-13. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
ls -1d /etc/letsencrypt/live/kzyosimo.example.com/*
#--> /etc/letsencrypt/live/kzyosimo.example.com/README
#--> /etc/letsencrypt/live/kzyosimo.example.com/cert.pem
#--> /etc/letsencrypt/live/kzyosimo.example.com/chain.pem
#--> /etc/letsencrypt/live/kzyosimo.example.com/fullchain.pem
#--> /etc/letsencrypt/live/kzyosimo.example.com/privkey.pem
vim /etc/httpd/conf.d/ssl.conf
--
SSLCertificateFile /etc/letsencrypt/live/kzyosimo.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/kzyosimo.example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/kzyosimo.example.com/chain.pem
---
# Let’s Encrypt で発行した証明書は、有効期限が3ヶ月です。
00 3 1 * * /usr/local/bin/certbot-auto renew -q --deploy-hook "systemctl restart httpd"
  • preforkを有効化
vim /etc/httpd/conf.modules.d/00-mpm.conf
---
# 以下をコメントイン
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
# 以下をコメントアウト
#LoadModule mpm_event_module modules/mod_mpm_event.so
---
systemctl restart httpd

Go言語の覚書き(基本編1)

目次

インストール手順

  • GitHubよりチェックアウト
cd `
git clone https://github.com/syndbg/goenv.git `/.goenv
echo 'export GOENV_ROOT="$HOME/.goenv"' >> `/.bash_profile
echo 'export PATH="$GOENV_ROOT/bin:$PATH"' >> `/.bash_profile 
  • 「goenv init」を呼び出してShimsとオートコンプリートを有効にする。
echo 'eval "$(goenv init -)"' >> `/.bash_profile 
  • ログインシェルを再読み込みする。
source `/.bash_profile
  • 任意のバージョンをインストール
goenv install 1.11.0
go version
# Output : go version go1.11 linux/amd64
  • 下記追加
`/.bash_profileに
export GOENV_VERSION=1.11.0

アンインストール

  • ログインシェルより下記行を削除
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
rm -rf `goenv root` 

実行方法

  • サンプルプログラム
package main
import "fmt"

function main() {
  fmt.Printf("hello, world¥n")
}
  • 実行方法
# ビルドして実行する
go build hello.go 
./hello 

# または、ビルド実行を同時に行う
go run hello.go 

データ型

  • データ型宣言
var ival int     // 0
var fval float64 // 0
var bval bool    // false
var sval string  // ''
  • データ型宣言(初期値指定)
ival := 10
fval := 12.3
bval := true
sval := "hoge"
  • データ型宣言(まとめて定義)
var (
  ival int
  fval float64
  bval bool
  sval string
)
  • データ型宣言(まとめて定義)
ival, fval, bval, sval := 10, 10.1, true, "hoge"

文字列処理

  • 文字列
var sval string
sval = "good " + "moring"
fmt.Println(sval)
// output: good moring

配列

  • 配列1
var iVals [5]int
iVals[0] = 10
iVals[1] = 20
iVals[2] = 30
fmt.Println(iVals)
// output: [10 20 30 0 0]
  • 配列2
iVals := [...]int{10, 20, 30, 0, 0}
fmt.Println(iVals)
// output: [10 20 30 0 0]

ポインタ型

  • ポインタ
sVal := "hoge"
var psVal *string
psVal = &sVal
fmt.Println(psVal)
// Output : 0xc00000e1e0 (address of sVal)
fmt.Println(*psVal)
// Output : hoge

関数

  • 関数
package main
import "fmt"

func hello(aVal string) string {
  return "hello " + aVal
}

func main() {
  fmt.Println(hello("taro"))
  // Output : hello taro
}
  • 関数(返り値複数)
package main
import "fmt"

func hello(aVal string) (string, string) {
  return "hello ", aVal
}

func main() {
  var sVal1, sVal2 string
  sVal1, sVal2 = hello("taro")
  fmt.Println(sVal1 + " " + sVal2)
  // Output : hello taro
}
  • 関数(即時関数)
package main
import "fmt"


func main() {
  var sVal1, sVal2 string
  sVal1, sVal2 = func (aVal string) (string, string) {
    return "hello ", aVal
  } ("taro")

  fmt.Println(sVal1 + " " + sVal2)
  // Output : hello taro
}

参考サイト

GitHub - syndbg/goenv: Like pyenv and rbenv, but for Go.