2020/08,江端さんの技術メモ

// mail.go

package main
 
import (
    "net/http"
 
    "github.com/labstack/echo"
)
 
func main() {
    e := echo.New()
	e.POST("/save", save)
	e.Logger.Fatal(e.Start(":1323"))
}


func save(c echo.Context) error {
	 name := c.FormValue("name")
	 email := c.FormValue("email")
	 return c.String(http.StatusOK, "name:"+name+", email:"+email)
}

でもって、curlで送ってみた。

ebata@DESKTOP-P6KREM0 MINGW64 ~
$ curl -F "name=ebata" -F "email=mailmail" http://localhost:1323/save

で、出力が、以下のようになった。
name:ebata, email:mailmail

2020/08,江端さんの忘備録

コロナ感染症対策として、マスクが有効か否かついては、こちらで記載しております。

Whether or not masks are effective in fighting corona infection is described here.

また、こちらで記載しているように、感染しているか否かを、"0"と"1"のように考えることができないことも明らかです。

It's also clear that you can't think of being infected or not as a "0" and a "1", as described here.

しかし、その効果がどうであれ、「マスク」が一種のマナーとなっているのは事実です。

But whatever the effect, it is true that "masks" have become a kind of etiquette.

そして、「マスク」は、いわゆる「コロナリテラシー」の初歩の初歩と言えます。

And the "mask" is the first step of steps in so-called "corona literacy".

私としては、このマスクに加えて「COCOA(新型コロナ接触確認アプリ)」を、このマナーに入れることを提言したいと思います。

For me, I would like to suggest that in addition to this mask, the COCOA (new corona contact verification app) be included in this etiquette.

COCOAについては、すでに私、色々書いていますので、参考にして下さい。

I've already written a lot about COCOA, so please refer to it.

■COCOAのインストールは個人の自由ですが、私はインストールをお勧めしたいと思います。

Installing COCOA is a personal choice, but I would recommend that you install it.

■「セキュリティが万全」というよりは、「ハックするコストが全然見合わない」という感じです。

It's not so much "full security" as it is "not at all worth the cost to hack.

私は、「COCOAのインストール」を実施したか/していないかで、その人の「コロナリテラシー」を判断できると思っています。

I believe you can determine a person's "corona literacy" by whether or not they have/don't have implement a "COCOA installation".

-----

やり方は色々あると思いますが、もっとも簡単な方法は、

There are many ways to do this, but the easiest way is to ask a question,

『COCOAインストールしました?』

"Have you installed COCOA?

という質問をすることです。

■「もちろんです」という人は、リテラシー"1"で良いと思います。

If the person says "of course", I think his/her literacy level is "1".

■「ああ、COCOAですね。でも個人情報について不安が・・・」という人は、「リテラシー"0.9"」くらいと判断して良いかと思います。

"Oh, COCOA. But I'm worried about personal information...", I think it's safe to say that he/she have a literacy level of "0.9".

比して、

In comparison to,

■「COCOA? 何ですか、それ?」という人は、「リテラシー"0"」と断定して良いでしょう。

If the person says "COCOA? What's that?", I think his/her literacy level is "0".

いわゆる「自粛警察」をやっている人で、COCOAを知らない人がいたら、あなたは、その「自称警察官」、殴っていいです。

If you're a so-called "self-restraint police" and you don't know COCOA, I will hit you absolutely.

(私は、これに加えて、大声で、"ふざけるな!"と罵ります)。

In addition, I will shout "Do not be silly!" loudly,

(続く)

(To be continued)

2020/08,江端さんの技術メモ

golang ではファイル名が _test.go で終わるファイルを run すると
上記のエラーが表示されて実行できません。

ちなみに、buildだと

$ go build echo_test.go
no packages to build

と表示されて、なんのことやらさっぱり分かりませんでした。

2020/08,江端さんの技術メモ

$ go build echo.go
echo.go:4:5: cannot find package "github.com/trevex/golem" in any of:
        c:\go\src\github.com\trevex\golem (from $GOROOT)
        C:\Users\ebata\go\src\github.com\trevex\golem (from $GOPATH)

