2021/03,江端さんの技術メモ

swigを使ってgoとc++をブリッジをやっているのですが、そうなると、コンパイルオプションの

gcc xxxx xxxxx  -I c:\users\ebata\json\include

というような、力づくが使えないです。

まあ、色々やり方はありますが、一番簡単なのは、Windows10のコントロールパネルから、"CPATH" を作って、 ダイレクトに"c:\users\ebata\json\include"を書き込むのが簡単です。

スマートとか、かっこいいとか、汎用性とか、そういうことは、考えないのが良いです。

2021/03,江端さんの技術メモ

まず、何も考えないで以下のプログラムを実行

// go run main2.go

package main

import (
	"fmt"
)

func subPerson(i int) {
	fmt.Printf("Now... sub_person(%v)\n", i)
}

func person(i int) {
	fmt.Printf("Now... person(%v)\n", i)

	go subPerson(i)
}

func main() {

	for i := 0; i < 5; i++ {
		go person(i)
	}

}

当然、何も表示されれない。go routineが起動する前に、main()が終了してしまうから

なので、最後のスレッドが完了するまでは待機するようにする

// go run main2.go

package main

import (
	"fmt"
	"sync"
)

func subPerson(i int) {
	fmt.Printf("Now... sub_person(%v)\n", i)
}

func person(i int, wg *sync.WaitGroup) {
	defer wg.Done() // WaitGroupを最後に完了しないといけない。
	fmt.Printf("Now... person(%v)\n", i)

	go subPerson(i)
}

func main() {

	var wg sync.WaitGroup
	for i := 0; i < 5; i++ {
		wg.Add(1) // goルーチンを実行する関数分だけAddする
		go person(i, &wg)
	}
	wg.Wait()
}

$ go run main2.go
Now... person(0)
Now... sub_person(0)
Now... person(4)
Now... sub_person(4)
Now... person(2)
Now... person(3)
Now... sub_person(3)
Now... person(1)

ただ、これの場合、subPerson()が実行されないまま終了することがある。例えば、、上記の場合、sub_person(1)が実施されずに終了してしまっている。

なので、subPerson()の終了を持って、main()の終了とするようにすると、こうなる。

// go run main2.go

package main

import (
	"fmt"
	"sync"
)

func subPerson(i int, wg *sync.WaitGroup) {
	defer wg.Done() // WaitGroupを最後に完了しないといけない。
	fmt.Printf("Now... sub_person(%v)\n", i)
}

func person(i int, wg *sync.WaitGroup) {
	subWG := wg
	//defer wg.Done() // WaitGroupを最後に完了しないといけない。
	fmt.Printf("Now... person(%v)\n", i)

	go subPerson(i, subWG)
}

func main() {

	var wg sync.WaitGroup
	for i := 0; i < 5; i++ {
		wg.Add(1) // goルーチンを実行する関数分だけAddする
		go person(i, &wg)
	}
	wg.Wait()
}

結果は、以下の通りとなり、問題なし。

 

$ go run main2.go
Now... person(0)
Now... person(1)
Now... sub_person(1)
Now... person(4)
Now... sub_person(4)
Now... sub_person(0)
Now... person(2)
Now... sub_person(2)
Now... person(3)
Now... sub_person(3)

 

 

 

 

 

 

 

 

 

 

 

2021/03,江端さんの技術メモ

「ドメイン "sea-anemone.tech "のLet's Encrypt証明書期限切れのお知らせ」というのがメールで届きました。
一通りメールを読んだのだけど、詰るところ「作り直せ」ということかな、理解して、以前書いたメモ通りを実施して、関係のあるディレクトリに片っぱしからバラまくことにました 。
に記載されたことを、唯唯諾諾と実施しました。
―― 自動化シェルスクリプトなどというシャレたものを"作らない"ことが寛容だ、ということを、私は知っています。
Let's Encrypt certificate expiration notice for domain "sea-anemone.tech"


ドメイン "sea-anemone.tech "のLet's Encrypt証明書期限切れのお知らせ。


Hello,


こんにちは。


Your certificate (or certificates) for the names listed below will expire in 19 days (on 29 Mar 21 23:38 +0000). Please make sure to renew your certificate before then, or visitors to your web site will encounter errors.


