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

昨夜、らくがきのように綴った

Let’s encrypt を試してみた件(整理は明日)

を、まとめておきます。

昨日の実験で、Amazon lightsail でも、自前の公開暗号鍵(Let’s encrypt)を使えることが分かって、昨夜から気分の良い私です ―― これで、3.5ドル/月の、個人AWS練習用サーバの目処が立った。

どうも、私、"Let’s encrypt"を含めて、どうも私は公開暗号鍵の取扱いを、色々勘違いしていたようです。

たとえば、こちら、とか、こちら、で、AWSのロードバランサー(ELB: Amazon Elastic Load Balancing)に、"Let’s encrypt"で作った公開暗号鍵を関連付ける作業について記載しています。

しかし、AWSの供与をして頂いた部署が、IAMの設定を理解しておらず(もちろん、私も理解していませんでしたが)、 公開暗号鍵がロードバランサに紐付かずに、この時は、地獄を見ました

"Let’s encrypt"を使った認証鍵と暗号鍵を生成する時に、引数に、httpサーバの起動状態やら、鍵の置き場所などを指定するものだから、私は上位の認証局が、下々(私)の認証鍵と暗号鍵を見張っていると思っていました。

しかし、昨夜のGolandのコーディングで、認証鍵と暗号鍵は、有効期限付きのただのファイルである、ということを理解しました。

公開鍵証明書の認証局(CA: Certificate Authority)は、「下々のもの(私)に頼まれて、上位認証局(お上)が、鍵(ファイル)を作っているだけ」 ―― とりあえずは、この理解で十分であることが分かりました。

# というか ―― 巷(ちまた)の説明、難しすぎる。

まあ、それはさておき。

今回試みた、Let’s encryptでの鍵作りについて説明します(前提は、こちらを読んでおいて下さい)。

Let’s encryptでの鍵作りのパラメータは、省略することができるようです

$sudo certbot certonly --webroot -w /var/www/html -d sea-anemone.tech -d www.sea-anemone.tech