ebata@DESKTOP-P6KREM0 MINGW64 ~/go_websocket_test
$ go get -u github.com/trevex/golem

ebata@DESKTOP-P6KREM0 MINGW64 ~/go_websocket_test
$ go build echo.go

2020/08,江端さんの忘備録

(昨日の続きです)

(Continuation from yesterday)

私は、コラムを書くのが好きで、イラストを描くのが好きで、コーディングをするのが好きで、そして ――

I like to write columns, I like to illustrate, I like to code, and

その全てが「下手くそ」です。

I am not good at all of them.

だから、これらを他人に任せるのが、もっとも効率的であり、いわゆる『生産性が上がる』のは間違いないでしょう。

So, I think it's most efficient to leave these things to others, and there is no doubt that it will increase so-called "productivity".

だが、それは「楽しいのか?」

But is it "fun"?

自分の作り出したモノ、自分でやった仕事は、他人のモノや仕事より「愛おしくはないか?」

Do you love what you created and worked, more than other people's creations and works ?

と考えると、私には分からなくなるのです。

I don't know that.

それ故に、私は「私を幸せにするアプローチ」として、

Therefore my "approach to making me happy

(1)ひとりでやる

(1) Do it alone.

(2)ずっとやる

(2) Do it for a long time.

(3)会議に出ない(ここはGoogleと同じで、これまでも、これからも)

(3) Don't attend meetings.(It's the same as Google here, from now and to now)

を続けていくことになると思います。

I think I'll continue to do them.

-----

つまるところ、これは人間のスケール感の問題かもしれないなぁ、とも思います。

As a result, I think that this is about a matter of human scale.

私は「技術」が好きで、特に「小技」が好きですが、その技の集大成である「サービス」や「ビジネス」が好きな人にとっては、「Google式仕事術」は正しいアプローチだと思います。

While I like "technology" and especially the "little tricks, for people who like "service" and "business", the "Google Method of Working" is the right approach.

私は、「他の人」を喜ばせることに幸せを感じられます。

I feel happy to please other people.

しかし、私は、「"多く"の他の人」を喜ばせることが、"多くの幸せ"になるとは、感じることはありません。

However I can't feel many happiness to please many other people.

つまるところ、

In conclusion,

『私は、人間としての器が小さい』

"I don't have what it takes"

この結論で、私は異義ありません。

I have no objection to this conclusion.

2020/08,江端さんの忘備録

「Google式仕事術」では、生産性を上げる為に、以下を提唱しているそうです(読んでいません)。