以下の名前に対するあなたの証明書(または複数の証明書)は、19日後(29 Mar 21 23:38 +0000)に期限切れとなります。それまでに証明書を更新しないと、あなたのウェブサイトにアクセスした際にエラーが発生します。


We recommend renewing certificates automatically when they have a third of their total lifetime left. For Let's Encrypt's current 90-day certificates, that means renewing 30 days before expiration. See https://letsencrypt.org/docs/integration-guide/ for details.


私たちは、証明書の有効期間の3分の1が経過した時点で、証明書を自動的に更新することをお勧めします。現在のLet's Encryptの90日証明書の場合、期限切れの30日前に更新することになります。詳細は https://letsencrypt.org/docs/integration-guide/ をご覧ください。


sea-anemone.tech


For any questions or support, please visit: https://community.letsencrypt.org/ Unfortunately, we can't provide support by email.


ご質問やサポートについては、次のサイトをご覧ください: https://community.letsencrypt.org/ 残念ながら、電子メールによるサポートは行っておりません。


For details about when we send these emails, please visit: https://letsencrypt.org/docs/expiration-emails/ In particular, note that this reminder email is still sent if you've obtained a slightly different certificate by adding or removing names. If you've replaced this certificate with a newer one that covers more or fewer names than the list above, you may be able to ignore this message.


特に、名前を追加または削除してわずかに異なる証明書を取得した場合にも、このリマインダーメールが送信されますのでご注意ください。この証明書を、上記のリストよりも名前の数が多かったり少なかったりする新しい証明書に差し替えた場合は、このメッセージを無視することができるかもしれません。


If you are receiving this email in error, unsubscribe at:


誤ってこのメールを受信している場合は、以下の方法で配信を停止してください。


  http://delivery.letsencrypt.org/track/unsub.php?u=30850198&id=f76fe707fe6142509a23d40dde02c153.3i5yYrnKlNWIWqOs%2Fn8YMBMPOVU%3D&r=https%3A%2F%2Fmandrillapp.com%2Funsub%3Fmd_email%3Dt%252A%252A%252A%252A%2540g%252A%252A%252A%252A.%252A%252A%252A




Please note that this would also unsubscribe you from other Let's Encrypt service notices, including expiration reminders for any other certificates.


これにより、他の証明書の期限切れのお知らせなど、Let's Encryptの他のサービスのお知らせも配信停止となりますので、ご注意ください。




Regards,
The Let's Encrypt Team


Let's Encryptチーム

2021/03,江端さんの忘備録

私、これまで新型コロナ感染の「苦痛」について、コラムの中で散々述べてきたのですが、所詮は「伝聞」に過ぎません。

I have been talking a lot about the "pain" of the new corona infection in my column, but it is just "hearsay".

そういう訳で、「苦痛」について是非ご覧頂きたいのは、このYouTubeです

That's why I'd like you to check out this YouTube video about the "pain".

感染したらこうなった!~新型コロナ感染体験から後遺症まで【解説】します~(2021年3月2日)

"This is what happened when I got infected! ~From the experience of the new corona infection to the aftereffects, I will "explain" it - (March 2, 2021)"

-----

私、(普通の)風邪で寝込んでいる時ですら、簡単に「死にたい」と思うほど、苦痛に対して弱い人間です

I am a person who is so vulnerable to pain that even when I'm in bed with a (normal) cold, I easily feel like I want to die.

これ見ていたら、「私は、COVID-19闘病中に、10回くらいは自殺を試みてみるんじゃないか」と思えるほどでした。

Watching this made me think, "I'm probably going to try to kill myself at least 10 times during my COVID-19 struggle.

-----

ちなみに、この報道局の方がおっしゃっている「感染入院中の人間に、電話やメール、LINEをしてこないで欲しい」というのは、本当によく分かります。

By the way, I really understand what this news station staff is saying, "I don't want people to call, email, or call me on line when I'm in the hospital with an infected patient.

そういう意味で、被災地の被災直後の、『お見舞い電話』などというという、バカげた慣習も叩き潰したいです。

In this sense, I would like to crush the ridiculous practice of "sympathy calls" immediately after the disaster in the affected areas.