$sudo certbot certonly  -w /home/ubuntu/go_template/server_test -d sea-anemone.tech

  • "--webroot"は、webサーバの稼動している状況で扱う(しかもhttp://(×https://)が通らないとダメだめらしい)
  • "-w"以下は、golangのサーバを動かしている(サーバプログラムのある)ディレクトリを記載するらしい
  • "-d"以下は、SSLで使うドメイン名を入力("www.sea-anemone.tech"は、なんか知らんけど拒否された。理由は不明だけど、まあ、今は使っていないので無視する)

てな感じで、「とにかく鍵作ってくれ!」と頼むと、

How would you like to authenticate with the ACME CA? 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
1: Spin up a temporary webserver(standalone)  (一時的なWebサーバを単独で起動する) 
2: Place files in webroot directory (webroot)ファイルを webroot ディレクトリに配置 する(webroot) 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

となっていて、少なくとも、nginxなどのwebサーバ上げていない状態だから、少くとも"2"ではなく、"1"でを押下したら、

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at:
 /etc/letsencrypt/live/sea-anemone.tech/fullchain.pem 
Your key file has been saved at: 
/etc/letsencrypt/live/sea-anemone.tech/privkey.pem

という場所に鍵を作ってくれた様子。

ところが、この鍵、普通のmoreやlessでは見えずに、sudo more などとしないと見えないし、privkey.pemについては、それすらも見えない、という慎重さです。

とにかく、golangのサーバを動かしている(サーバプログラムのある)ディレクトリにコピーしました。

ubuntu@ip-172-26-13-137:~/go_template/server_test$ sudo cp /etc/letsencrypt/live/sea-anemone.tech/fullchain.pem . 
ubuntu@ip-172-26-13-137:~/go_template/server_test$ sudo cp /etc/letsencrypt/live/sea-anemone.tech/privkey.pem .

そんでもって、privkey.pemの権限が厳しいので、危ないけど >chmod +777 privkey.pem をやって、golangからアクセスして貰えるようにしておきました(権限のモードを忘れた)。こうしないと、go run serverXX.goをやると「privkey.pemが読めん」と文句を言われます。

で、serverXX.goの中を書き換え

/*
                log.Fatal(http.ListenAndServe(*addr, nil)) // localhost:8080で起動をセット
        */

        /*
        var httpErr error
        if _, err := os.Stat("./algo.crt"); err == nil {
                fmt.Println("file ", "algo.crt found switching to https")
                if httpErr = http.ListenAndServeTLS(*addr, "./algo.crt", "./algo.key", nil); httpErr != nil {
                        log.Fatal("The process exited with https error: ", httpErr.Error())
                }
        } else {
                httpErr = http.ListenAndServe(*addr, nil)
                if httpErr != nil {
                        log.Fatal("The process exited with http error: ", httpErr.Error())
                }
        }
        */

        var httpErr error
        if _, err := os.Stat("./fullchain.pem"); err == nil {
                fmt.Println("file ", "fullchain.pem found switching to https")
                if httpErr = http.ListenAndServeTLS(*addr, "./fullchain.pem", "./privkey.pem", nil); httpErr != nil {
                        log.Fatal("The process exited with https error: ", httpErr.Error())
                }
        } else {
                httpErr = http.ListenAndServe(*addr, nil)
                if httpErr != nil {
                        log.Fatal("The process exited with http error: ", httpErr.Error())
                }
        }

としたら、iPadで

https://sea-anemone.tech:8080
https://sea-anemone.tech:8080/smartphone

も、問題なく出力されるようになりました。

とりあえず、PruneMobileを雲の上に上げるメドが付き、ようやく一安心です。

 

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

ubuntu@ip-172-26-13-137:~/go_template/server_test$ sudo certbot certonly  -w /home/ubuntu/go_template/server_test -d sea-anemone.tech
Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/sea-anemone.tech/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/sea-anemone.tech/privkey.pem
   Your cert will expire on 2021-01-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - 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

--webroot などをガン無視。www.sea-anemone.tech が作れなかったけど、こっちも無視。

でもって、

ubuntu@ip-172-26-13-137:~/go_template/server_test$ sudo cp /etc/letsencrypt/live/sea-anemone.tech/fullchain.pem .
ubuntu@ip-172-26-13-137:~/go_template/server_test$ sudo cp /etc/letsencrypt/live/sea-anemone.tech/privkey.pem .

を強行。

privkey.pemの権限が厳しいので、危ないけど >chmod +777 privkey.pem をやって、golangからアクセスして貰えるようにしておいた(権限のモードを忘れた)

で、serverXX.goの中を書き換え

/*
                log.Fatal(http.ListenAndServe(*addr, nil)) // localhost:8080で起動をセット
        */

        /*
        var httpErr error
        if _, err := os.Stat("./algo.crt"); err == nil {
                fmt.Println("file ", "algo.crt found switching to https")
                if httpErr = http.ListenAndServeTLS(*addr, "./algo.crt", "./algo.key", nil); httpErr != nil {
                        log.Fatal("The process exited with https error: ", httpErr.Error())
                }
        } else {
                httpErr = http.ListenAndServe(*addr, nil)
                if httpErr != nil {
                        log.Fatal("The process exited with http error: ", httpErr.Error())
                }
        }
        */

        var httpErr error
        if _, err := os.Stat("./fullchain.pem"); err == nil {
                fmt.Println("file ", "fullchain.pem found switching to https")
                if httpErr = http.ListenAndServeTLS(*addr, "./fullchain.pem", "./privkey.pem", nil); httpErr != nil {
                        log.Fatal("The process exited with https error: ", httpErr.Error())
                }
        } else {
                httpErr = http.ListenAndServe(*addr, nil)
                if httpErr != nil {
                        log.Fatal("The process exited with http error: ", httpErr.Error())
                }
        }

としたら、とりあえず

https://sea-anemone.tech:8080

で、iPadに地図が表示されるのは確認できた。

今日はここまで。

 

 

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

本日は、コラムがリリースされた日なので、日記はお休みです。

Today, new my column is released, so I take a day off.

踊るバズワード ~Behind the Buzzword(7)ブロックチェーン(1):

ビットコインの正体 ~電力と計算資源を消費するだけの“旗取りゲーム”

Dancing Buzzword - Behind the Buzzword (7) Blockchain(1)

The true nature of Bitcoin - a "beach flag" that only consumes power and computing resources

-----

今回から、新シリーズ「ブロックチェーン」になります。

I am launching a new series, "Blockchain"

特に今回は、「ビットコイン」について調べていたのですが、ずっと頭の中に出続けていたのは、

This time in particular, I was researching "Bitcoin" and the one thing that kept popping up in my head was

「ルパン三世」でした ―― いや、マジです。

It was "Lupin III" -- well, I was serious.

-----

ルパン一味が、自動車(フィアット500)に、札束を満載にして地元警察から逃げるシーンって、定番ですよね。

It's a classic scene that the Lupins escape with a car (Fiat 500) full of stolen cash from local police.

でも、ルパンたちが奪った札束は、つまるところ「印刷物」 ―― つまり「紙」です。

However, the bills taken by the Lupin gang was just "print" -- that is "paper".

ルパン一味による銀行強盗事件に怒った財務大臣が、翌日、通貨単位を1/1000にするデノミ(*)を実行したらどうなるか?

What would happen if the Finance Minister, angered by the bank robbery by the Lupin gang, carried out a denomination (*) that would reduce the unit of currency to 1/1000th of its original size?

(*)ここでは「通貨単位を切り下げる」の意味

(*) In this context, it means "devaluing a currency unit".

ルパン一味は、その強盗事件の必要経費すら捻出できない、という窮地に追いやれることになります。

The Lupin gang can't even come up with the necessary expenses for the robbery, which puts them in a tight spot.

『債権者に追い立てられるルパン三世』 ―― あまり見たくないシーンです。

'Lupin III being driven out by his creditors' -- a scene I don't really want to see.

まあ、強盗事件くらいで、政府がデノミをするとは思えませんが、それでも、

Well, I don't think the government is going to denominate at least a robbery, however,

―― ルパンより、国家権力の方が強いよなぁ

"The power of the state is more powerful than Lupin"

と、当たり前の事実を、今さらながら考えていました。

I was thinking about such an obvious fact.

-----

量子コンピュターの論文を全部廃棄処分した後、私は、ずっと、

After disposing of all the quantum computer papers, I've been thinking

■貨幣って何だろう?

What is currency?

■価値ってどういうことだろう?

What does value look like?

■信用って、どうやって発生させるんだろう?

How can trust be generated?

ということを考え続けていて ――

「通貨ゲシュタルト崩壊」を発生させていました。

I was in a "currency gestalt collapse".

 

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

PruneMobile  を Amazon Lightsail に乗せています。

https://が上手く起動しなかったので、色々考えていました。

まず、serverXX.goを、

//var addr = flag.String("addr", "0.0.0.0:8080", "http service address") // ローカルテスト
var addr = flag.String("addr", ":8080", "http service address") // AWS上で動かす時

と変更して、さらに、これまで使ってきた「オレオレ証明書」の内容に問題があると気がついて、mkcert を使って、AWS Lighsail対応に作り直してみました。

C:\Users\ebata\Downloads>mkcert-v1.4.1-windows-amd64.exe sea-anemone.tech 43.53.5.81 137.172.25.12 localhost 127.0.0.1
Using the local CA at "C:\Users\ebata\AppData\Local\mkcert" ✨

Created a new certificate valid for the following names 📜
 - "sea-anemone.tech"
 - "43.53.5.81"
 - "137.172.25.12"
 - "localhost"
 - "127.0.0.1"

The certificate is at "./sea-anemone.tech+4.pem" and the key at "./sea-anemone.tech+4-key.pem" ✅

で、"sea-anemone.tech+4.pem"を"algo.crt"と、"./sea-anemone.tech+4-key.pem" を"algo.key"とリネームして、serverXX.goの入っているディレクトリに放り込みました。

WindowsPCの方は、上手く表示できるのですが、iPhoneやiPadの方は、

ERROR:undefined
onclise:CLOSE

が表示されて、JavaScriptが走りません。

分からないのですが『さすがに、iPhoneは「オレオレ証明書」では騙せないのかな』などと考えています。

Amazonの証明書は無料なのですが、なぜかAmazonの証明書はロードバランサがないと使えず、そんでもってロードバランサは$18/monthも金を取られるんです。本体が$3.5/monthなのに、なんか理不尽です。

とすると、アレかなぁ・・・できるだけ手を出したくないんだけどなぁ。

ともあれ、今日は疲れましたので、終了です。

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

(昨日の続きです)

(Continuation from yesterday)

一方、「一般社会の犯罪率と比較して犯罪率は低い」という論文もあります。

On the other hand, the paper says that "crime rates are low compared to the crime rates of the general public".

しかし、逃げられない子どもたちを閉じこめた空間での犯罪を、一般社会の犯罪率と比較して論じても意味はありません。

But crime in spaces that confine children who cannot escape. It makes no sense to discuss this in comparison to the crime rate in the general public.

「教師」に限っていえば、社会の一般的な犯罪に対するスタンスと、同様に取り扱われる訳がないのです。

When it comes to 'teachers', there is no reason why it should be treated in the same way as society's general stance on crime.

この論文の表1に記載されている、教員による犯罪者が、2008年~12年の4年間に2685人もいた、という絶対値だけでも、驚愕の事実です(最近のデータは、もっと凄いはずですが)。

The absolute figure alone, listed in Table 1 of this paper, of 2,685 offenders by teachers in the four-year period 2008-12, is astounding (although the more recent data should be even more impressive).

「教師による性犯罪が一般社会と比較して半分程度である」という事実は、「少ない」のではなく、驚愕的に「多い」のです。

The fact that "sexual crimes committed by teachers are about half as high as those committed by the general public" is not "low", but shockingly "large".

そもそも、教師は、基本的には大学出身者からなる高学歴者の集団です。

To begin with, teachers are essentially a group of highly educated people made up of college graduates.

集団で比較するのであれば、「従業員数万人の上場企業の従業員」と比較するのが妥当です。

If you want to make a comparison, it's reasonable to compare it to "employees of a publicly traded company with tens of thousands of employees".

調査していませんが、断言します ―― この上記2つの集団を比較すれば、教師の性犯罪率の方が圧倒的に高いはずです。

I haven't studied it, but I assure you -- if you compare these two populations above, the sex offense rate for teachers should be significantly higher.

さらに言えば、「自己評価のできない馬鹿な大人と、性被害を告発できない子ども」のペアからなる性犯罪のかなりの多くが明みに出ていない、という確信が私にはあります。

According to the pair of "Stupid adults who can't evaluate themselves and children who can't accuse them of sexual assault", I am convinced that a significant number of sex crimes consisting of this pair have not come to light.

もし、ご要望があれば、私が、この連載シリーズで取り上げて、各種の解析手法で調べ上げます。

If you request, I will cover the subject in this series of articles and examine it with various analysis methods.

-----

―― 「教育現場というシステム」は「性犯罪発生装置」として機能する

"The "educational system" functions as a "sex crime generator"

これは、私たち全ての大人にとって辛い現実ではありますが、それでも、この事実の認定から始めなければなりません。

This is a painful reality for all of us adults, but we must begin with an acknowledgement of this fact.

そして、そのような装置の機能を破壊するために、あらゆる手を尽さなければなりません。

And we must do everything in our power to destroy the functioning of such a device.

とりあえず今日のところは、

Anyway, for today, I propose the perspective of

―― 「将来、教師になりたい」という夢を語る若者を「気持ち悪い奴」という目で見る

"Young people who talk about their dreams of being a teacher in the future to be "creepy""

という視点を提案します。

もちろん、酷すぎる暴論であり、恐しいまでの偏見であり、職業差別の極(きわみ)と言えます。

Of course, this is an outrageous argument, a horrible prejudice, and the ultimate in professional discrimination.

-----

ただ、

However, based on the facts of

『そういう目線でお前を見ている奴(江端)が、少なくとも、ここに一人いる』

"There's at least one person here who's looking at you like that. That is "Ebata""

という事実を踏まえた上で、教職を希望する全ての若者が、

All young people who want to teach ask themselves,

―― 『自分は、人を教え導く人間である』という「肥大した自我」を持っているのではないか?

"Do I have a 'bloated ego' that says 'I can be a person who teaches and leads others'?"

と、自分に問いかける「きっかけ」になってくれれば、先ずは良いと思います。

If this is a "trigger" for them to ask themselves, it might be good.

-----

少なくとも、私は「全ての生徒を、平等に取り扱うことができる様な人間ではない」という自己評価を行い、「教職」を候補から外した人間です。

At least, I made a self-assessment that "I'm not the kind of person who can treat all students equally." and has excluded "teaching profession" from by candidates.

そして、その時の私の評価が『恐しく正確であったこと』を、今、心底から実感しています。

And now, from the bottom of my heart, I realize that my evaluation at that time was "terrifyingly accurate".

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

(昨日の続きです)

(Continuation from yesterday)

ところが、この閉じられた特殊な閉鎖環境において、「自分は異性にモテる」と感違いするバカがいる訳です。

However, in this closed-off environment, there are idiots who think that they are popular with the opposite sex.

そして、このバカは、そのような閉鎖環境にあって、子どもの無知に付け込み、社会的に犯罪(性犯罪)を、大した意識もなく実行する。

And this idiot takes advantage of the child's ignorance in such a closed environment to commit crimes (sex crimes) in society without much awareness.

恐らく、その事件の多くは、明るみにでることがありません。

Perhaps many of those incidents will never come to light.

被害者である子どもは「告発」という手段の存在を学んでおらず、知らないからです。

This is because the child, the victim, has not learned and does not know that the means of "accusation" exists.

自己評価のできない馬鹿な大人と、性犯罪被害を告発できない子ども ―― 背筋が凍るような恐しい組み合わせです。

"Stupid adults who can't evaluate themselves and children who can't accuse them of sexual assault". This is a frightening combination that sends chills down my spine.

-----

ちょっと言い過ぎかもしれませんが、正直に言わせて頂きますと、

That may be a bit of an exaggeration, but I have to be honest with you.

―― 「将来は教師になりたい」という夢を語る若者の全てを、私は「気持ち悪い」と思う

I find young people who talk about their dreams of being a teacher in the future to be "creepy".

『自分は、人を教え導く人間になれる』という「肥大した自我」を持っているというだけで、私は寒気がします。

Just the fact that I have a 'bloated ego' that says 'I can be a person who teaches and leads others' gives me chills.

そもそも、社会一般の矛盾や非合理や理不尽に一度も接することなく、「学生→教師への、タイムラグ0の直行ルート」という就職パスがあること自体、どうかしていると思う。

In the first place, I think it's crazy that there is a 'direct route to employment, from student to teacher, with zero time lag', without ever having to deal with the contradictions, irrationality and unreasonableness of society in general.

教師の採用資格には、

A teacher's employment qualifications should be included

「文部科学省が認定する企業において、係長相当以上の職位での3年以上の業務経験のあるもの」

A person who has at least three years of work experience in a position equivalent to or higher than section head in a company certified by the Ministry of Education, Culture, Sports, Science and Technology.

と入れるべきでしょう。

学校という特殊な環境は、「肥大した自我」を「徹底的に叩き潰された者だけ」が「教師」として存在できる資格がある、と思うのです。

I believe that only those who have had their "bloated ego" "thoroughly beaten down" can enter the special environment of school.

(「文部科学省が認定する」を入れるのは、その気になれば、会社なんぞ1円で作れて、即日社長になれるからです)

(The reason for including the phrase "accredited by the Ministry of Education, is that 'anyone could build a company for a penny and become president on the same day")

(続く)

(To be continued)

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

私、学生のころ学習塾や家庭教師のアルバイトをやっていました。

When I was a college student, I had a part-time job as a tutor and cram school.

そして、

And I know the following from my experience.

―― 男性講師は、男性講師という理由だけで、女の子にモテる

"Male instructors are popular with girls just because they are male instructors"

ということを、経験的に知っています。

バレンタインや、年度末などは、結構な数のプレゼントを受けとりました(鉄板の『手編みのマフラー』というものもありました)

At Valentine's Day and the end of the school year, I received quite a few gifts from the girls (there was even "hand-knitted scarf").

もちろん、これらが「ティーン女子の幻想」であることは、よく分かっていました。

Of course, I was well aware that these were based on the "teen girl fantasy".

冷静に考えるまでもなく、私に「モテる要素」なんぞ、ある訳がないからです。

Needless to say, there was no way I have the "factor of being popular".

-----

ところが、講師(教師も含む)というものは、

However, instructors (including teachers) are

教壇から子どもを見おろしながら、

Looking down at the children from the podium.

■子どもに分からない勉強を、分かるように教えることができ、

- They can teach my children what they don't understand in a way that they can understand.

■子どもが、まだ体験していない、様々な人生経験を語ることができ、

- They can talk about a variety of life experiences that the children have not yet experienced, and

■子どもでは獲得できない、人生訓のようなものを語ることができ、

- They can speak the kind of life lessons that the children can't acquire.

ます。

そして、実社会であれば「一笑に付されるような理想論」や「簡単にバレるような自分の英雄譚」を、

And they can speak non-sense "laughable idealism" and "easily exposed tales of their own heroism"

閉じられた空間で、

in an enclosed space

誰にも邪魔されることなく、

without being interrupted

一方的に語る

unilaterally

ことができる環境にあります。

-----

そんな、男性講師に、ティーン女子が、恋心のようなものを発生させてしまうのは、これはもう、

"Such a thing as a teenage girl giving rise to a kind of love affair with a male instructor" is

―― 教育現場というシステムにおける、構造上の欠陥

"Structural flaws in the system of education field"

と言えます。

-----

まあ、私が、学生時代に、比較的マシな講師として過してこれたのは

Well, the reason why I did as a relatively good teacher when I was a college student

「学生だった頃、既に、この事実に気がついていた」

"I was already aware of this fact when I was a college student"

からです。

(続く)

(To be continued)

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

document.getElementById("open").onclick = function(evt) と、ws.onopen = function(evt) が、混乱して、上手く動かなかったけど、ようやく分かりました(ような気ががしています)。

■document.getElementById("open").onclick = function(evt) { 処理内容}は、
"open"ボタンを押した時に行う処理を行い、
■ws.onopen = function(evt){処理内容}は、
websocketのopenのイベントが飛んできた時に行う

つまり、"ボタン"と"websocket"という、全く別物を取り扱っている、ということに、やっと気がつきました ―― 同じ"open"という言葉を使うので、混同していました。

なので、

ws.close()処理は、当然に、document.getElementById("open").onclick = function(evt) { 処理内容} の中で実施しなけばなりません。

ws.onopen = function(evt){処理内容}は、すでにwebsocketのclose処理が行われた後の処理を記載するので、ここでws.close()を記載したら、変なことになります(二重にwebsocketのclose処理をすることになる)


 

それと、位置情報をコールバックで取得する関数を、
const successCallback = (position) => { 処理内容 }

エラーイベントを検知する関数を、
const errorCallback = (err) => { 処理内容 }
と記載した場合、

このコールバックを登録する関数は、
watchPositionID = navigator.geolocation.watchPosition(successCallback, errorCallback, options);
であり、

このコールバックを停止する関数は、navigator.geolocation.clearWatch(watchPositionID);

となります。

という訳で、server26.goの"smartphoneTemplate"で登録している、htmlファイル(javascriptを含む)の部分だけ切り出したものを記載しておきます。

var smartphoneTemplate = template.Must(template.New("").Parse(`
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script> 

let watchPositionID;  // グローバル変数として出しておく
let ws; // グローバル変数として出しておく

window.onload = () => {
	// これは、Web起動時に最初に読まれる部分であるが、今回、これらの関数は、全部
	// 	document.getElementById("open").onclick = function(evt) {  // openボタンを押した時 
	// 中に放り込んだ。 openボタンを押した後に起動するようにする為である

	// navigator.geolocation.watchPositionについては次のURLにかかれています。
	// https://developer.mozilla.org/ja/docs/Web/API/Geolocation/watchPosition

	// これが位置情報コールバックの起動コマンド
	//watchPositionID = navigator.geolocation.watchPosition(successCallback, errorCallback, options);

	// ここで(もう)webソケットを開く
	//ws = new WebSocket("{{.}}");

};

// ブラウザーを閉じる前に位置の監視を止めます
window.onbeforeunload = () => {
	// こちらの内容も
	// document.getElementById("close").onclick = function(evt) { // closeボタンを押した時
	// の中に放り込んだ  closeボタンを押した時に起動するようにする為である	

	// これが位置情報コールバック停止のコマンド	
	//navigator.geolocation.clearWatch(watchPositionID);
	
	//ws.close();
}


// 引数にはミリ秒を指定。(例:5秒の場合は5000)
function sleep(a){
	  var dt1 = new Date().getTime();
	  var dt2 = new Date().getTime();
	  while (dt2 < dt1 + a){
		dt2 = new Date().getTime();
	}
	  return;
}

// 以下の3つはグローバル変数として取り扱う
var personal_id =0;  
var lat;
var lng;  

//var ws;

// 位置情報を構造体として格納する為のファンクション(jsでは、こういう風に使うらしい)
function obj(id, lat, lng){
	this.id = id;
	this.lat = lat;
	this.lng = lng;
}

// 乱数生成装置 (minとmaxの間の乱数を作る)
function random(min, max){
	return  Math.random()*(max-min) + min;
}


window.addEventListener("load", function(evt) {
	// メッセージ表示部
    var output = document.getElementById("output");
    var input = document.getElementById("input");

    var print = function(message) {
        var d = document.createElement("div");
        d.textContent = message;
        output.appendChild(d);
	};

	///// 起動時のボタン設定(アクティブにしたり非アクティブにしたりする)
	// disabled属性を削除
	document.getElementById("open").removeAttribute("disabled");
	document.getElementById("open").style.color = "black";

	// disabled属性を設定 (closeボタンを非活性化)
	document.getElementById("close").setAttribute("disabled", true);
	document.getElementById("close").style.color = "White";			

	document.getElementById("open").onclick = function(evt) {  // openボタンを押した時
		console.log("document.getElementById open");

		// disabled属性を設定 (openボタンを非活性化)
		document.getElementById("open").setAttribute("disabled", true);
		document.getElementById("open").style.color = "White";		

		// disabled属性を削除(closeボタンを非活性化)
		document.getElementById("close").removeAttribute("disabled");
		document.getElementById("close").style.color = "black";	

        //if (ws) {
        //    return false;
        //}
	

		// ここでコールバック関数を起動
		watchPositionID = navigator.geolocation.watchPosition(successCallback, errorCallback, options);
		// websocket オープン
		ws = new WebSocket("{{.}}");
		// 最初はidを0にする
		personal_id = 0;   
			
		ws.onopen = function(evt) {  // 通信openイベントを検知した時(通信がopen状態になった後)
			print("OPEN");
		
			var send_obj = new obj(0, lat, lng);  // 最初はpersonal_idを"0"としてエントリ
	
			console.log("open:send_obj");	
			console.log(send_obj.id);	
			console.log(send_obj.lat);
			console.log(send_obj.lng);		
	
			var json_obj = JSON.stringify(send_obj);
			ws.send(json_obj);

		}

		ws.onclose = function(evt) {  // 通信closeイベント(×ボタン)を検知した時 (通信がclose状態になった後)
			print("onclose:CLOSE");
            ws = null;
        }

		ws.onmessage = function(evt) {  // 通信メッセージを受信した時(受信した後)
			print("RESPONSE: " + evt.data);  // jsonメッセージの内容を表示
			// データをJSON形式に変更
			var obj = JSON.parse(evt.data);

			personal_id = obj.id; // IDの取得(何回も取る必要はないが)
			console.log("personal_id");			
			console.log(personal_id);
			
			if ((Math.abs(obj.lat) > 90.0) || (Math.abs(obj.lng) > 180.0)){ // 異常な座標が入った場合は、マーカーを消去する
				console.log("before ws.close()");
				ws.close();
				console.log("after ws.close()");
			}
		}
		
        ws.onerror = function(evt) { //  エラーイベントを検知した時(検知した後)
            print("ERROR: " + evt.data);
        }
        return false;
    };
	
	document.getElementById("close").onclick = function(evt) { // closeボタンを押した時
		console.log(" document.getElementById close");

		// disabled属性を削除
		document.getElementById("open").removeAttribute("disabled");
		document.getElementById("open").style.color = "black";

		// disabled属性を設定 (closeボタンを非活性化)
		document.getElementById("close").setAttribute("disabled", true);
		document.getElementById("close").style.color = "White";	

        if (!ws) {
            return false;
		}
		
		var send_obj = new obj(personal_id, 999.9, 999.9); //  意図的に異常な位置情報を入れて正常終了させる処理

		console.log("close:send_obj");
		console.log(send_obj.id);		
		console.log(send_obj.lat);
		console.log(send_obj.lng);		

		var json_obj = JSON.stringify(send_obj);
		ws.send(json_obj);

		ws.close();  // これはws.closeの方で実施すると変なことになる  closeが実施された後で、close()することになる

		navigator.geolocation.clearWatch(watchPositionID); //コールバック関数の停止?

		personal_id = 0;   // 最後もidを0にする		
	
        return false;
    };
});

// 位置情報の取得に成功した際のコールバック

const successCallback = (position) => {
	console.log("successCallback:position");

	lat = position.coords.latitude;
	lng = position.coords.longitude;

	console.log(personal_id);
	console.log(lat);
	console.log(lng);

	//コールバックが発生するタイミングでサーバに位置情報を送付する

	if (personal_id != 0){
		var send_obj = new obj(personal_id, lat, lng);  // 最初は"0"でエントリ

		console.log("open:send_obj");	
		console.log(send_obj.id);	
		console.log(send_obj.lat);
		console.log(send_obj.lng);		

		var json_obj = JSON.stringify(send_obj);
		ws.send(json_obj);
	}

	// sleep(1000); // 1秒待つ	

}

// 位置情報の取得に失敗した際のコールバック
const errorCallback = (err) => {
	console.log(err);
};

// 位置を監視する構成オプション
// オプションの内容は次のリンクに書かれています。
// https://developer.mozilla.org/ja/docs/Web/API/PositionOptions
const options = {
	enableHighAccuracy: true,
	//timeout: 5000,
	timeout: 500000,
	maximumAge: 0
};

</script>
</head>
<body>
<table>
<tr><td valign="top" width="50%">
<p>Click "Open" to create a connection to the server, 
"Send" to send a message to the server and "Close" to close the connection. 
You can change the message and send multiple times.
<p>
<form>
<button id="open">Open</button>
<!-- <p><input id="input" type="text" value="Hello world!"> -->
<!-- <button id="send">Send</button> -->
<button id="close">Close</button>
</form>
</td><td valign="top" width="50%">
<div id="output"></div>
</td></tr></table>
</body>
</html>
`))

 


 

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

我が国では、「非婚者」の比率が増えてきています。

The proportion of "non-married" people is increasing in our country.

『「非婚」という選択が幸せである』というのではなく、事実『「非婚」は幸せである』のです。

It's not that 'choosing to be 'non-married' is a happy choice,' but the fact that 'non-marriage' is a happy choice.

そもそも「他人と共に生きる」という人生は、それ自体がハードルの高い生き方です。

To begin with, a life of "living with others" is a hurdle in itself.

自分の管理・制御下にない人間と、(大抵の場合は)生涯パートナーとして生きていくというのは、それ自体が奇跡である、と ―― そういう当たり前のことに、ようやく人類は気がつき出したのだと思います。

"living as a partner who is not under our management and control is a miracle (in most case)". I think we are finally realizing that this is a matter of course.

-----

「非婚」によって、出生率が低下し、生産力が減り、国力が削られる ―― なるほど、そうかもしれません。

"Non-marriage" reduces the birth rate, reduces the productive capacity, and diminishes the nation's strength -- okay, maybe so.

―― だったら、何だというのだ?

"What's the matter, even if so ?"

国民の選択によって、国家が衰退するなら、それは国家の運命です。

If a nation is decimated by the choices of its people, it is the fate of the nation.

少なくとも私は構いません ―― 衰退していく国家であっても、それに適応しながら、なんとか生きていける程度には、私は、毎日、勉強し続けています。

At least I don't mind. I continue to learn, every day, to manage to live with it, even in a declining nation, while adapting to it.

-----

どうも、勘違いしている人が多いようですが、「国家(特に政府)は、国民に対して役務(サービス)を提供する主体」です。

Apparently, there are a lot of people who are mistaken. "The state (especially the government) is an entity that provides services to its citizens".

「国民が、国家に使役する義務は1mmもない」のです。

The people are under no obligation to serve the state at all.

なぜ少子化対策をしているのか? ―― これも勘違いしている人が多いようです。

Why is the government taking measures against the declining birthrate? It seems that many people misunderstand this as well.

少子化対策をしているのは、現状の日本国というシステムが必要とする人数を、維持したいからです。

The reason why the government is taking measures against the declining birthrate is because the government wants to maintain the number of people that the current system of Japan needs.

その為には、人口を維持する戦略「少子化対策」が、一番コストが安いからです。

For that purpose, the strategy to maintain the population, "Countermeasures against the declining birthrate," is the cheapest.

-----

しかし、少子化は、もう避けられません。

However, the declining birthrate is inevitable.

少子化が避けられないのであれば、少子化に適応させる方向で、日本国というシステムを変更(縮退)させるしかありません。

If the declining birthrate is unavoidable, there is no choice but to change (degenerate) the system of Japan in the direction of adapting to the declining birthrate.

もっとも、そのようなシステム変更が「簡単である」とは言いませんが、少子化は文明と歴史の必然です。

Although I do not say that such system changes are "easy", the declining birthrate is an inevitable part of civilization and history.

面倒くさらがずに「現状のシステムを変更」し、必要であれば「現状のシステムを放棄する」覚悟が必要とされています。

We need to be prepared to "change the current system" and, if necessary, "abandon the current system" without any hassle.

(まあ、テクノロジーによる解決法もあるのですが、今回は割愛します)

(Well, there is a technology solution, but I'll omit it this time.)

-----

ただ ―― 「非婚」を選んだ人たちに、申し上げたいことはあります。

However, I would like to call attention to those who chose "unmarried."

「非婚」を選んだ人が、頻繁に親戚などの家庭を訊ねる、という傾向が散見されます。

There is a tendency for people who choose "unmarried" to frequently ask their relatives' families.

『休日になると、親戚のその家にいりびたり、子どもたちと遊んで、一日過ごしていく』ということを、日常的に行っている者がいます。

Some people regularly do "on holidays, spend the day at their relatives' homes, playing with their children,".

はっきり言いますが ―― 鬱陶(うっと)しい

To be clear, they are annoying.

というか、空気読め、バカ。

In other words, "Read the atmosphere. this idiot!"

「非婚」を選択しておきながら、何、ラクして「アットホーム」だけを享受しようとしているんだ。

Why you are trying to enjoy only "at home" with ease, even you have selected "unmarried".

厚かましいにも程がある。

You have quite a nerve.

「非婚」という「自由」を選択したのであれば、それに付随する「孤独」も一緒に飲み込め。

If you've chosen the "freedom" of "non-marriage," then swallow the "loneliness" that comes with it, too.

それがトレードオフというものだ。

That's called a trade-off.

例えば、幼児や小学生の女児がいるような家に、頻繁に独身の男がやってくるのを、歓迎する親がいると思うか?

For example -- do you think any parent would welcome a single man who frequents a house with toddlers and school-age girls?

はっきり言って「気持ち悪い」し、もっとはっきり言えば「怖い」。

To be clear, it is "unpleasant", and more clearly, it is "scary".

そもそも『いい歳こいて、自分一人で、自分自身を楽しませる方法すら確立できない奴』というだけで、信用は絶無だ。

In the first place, if you're 'a good old man, on your own, who can't even establish how to entertain himself,' you have no credibility.

―― ということを、本人の前でハッキリと言うのは難しいのです(私は例外)。

It's hard to say that clearly in front of you (I'm an exception).

-----

ともあれ『非婚者の訪問は、既婚者の家庭では歓迎されていません』。察して下さい。

Anyway, 'visits from non-married people are not welcome in the homes of married people'. Please guess.

『「非婚」という選択が幸せである』を選んだ人は、生涯、それを、たった一人で貫ぬく覚悟と義務があります。

Those who choose "Non-marriage is a happy choice" have a lifelong obligation to carry it out alone.

厚かましくも、人様が苦労して作り上げた「幸せシステム」に「ただ乗り」するような奴は ―― 少なくとも、私は許しません。

I won't tolerate anyone who "free rides" on the "happiness system" that others have worked so hard to create.

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

(昨日の続きです)

(Continuation from yesterday)

しかし、私の娘たちは、父親の「技術力」や「資質」を使い倒すことに対しては、一切の躊躇がありません。

However, my daughters have no hesitation about using their father's "technical skills" and "qualities" to defeat him.

家電機器の設定、ネットワーク配線、パソコンの初期構築、ソフトウェアのインストールから、学術レポート書き方、英語翻訳、工作加工、就職や入学試験対応、プレゼンテーション資料の作り方や纏め方 ―― 果ては、

How to set up appliances, network wiring, initial computer setup, software installation, academic report writing, English translation, crafting, job and school entrance exams, how to make and organize presentation materials -- and more,

「自分」の志望動機や、「自分」の将来の夢、に至るまで、「この私」にネタ出し(ブレーンストーミング)をさせます。

They let "me" brainstorm about everything from their motivations for applying for jobs to their dreams for the future.

その為であれば、暗に父親の就寝時間まで指定してきます(例: 『パパさぁ、今日、午前4時より前に寝ちゃう?』)

They will even implicitly specify a bedtime for their father (e.g., "Dad, are you going to bed before 4:00 a.m. today?").

-----

江端:『あのなぁ、なんで、私がお前たちの"動機"や"夢"まで考えなければならないのだ?』

Ebata: "Listen, why do I have to think about your 'motives' and 'dreams' as well?

娘:『いや、私がパパに期待しているのは、"動機"や"夢"に繋げるまでの、論理的な筋道(説明)だよ』

Daughter: "No, what I expect you is a logical path (explanation) to connect to my 'motives' and 'dreams'"

そう。その通り。

Exactly.

"動機"や"夢"を語ることは、それほど難しくありません(もちろん「難しい」という人も沢山いますが)。

"It's not that difficult to talk about their "motivation" and "dreams" (although of course there are many people who say it's difficult).

本当に難しいのは、その"動機"や"夢"に至るまでの、具体的な事例と、客観的な実現性と、そこそこ迫力とドラマのあるストーリー作りです。

What is really difficult is to create a story with concrete examples, objective feasibility, and moderate power and drama, to lead up to the "motivation" and "dream".

-----

実は、これ、特許明細書の書き方と同じです。

In fact, this is the same as how to write a patent specification.

特許明細書は、国家に対して、発明の独占的使用権の付与を請求するための、行政書類です。

A patent specification is an administrative document for requesting the state to grant an exclusive right to use an invention.

しかし、その書類の中には、審査官を納得させ、そこそこ感動させる力強いストーリーも必要なのです。

However, some of the documents also need a powerful story that convinces and impresses the examiner.

それ故、発明を生業(なりわい)とするエンジニアには、「技術力」に加えて、「ストーリーテーラー」としての資質も要求されるです。

Therefore, an engineer whose business is invention is required not only to have "technical ability" but also to have qualities as a "storyteller".

-----

総じて、私は ―― 『娘にブランドバッグをねだられる方が、ラクだな』と思える程度には、娘たちに、コキ使われています。

In general, my daughters have used me as a convenience, like 'it is easier to beg my daughter for a branded bag'