The "Google Method of Working" advocates the following to increase productivity (I haven't read it)

(1)ひとりでやらない

(1) Don't do it alone.

(2)ずっとやらない

(2) Don't do it for a long time.

(3)会議に出ない

(3) Don't attend meetings.

なるほど「生産性を上げる為」には、これが正解かもしれません。

Okay, maybe this is the right thing to do "to increase productivity".

しかし、「生産性なんぞ知ったことか」と置き換えるだけで、このメソッドはボロボロと崩れていきます。

But simply replacing it with "I don't care of productivity", the method falls apart in tatters.

-----

私、生産性については、かなり徹底的に勉強しました。

Me, I've studied productivity pretty thoroughly.

その結果、「生産性について、合意が取れている定義が存在しない」ということを発見しました。

As a result, I found that "there is no agreed-upon definition of productivity.

そして、「生産性」と「幸福」の間には、強い相関が存在しないことも知りました。

I also learned that there is no strong correlation between "productivity" and "happiness".

-----

「生産性を上げる = 幸福」と「幸福 = 善」から、「生産性を上げる = 善」という三段論法は成立します。

The triadic argument, "Increase productivity = happiness" and "Happiness = goodness," is established from "Increase productivity = goodness.

しかし、

However, it can also be interpreted as,

―― その"生産性"を上げるのは、"私以外の誰か"で良くね?

"Why can't someone other than me make it more productive?"

という解釈が可能です。

さらに、「Google式仕事術」が、"この私"に「楽しさや喜びを与えているのか?」 という点について、私には分からないのです。

Furthermore, I can't know that "Google Method of Working" gives me joy and pleasure of mine.

■自分でコラムを書かなくても、面白いコラムを書いている人がいるから、そのコラムを読めばいい。

- Even if I don't write your own column, someone else writes an interesting column, so I can read it.

■綺麗なイラストを書ける人は、世の中にゴマンといるから、その人に外注すればいい

- There are many people who can draw beautiful illustrations in the world, so I can outsource to them.

■自分でコーディングしなくても、コーディングのプロに頼めばいい

- I can ask a professional to do the coding for me.

まったく、その通りだと思います。

I think these are absolutely right.

(続く)

(To be continued)

2020/08,江端さんの技術メモ

0. メモ

CREATE DATABASE ca_sim0; の逆で、DBの消去方法は DROP DATABASE ca_sim0;

  1. メイン

すでに地図DBは作ってきたが、今のうちに纏めておきます。ここでは東京の豊洲地区を例にして説明します。

なお、Dockerの利用を前提とし、それぞれの地区のDBはバラバラに管理するものとします。地区ごとに取り扱えるようにして、DBを切り替えて利用することを前提とする為です。

(Step1) (to-path)/toyosu というディレクトリを掘る

(Step2) そのディレクトリに、以下のdocker-compose.ymlを作ります。

version: '3.7'

services:
  db:
    image:  postgis-pgrouting:latest
    environment:
      POSTGRES_HOST_AUTH_METHOD: 'trust'
      POSTGRES_PASSWORD: 'postgres'
    expose:
      - 5432
    ports:
    - 15432:5432
    volumes:
      - db_data
      - ./shared:/shared
  db_data:
    image: busybox
    volumes:
      - /data/db

これに対して、

docker-compose up -d
Creating network "toyosu_default" with the default driver
Pulling db (postgis-pgrouting:latest)...
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.

Continue with the new image? [yN]y
Pulling db (postgis-pgrouting:latest)...
ERROR: pull access denied for postgis-pgrouting, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
ubuntu@ip-172-26-13-137:~/toyosu$

てなものが出てきた時は、

image: postgis-pgrouting:latest

の代わりに、

image: pgrouting/pgrouting:v3.0.0-dev-postgresql_12

にしたら動いた(理由は不明だが、まあいいか)

DB(PostgreSQL)のアクセス用のポート番号は、15432としています。ローカルにPostgresがある場合にバッティングを避ける為です。

(Step3) そのディレクトリの中で、"docker-compose up -d"を実行する。

(Step4)"$ docker start -a toyosu_db_1"としてコンテナを起動する

(Step5)(winpty) "docker container exec -it toyosu_db_1 bash" でシェルに入る

(Step6) "psql -U postgres" で、DBのコンソールに入る

(Step7)psqlでデータベースを新規作成する(以下、データベース名をca_simとする)。

postgres=#CREATE DATABASE ca_sim

(Step8)次のコマンドを実行する

postgres=# \c ca_sim
postgres=# create extension postgis;
postgres=# create extension pgrouting;

(Step9) ここで、もう一つ、コンソール(2)をたちあげて、(to-path)/toyosuに入っておく

(Step10) https://www.openstreetmap.org/ から、豊洲地区を選んで地図DBをエクスポートする

ファイル名を"toyosu.osm"として、(to-path)/toyosuに保存する。

↓私が使っている、"toyosu.osm"

(Step11) コンソール2で、"toyosu.osm"を、コンテナに放り込む

>docker cp toyosu.osm toyosu_db_1:/db_data

(Step12)コンソール2で、"apt-get update"、"apt-get update" を実施した後、"apt-get install osm2pgrouting"を実施

(Step13)コンソール2で、"osm2pgrouting -f /db_data/toyosu.osm -c /usr/share/osm2pgrouting/mapconfig_for_cars.xml -d ca_sim -U postgres" を実施

これで、地図DBはできているハズだが、多分、一発で成功することはないので、いろいろ試してみて下さい。

(Step14) psqlでログインしているコンロールから、以下の操作をして表示ができれば、成功

postgres=# \c ca_sim
You are now connected to database "ca_sim" as user "postgres".
ca_sim=# \dt
List of relations
Schema | Name | Type | Owner
--------+-------------------+-------+----------
public | configuration | table | postgres
public | pointsofinterest | table | postgres
public | spatial_ref_sys | table | postgres
public | ways | table | postgres
public | ways_vertices_pgr | table | postgres
(5 rows)

ca_sim=# select * from ways;

以下のような表示がでてくれば、(多分)成功

QGIS3で接続すると、こんな感じのものが表示されるはず

以上

江端さんの忘備録

コンテナに、"ebata_db_1" とか、 "ebata_db_data_1"とかの名前ができているんだけど、一体、誰が命名しているのか全然分からなかったけど、たまたま見つけたので記載しておく。

ディレクトリ名 "casim2020"のところに、以下のdocker-compose.yml を作り、

version: '3.7'

services:
  db:
    image:  postgis-pgrouting:latest
    environment:
      POSTGRES_HOST_AUTH_METHOD: 'trust'
      POSTGRES_PASSWORD: 'postgres'
    expose:
      - 5432
    ports:
    - 15432:5432
    volumes:
      - db_data
      - ./shared:/shared
  db_data:
    image: busybox
    volumes:
      - /data/db

ebata@DESKTOP-P6KREM0 MINGW64 ~/casim2020
$ docker-compose up -d
Creating network "casim2020_default" with the default driver
Creating casim2020_db_1 … done
Creating casim2020_db_data_1 … done

というように、ディレクトリの名前が自動的に付与されるらしい。

2020/07,江端さんの技術メモ

Docker commitで作ったイメージをアップしてみようと思って、docker pushを使ってみたんだけど、上手く動きませんでした。

ebata@DESKTOP-P6KREM0 MINGW64 ~/xxxxxxx_ride_hailing_go
$ docker push ebata_db_data_1_back2
The push refers to repository [docker.io/library/ebata_db_data_1_back2]
d103f95b4a98: Preparing
195be5f8be1d: Preparing
denied: requested access to the resource is denied

ebata@DESKTOP-P6KREM0 MINGW64 ~/xxxxxxx_ride_hailing_go
$ docker push ebata_db_data_1_back2
The push refers to repository [docker.io/library/ebata_db_data_1_back2]
d103f95b4a98: Preparing
195be5f8be1d: Preparing
denied: requested access to the resource is denied

なんで上手くいかないのかなー、とググッてみたら、イメージ名にルールがあったみたいです。ユーザ名がtomoichiならば、image作る時に、こういう名前にしなければダメみたい。

ebata@DESKTOP-P6KREM0 MINGW64 ~/xxxxxxx_ride_hailing_go
$ docker commit f5ae64d47096 tomoichi/ebata_db_data_1_back2
sha256:bf565f55a2cf06e0c9fe6ecb3460f7afe7228cf48886ae0a71cde6bf770ebf1c

ebata@DESKTOP-P6KREM0 MINGW64 ~/xxxxxxx_ride_hailing_go
$ docker commit 64101530c199 tomoichi/ebata_db_1_back2
sha256:6243b4ad2ea96bca6183b331a1c2c4467c9337ce2b305e40ca6a1d456b58df8d

でもって、

ebata@DESKTOP-P6KREM0 MINGW64 ~/xxxxxxx_ride_hailing_go
$ docker push tomoichi/ebata_db_data_1_back2
The push refers to repository [docker.io/tomoichi/ebata_db_data_1_back2]
d103f95b4a98: Preparing
195be5f8be1d: Preparing
d103f95b4a98: Pushed
195be5f8be1d: Pushed
latest: digest: sha256:e69eb3011f892fc5fe80530657f2ed0c1b59202cdca62788483315412a54be50 size: 734

みたいに成功するようです。

2020/08,江端さんの技術メモ

「パスワードの長さが足りん」とか言われるが、今さらログイン環境変えるのも恐しいので、なんかとできないか探ってみた。たまたま上手くいったのでメモを残しておく

と、9文字以上のパスワードが必要と言われたが、"Sing in"を押下する。

入れた様子。

Dockerの環境、ふっとぶとか考えるだけで怖いので、できるだけ何も変更しないで進めたい。