江端家では、家族の誰かが、地震や災害の直後に電話しようとすると ―― 私が止めます。

In the Ebata family, if a family member tries to call a relative or friend right after an earthquake or disaster -- I stop them.

『震災地の貴重な通信リソース(救難通信が最優先)を"お見舞い"ごときで消費するな』

"Don't consume precious communication resources in the disaster area just for "sympathy". Their first priority is rescue communications"

『自分が安心したい為だけに、被災地の人に迷惑をかけるな』

"Don't bother the people in the disaster area just to make yourself feel safe.

と、言い聞かせています。

That's what I tell my family.

2021/03,江端さんの忘備録

次女:iPhoneを中心としたiOS派

Junior daughter:iPhone and other iOS users

長女:ChromoBookを自費で購入するAndroid派

Senior daughter:Android user who bought ChromoBook at her own expense

嫁さん:娘たちと完全同一機種を購入して、設定を丸投げする派

Wife:who buys the exact same model as her daughters and throws in the whole setup.

江端:職務上、プラットフォームに好みを言える立場にないオールラウンダー

Ebata:All-rounder who is not in a position to express a preference for the platform due to his duties.

-----

という風に、江端家は、ITプラットフォームに関しては、世間の縮図となっています。

Thus, when it comes to IT platforms, the Ebata family has become a microcosm of the world.

2021/03,江端さんの忘備録

最近、朝方、寒さで目が覚めます。

Lately, I wake up in the morning with a cold feeling.

この理由は分かっていて、運動不足による筋力量の減少です。

We know the reason for this. It is the loss of muscle mass due to lack of exercise.

ただ今の時期、「寒い」などと言えば、家族がざわめき出すのは当然で、体温計を押しつけられました。

But at this time of year, if I say something like "it's cold," it's natural for my family to start buzzing, and they push thermometers at me.

私は、確信をもって『風邪とかインフルエンザとか、もう一つの怖い何かではないから』と思っているのですが、

I'm pretty sure it's not 'the common cold or the flu or another scary something, however,

―― 体温を測って見せるのは、自分の為ではなくて、回りの人間の安心の為

"Taking my temperature is not for my own sake, but for the peace of mind of those around me"

であることを知っていますので、素直に従いました。

I knew this, so I obeyed what my family told me.

-----

体温、計測しました。2回。

I've taken my temperature twice.

熱がないことは証明されました。

It proved that my body temperature was not high enough.

なにしろ、一回目の計測が34.2度、二回目は33.9度でしたから。

The first measurement was 34.2 degrees and the second was 33.9 degrees.

------

確認されたのは、体温計の故障でした。

The thermometer malfunction has been confirmed.

本日中に、体温計を換えて、再計測です。

I'll change the thermometer and take another measurement later today.

2021/03,江端さんの忘備録

BS1スペシャル「全貌 二・二六事件~最高機密文章で迫る~」(再放送)を見ました。

I watched the BS1 Special "2.26 Incident - Approaching with Top Secret Documents" (rebroadcast).

私、Nスペは、「キューバ危機・戦慄の記録 十月の悪夢」を超える作品はないだろうと思っていたのですが、これも凄い作品でした。

I thought that N-Spe would never be able to surpass "The Cuban Missile Crisis: A Shuddering Record, Nightmare in October", but this was another great work.

珍しく、私以外の家族も、真剣に見ていました ―― 映画とは異なった迫力と恐怖がありました。

Unusually, my other family members were also watching the program seriously. There was a different kind of power and fear than in the movies.

―― 陸軍の青年将校のクーデターの発生から鎮圧までを、海軍のネットワークがリアルタイムで把握し続けていた

The Navy's network kept track of the coup d'etat of the army's young officers in real time, from its inception to its suppression.

という、近年発見された資料を元に作られたものです。

This is based on a recently discovered document.

-----

私、父が、海軍兵学校の学生だった(在学中に終戦)ので、「陸軍 vs 海軍」については、かなり生々しい話を聞いています。

My father was a student at the Naval Academy (the war ended while he was still in school), so I have heard some very vivid stories about the Army vs. the Navy.

まあ、それはさておき。

Well, that's aside.

