PostgreSQL でユーザとデータベースの作成

$ psql -U postgres -d postgres

postgres=> 

-- DATABASE一覧の表示
postgres=> \l

-- ユーザーの一覧を表示
postgres=> \dg

-- DATABASE作成
postgres=> CREATE DATABASE newdb OWNER postgres;

-- Userの作成
postgres=> CREATE USER newuser WITH PASSWORD 'password';

-- DATABASE、Userの削除
postgres=> DROP DATABASE newdb;
postgres=> DROP USER newuser;

-- psqlから出る
postgres=> \q

$

SBCL で UnitTest

なんか作るにしてもユニットテスト書けないと辛いなってことで
ユニットテストのやり方を調べてみました。

探す

CLで使えるテストフレームワークはこの辺で探してみました qiita.com

選ぶ

  • インストール簡単なやーつがいいな
  • 情報が多いほうが良いなぁ
  • みんなに使われてるのがいいなぁ

qiita.com https://lisphub.jp/common-lisp/users/index.cgi?FiveAM

わかりやすい記事がたくさんある fiveam を使ってみることに

使う

install

ros run
(ql:quickload "fiveam")

run

ros run
? (5am:test test
  (5am:is (= 1 1)))

TEST
? (5am:run! 'test)

Running test TEST .
 Did 1 check.
    Pass: 1 (100%)
    Skip: 0 ( 0%)
    Fail: 0 ( 0%)

T
NIL
NIL
?

リモートディスクトッププロトコル(RDP)のプロキシとか

RDP を直接接続するのではなく、色んな方法で間接的に繋げる方法を調べてみました

環境情報

調査した環境はこんな感じ

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"

トンネル

socat を使用した トンネル掘り

socat -d tcp4-listen:3389,reuseaddr,fork TCP:<Windowsホスト>:3389

HTTP Proxy

squid を使って HTTP Proxy 経由でRDPする方法。

squid インストール+設定

$ sudo apt install squid
$ squid -v
Squid Cache: Version 3.5.12
Service Name: squid

$ sudo vi /etc/squid/squid.conf

  acl Safe_ports port 3389
  http_access allow Safe_ports
  http_access allow localhost manager
  http_access deny manager
  http_access allow localhost
  http_access deny all
  http_port 3128


$ sudo systemctl restart squid
$ sudo tail -f /var/log/squid/access.log

middleware ってどうやって呼んでるのん?

Nuxt で Layoutに設定したミドルウェアがどのような順序で実行されているのか調べてみました。
Promise.all で呼んでたりするのかな?

該当コード

呼んでいる

https://github.com/nuxt/nuxt.js/blob/fb978b812a3790f3e0be386931a75662e6903fe5/lib/app/server.js#L131

よばれている

結果

  • Promise.all では実行されていなかった。
  • middlewareSeries というファンクションで実行されているみたい

middlewareSeries

export function middlewareSeries(promises, appContext) {
  if (!promises.length || appContext._redirected || appContext._errored) {
    return Promise.resolve()
  }
  return promisify(promises[0], appContext)
  .then(() => {
    return middlewareSeries(promises.slice(1), appContext)
  })
}

then句 内で次のPromise を再帰的に呼んでるみたい。
てことは middlewareは 指定した順番通りに実行されると思っていいのかな?

ES初心者なのでわかっていないかも・・・
間違ってたら教えてください。

roswellをインストールしてみる

あらすじ

前回、Roswellをインストールしてみようとしたらうまくいかなかったので ソースからコンパイルしてインストールしてみることにします

参考

ここを参考にインストールしていきます github.com

インストール

事前準備

$ sudo apt update
$ sudo apt install gcc automake libcurl4-openssl-dev zlib1g-dev

インストール

$ git clone -b release https://github.com/roswell/roswell.git
$ cd roswell
$ sh bootstrap
$ ./configure
$ make
$ sudo make install

setup

この辺を参考にセットアップ github.com

$ ros
$ ros -- --version
roswell 18.4.10.91(0bd00aa)

$ ros install sbcl
$ ros install sbcl-bin
$ ros install ccl-bin
$ ros use sbcl/1.4.8

備考

hello world

REPL でハローワールド

~$ ros run
* (print "hello world!")

"hello world!" 
"hello world!"
* (exit)

~$

文字列を突っ込んでハローワールド

~$ ros run -e "(princ \"hello world\!\")" -q

ファイルを作る

~$ ros init hello-world

hello-worls.ros ができるのでエディタで開いて編集します

#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 "$@"
|#
(progn ;;init forms
  (ros:ensure-asdf)
  ;;#+quicklisp (ql:quickload '() :silent t)
  )

(defpackage :ros.script.hello-world.3738098721
  (:use :cl))
(in-package :ros.script.hello-world.3738098721)

(defun main (&rest argv)
  (declare (ignorable argv))
  
  ;; ここに処理を追加
  (print (format t "~A" "Hello world!"))
  
  )
;;; vim: set ft=lisp lisp:

実行

$ ./hello-world.ros
Hello world!
NIL

バイナリにもできるよ! (ちょっと早くなる)

~$ ros build hello-world.ros

$ ./hello-world
Hello world!
NIL

roswell をインストールしてみる(失敗)

パッケージマネージャってどれがいいんだろうか。。 diary.wshito.com

Roswell がよさそうだな インストール方法はこんな感じだな。よしよし github.com

debをDLしてインストールするんだな。 deb のインストールはここを参考にしてみました mickey-happygolucky.hatenablog.com

環境

Ubuntu 18.01LTS Desktop

必要なコマンドを最初にインストール

~$ sudo apt install curl jq gdebi make
~$ curl -sOL `curl -s https://api.github.com/repos/roswell/roswell/releases/latest | jq -r '.assets | .[] | select(.name|test("deb$")) | .browser_download_url'`
~$ sudo gdebi roswell_18.3.10.89-1_amb64.deb
~$ ros list versions
candidates for ros list versions [impl] are:

abcl-bin
allegro
asdf
ccl-bin
clasp
clisp
cmu-bin
ecl
quicklisp
sbcl-bin
sbcl
slime
sly


~ $ ros install sbcl

<なんかエラー>

ん!? なんか最新版じゃないと動かないかも・・・ https://github.com/roswell/roswell/issues/320

おかたずけ

あとでやりなおすため、失敗したものを取り除いておきます。

~ $ sudo apt remove roswell