この番組では、「青年将校が占拠している国会議事堂を、戦艦からの遠方射撃(射程40km)で直接攻撃する」という計画があり、すでに東京湾に戦艦長門が東京湾に配備されていた、という話を聞いて ―― 正直、青さめました。

In this program, I heard that there was a plan to "directly attack the Diet building occupied by young officers with distant fire (40km range) from a battleship", and that the battleship Nagato had already been deployed in Tokyo Bay -- to be honest, I was pale.

この話、レーザを使った、ピンポイントのミサイル攻撃ができる時代の話ではりません。

This is not the era of pinpoint missile attacks using lasers.

―― 千代田区、全滅

"Chiyoda Ward, annihilation"

と、私も思いました。

I thought so too.

-----

それより、私が一番驚いたのは、反乱軍(に、自動的に組込まれてしまった)当時の陸軍兵 ―― 御歳103歳のインタビューの対応でした。

What surprised me the most was the interview with a 103 year old army soldier who was automatically included in the rebel army.

うそだろ? この理路整然としたしゃべり方、当時の詳細な記憶の証言、どう見たって103歳の御老人のものではない。

No way, right? The way he speaks so clearly, the details of his memories of that time, they don't seem to belong to a 103-year-old man.

「65歳」といっても、十分に通じる若々しさでした。

He looked youthful enough to pass for "65 years old".

―― 旧日本軍か? 陸軍か? それとも軍隊か? 軍隊に所属すれば、アンチエイジングの効果を得られるのか?

Is it "Old Japanese Army" ? Would I get the anti-aging benefits if I joined the military?

『自衛隊のシニア隊員募集』というものはないのか、と思ってしまった私でした。

I wondered if there was such a thing as "recruiting senior members of the Self-Defense Forces.

2021/03,江端さんの技術メモ

C++でJSONを扱わなければならなくなりました。

blog.livedoor.jp/tek_nishi/archives/10216517.html

に、

JSON for Modern C++ を紹介するよ!
ブログに書いた書いたと思い込んでてまったく触れてなかった...
このJSON読み書きライブラリは他のライブラリに依存しておらず、json.hppをインクルードするだけというお手軽さながら、JSONオブジェクトをめっちゃ気楽に扱えるようにしてくれます。

なん・・だと・・。インクルードするだけ・・ 採用決定!!

となりました。

で、早速、

$ git clone https://github.com/nlohmann/json.git

をして、

// g++ test_json.cpp -o test_json -I json/include/
// g++ test_json.cpp -o test_json -I json/include/

#include <stdio.h>
#include <string.h>
#include <nlohmann/json.hpp>  
#include <iostream>

int main(int argc, char **argv){

  using json = nlohmann::json;

  json j;

  j["pi"] = 3.141;
  j["happy"] = true;
  j["name"] = "Niels";
  j["nothing"] = nullptr;
  j["answer"]["everything"] = 42;

  j["list"] = { 1, 0, 2 };         // [1,0,2]
  j["object"] = { {"currency", "USD"}, {"value", 42.99} };  // {"currentcy": "USD", "value": 42.99} 

  std::cout << j << std::endl;  // cout

  return 0;
}

をした後、

>g++ test_json.cpp -o test_json -I c:/Users/Ebata/json/include  (git cloneが展開された場所にjson/includeというディレクトリができているので、そこをダイレクトに指示する)

を行い、./test_json を実施したら、

さくっと動きました。

では、次にこのJSONをUDP通信で飛ばしてみます。

ゲストOSがLinuxのDockerコンテナの中から、ホストOSにデータを放り出す為に使ったUDPプログラム

この↑のプログラムを前提とします

■C++送信プログラム (キモは、std::string jj = j.dump(); です)

// g++ test_send_json.cpp -o test_send_json -I C:/Users/Ebata/json/include/ -lwsock32 -lws2_32 (Windows版)

#include <stdio.h>
#include <string.h>
#include <nlohmann/json.hpp>  
#include <iostream>
#include "simple_udp_win.h" // https://wp.kobore.net/江端さんの技術メモ/post-1959/
//#include "simple_udp.h"

//simple_udp udp0("0.0.0.0",12345); // これはWindowでは動かない
//simple_udp udp0("192.168.0.8",12345); // これは使わない方がいい
simple_udp udp0("127.0.0.1",12345); // ホストOSのUDPの受信側

int main(int argc, char **argv){

  using json = nlohmann::json;

  json j;

  j["pi"] = 3.141;
  j["happy"] = true;
  j["name"] = "Niels";
  j["nothing"] = nullptr;
  j["answer"]["everything"] = 42;

  j["list"] = { 1, 0, 2 };         // [1,0,2]
  j["object"] = { {"currency", "USD"}, {"value", 42.99} };  // {"currentcy": "USD", "value": 42.99} 

  std::cout << j << std::endl;  // cout

  std::string jj = j.dump(); // これが重要(これを見つけるのに時間がかかった)

  udp0.udp_send(jj);

  return 0;
}

■C++受信プログラム (キモは、json j = json::parse(rdata); です)

// g++ test_recv_json.cpp -o test_recv_json -I C:/Users/Ebata/json/include/ -lwsock32 -lws2_32

#include <stdio.h>
#include <string.h>
#include <nlohmann/json.hpp>  
#include <iostream>
#include "simple_udp_win.h" // https://wp.kobore.net/江端さんの技術メモ/post-1959/
//#include "simple_udp.h"

//simple_udp udp0("0.0.0.0",12345);  // これはWindowsでは動かない
//simple_udp udp0("192.168.0.8",12345); // これは使わない方がいい
simple_udp udp0("127.0.0.1",12345); // これを使うのが無難


int main(int argc, char **argv){
  
  using json = nlohmann::json;

  json j;
  
  udp0.udp_bind();
  while (1){
    std::string rdata=udp0.udp_recv();

    j = json::parse(rdata); // これが重要(これを見つけるのに時間がかかった)
    // j = json::parse(rdata.c_str()); これでも動くようだが

    std::cout << j << std::endl;  // cout
   
  }
  return 0;
}

さて、そろそろ詰めに入ろうか。

■GOのJSONのUDP受信プログラム(上記の「C++送信プログラム」と対向で動くもの)

// test_recv_json.go
// go run test_recv_json.go
// golangによるjsonのudp受信"だけ"するプログラム

package main

import (
	"encoding/json"
	"fmt"
	"net"
)

type Message struct {  // とりあえず3つ
	Pi    float64 `json:"pi"`
	Happy bool    `json:"happy"`
	Name  string  `json:"name"`
}

func main() {
	addr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:12345")
	sock, _ := net.ListenUDP("udp", addr)

	var j Message

	i := 0
	for {
		i++
		buf := make([]byte, 1024)
		rlen, _, err := sock.ReadFromUDP(buf)
		if err != nil {
			fmt.Println(err)
		}
		str := string(buf[0:rlen])
		fmt.Println(str)

		// 受信したメッセージをJSON形式に格納する
		json.Unmarshal(buf[0:rlen], &j)

		// JSONに格納したデータを見る
		fmt.Println(j)

		fmt.Println(j.Pi)
		fmt.Println(j.Happy)
		fmt.Println(j.Name)

	}
}

■GOのJSONのUDP送信プログラム(上記の「C++受信プログラム」と対向で動くもの)

// test_send_json.go
// go run test_send_json.go
// golangによるjsonのudp送信"だけ"するプログラム

package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net"
)

type Message struct { // とりあえず3つ
	Pi    float64 `json:"pi"`
	Happy bool    `json:"happy"`
	Name  string  `json:"name"`
}

func main() {

	addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:12345")
	if err != nil {
		log.Fatal(err)
	}

	conn, _ := net.DialUDP("udp", nil, addr)

	if err != nil {
		log.Fatal(err)
	}

	var j Message
	j.Pi = 3.1415
	j.Happy = false
	j.Name = "Ebata"

	s, _ := json.Marshal(j)

	n, err := conn.Write(s) // WriteToUDPを使ってはならない
	fmt.Printf("dial send: bytes=%d to=%s\n", n, addr.String())

}

 

以上

2021/03,江端さんの忘備録

アルコールを止めてから、体調が良いです。

Since I stopped drinking alcohol, I feel better.

人間ドッグも、ここ2~3年は、基本的にオールグリーンになっております。

For the past two or three years, the human dog has basically been all green.

体重も「(軽く表示させる為の)体重計の乗り方の工夫」などもあって、目標体重 + 1kg以内を、なんとか維持し続けております。

I've managed to keep my weight within 1kg of my target weight, thanks in part to my ingenuity in using the scale (to make it display a lighter weight).

-----

問題は、在宅勤務下における「運動不足」です。

The problem is the "lack of exercise" under telecommuting.

iPadを持ち歩いて、読書をしながらの町内一周の歩行を心掛けていますが、日常の仕事が立て込んでくると、ついついサボってしまいます。

I carry my iPad with me and try to walk around the town while reading, but I tend to skip it when my daily work gets busy.

今日も『面倒だなー』と思いつつ、テレビで録画しておいた、

Today, I thought, 'This is too much trouble,' and I watched recorded TV program, whose title is

―― はたらく細胞 BLACK

"Working Cells BLACK"

を見ました。

-----

それでは、今から、町内を歩いてきます。

Okay, I'm going to walk around the town now.

2021/03,江端さんの忘備録

こちらに、2015年の夏、鹿児島県の県知事が『女子高生は、三角関数より花や草の名前を教えた方がいい』と発言して大問題に発展した話題を書きました。

Here, I wrote about a story that developed into a big problem in the summer of 2015 when the prefectural governor of Kagoshima Prefecture said, 'High school girls should be taught the names of flowers and grasses rather than trigonometric functions'.

また、

In addition,

こちらの「リカレント教育【前編】 三角関数不要論と個性の壊し方」というコラムでは、

In this column, "Recurrent Education [Part 1]: Trigonometric Functions Unnecessary and How to Destroy Individuality," I raised the following issues.

■古典は必要か → 使う場面ないじゃんか?

Do we need the 'classics' → Why don't we use them?

■歴史は必要か → 昔の話を持ちだしてどうする?

Do we need 'history' → When do we use the story?

■英語は必要か → (江端試算では)4%の日本人しか使っていないぞ?

Do we need 'English' → (Ebata's estimate) only 4% of Japanese use it?

■現国は必要か → 文庫本が読める程度の漢字を知っていればいいんじゃないの?

Do we need to study 'Japanese'? → It's enough if we know enough kanji to read a paperback book.

■体育は必要か → 日常生活で、走ったり跳んだり泳いだりする必要性はあるか?

Do we need 'physical' → Do we need to run, jump, or swim in daily life?

■理科は必要か → リトマス試験紙が何色になるかが、そんなに重要か?

Do we need 'science' → Is it really that important what color the litmus test paper turns?

と問いつめれば、「畢竟(ひっきょう)、全ての学校教育は否定される」という結論に至るはずだ、という論を展開しました。

I argued that if we look at it this way, wewill come to the conclusion that "in the end, all schooling will be rejected.

-----

で、現在、ミャンマーで発生している「軍部によるクーデター事件」について語る時に、

So, when we talk about the "military coup d'etat incident" that is currently occurring in Myanmar.

『ああ、あれは、ざっくり言って、"2.26事件"と同じだよ』

"Yeah, that's roughly the same as the 2.26 incident"

と言った時に、

When I replied that way,

「ああ、なるほどね」

"Oh, I see"

と答える国民が、多数派の国になるか、

Will the people who answer this way become the majority? or,

「はあ? 何それ?」

"What? What's that?"

と答える国民が、多数派の国になるか、

Will the people who answer this way become the majority?

の、違いなのだろう、と思っています。

At the end of the day, this is what makes the difference, I believe.

-----

『国民の知的レベルは低いままにしておく方が統治しやすい』といったのは、毛沢東です。

It was Mao Zedong who said, "It is easier to rule if the intellectual level of the people is kept low.

私は、『国民の知的レベルを低いままにしておくと、感染症で国が滅びる』と思っています。

I believe that 'if the intellectual level of the people is kept low, infectious diseases will destroy the country.

-----

「毛沢東?はあ?それ誰?」と答える国民が・・・(以下省略)。

"Mao Zedong? Huh? Who is that? The people answered....(Omitted below)