2022/04,江端さんの技術メモ

異動先の部署でのキックオフの事務局長になったのは良いのですが、異動先の部署では、Teamsを使い倒しているので、四苦八苦しています。

何とか前任者と同じ「かっこいい」フォームを使って、チームへの投稿をしたいのですが、やりかたが分からくて、同僚に泣きついています。

で、先程教えて貰ったページを忘れない内に記載しておきます。

Teamsでアナウンスを投稿する方法

 

2022/04,江端さんの忘備録

最近、コラムで公開したメールアドレスに、色々な親切なメールが届いています。

Recently, I have received various kind emails to the email address I published in my column.

■mercari <no-reply@mercari.jp>

- mercari <no-reply@mercari.jp>

メルカリアカウントが第三者に悪用されたことが検出され,アカウントが制限されました。

We have detected that your Mercurial Account has been abused by a third party and your account has been restricted.

―― メルカリは、使ってない

"I don't use Mercury"

■AEON CARD <userid@aeon.co.jp>

- AEON CARD <userid@aeon.co.jp>

このたび、ご本人様のご利用かどうかを確認させていただきたいお取引がありましたので、誠に勝手ながら、カードのご利用を一部制限させていただき、ご連絡させていただきました。

We regret to inform you that we have restricted the use of some of your cards due to a transaction for which we would like to confirm whether the transaction was made by you or not.

―― イオンカード持っていない

"I don't have an AEON card"

■jcbカード <admin@cjuuwra.cn>

- jcb card <admin@cjuuwra.cn>

いつもJCBカードをご利用いただきありがとうございます。

Thank you for using JCB Card.

―― JCBカード使っていない

"I don't use a JCB card"

■J:COM <admin@brajyct.cn>

- J:COM <admin@brajyct.cn>

お支払い期日を過ぎています。

The payment due date has passed.

―― 江端家の通信インフラは、JCOMじゃない

"The Ebata family's telecommunications infrastructure is not JCOM"

■モバイルSuica <admin@pitvxsr.cn>

- mobile Suica <admin@pitvxsr.cn>

与信失敗により、モバイルsuicaの更新手続きが完了できませんでした。

Due to credit failure, the Mobile Suica renewal process could not be completed.

―― 私は、モバイルSUICAを使っていない

"I am not using mobile SUICA"

-----

わざわざ、

Purposely,

■中国(.cnドメイン)から、

- From China (.cn domain)

■私が所持も使用もしていないサービスについて、

- For services that I neither possess nor use.

■丁寧にご警告を頂き

- for your courteous warning.

ありがたいこととは存じますが、

I thank your cooperation, however,

『大変、うっとうしい』

"They are very annoying"

ので、昨日、コラムで公開していたメールアドレスを、全削除しました。

So, yesterday, I deleted all the e-mail addresses that I had published in my column.

後で復活させるかもしれませんが、一月くらいは放って置こうと思います。

I may revive it later, but I will leave it alone for a month or so.

送信側にエラーメールが届けば、再送はしなくなるでしょう。

If the error mail is delivered to the sender, it will not be resent.

-----

個人でドメイン名(私の場合"kobore.net")を取得して、メールアドレスをいくつも追加、削除できる環境を持っていると、なかなか便利です。

It is quite convenient to have a personal domain name (in my case "kobore.net") and an environment where you can add and delete a number of email addresses.

私、個人のメールアドレスも、時々変更しています。

I also change my personal email address from time to time.

意味不明なメールを送ってくる送信者を、スマートに振り切る為です。

This is to smartly shake off senders who send meaningless e-mails.

私が返事をしなくても、mailer-daemonさんが、"User unknown"と返事してくれて、後腐れもありません。

Even if I don't respond, mailer-daemon responds with "User unknown" and there is no need for me to answer.

これまで、色々なメールを受けとりましたが、『神様の声が聞こえる』ような文面を送ってくる人のメールは、私でも怖いです。

I have received many different emails, but even I am afraid of emails from people who send me text messages that sound like 'I can hear God's voice'.

-----

そういえば、昔、『特定の人物に限って、"mailer-daemon"さんからの返事に見せかける、自動メール応答システム』を作ったことを、思い出しました。

I remember that I once created an automatic mail response system that made it look like a reply from "mailer-daemon" only to a specific person.

2022/04,江端さんの忘備録

私、今ですら、こんな、ですが、若い頃は、「リア充」に努めていたようです。

I, even now, like this, but when I was younger, I was aiming to be "sociable" and seemed to strive to be a ""sociable".

―― と、以前の日記を見ながら、思いました。方向性はさておき。

with looking at my previous diary, I thought that. Directions aside.

ですが、それでも、中学生の頃から変わらないこともありました。

But still, some things had not changed since junior high school.

「孤食」 + 「読書」、すなわち『読食』です。

It is "solitary eating" + "reading," is equal to "lunch with reading".

-----

小学生時代の給食を終えて、中学生の弁当になってからは、『読書をしながらの食事』というのは、私にとっては最上の時間の一つでした。

After school lunches in elementary school ended and lunches for junior high school students began, 'lunch box with reading' was one of the finest times for me.

食事と読書を同時に楽しめる ―― なんと贅沢な時間なんだろう

Enjoy eating and reading at the same time -- what a luxury!

と思っていました。

I thought so.

学校に週休2日制度が導入される前は、土曜日は半日で授業が終わりました。

Before the school week was introduced, classes on Saturdays lasted half a day.

私は、人生通じて、ずっと「かぎっ子」(帰宅時に他の家族が自宅におらず、自ら家の鍵を持参している子供)でした。

I have always been a " latchkey kid" (a child who has no other family at home when he/she returns home and brings his/her own key to the house).

帰宅したら、自転車で近くの市場に、コロッケ2個と、鶏肉100グラムを購入しに行きました。

When I got home, I cycled to a nearby market to buy two croquettes and 100 grams of chicken.

そして、一人前の「味噌煮込みうどん」を作り、井上靖先生の本を読む時間は

And time to make "Miso Stewed Udon" for one person and read a book by Yasushi Inoue, was,

―― 至高のひとときでした。

"a supreme time".

『孤食が恥しい』という考え方は、当時はなかったような気がします ―― いや、あるいは私が気がつなかっただけかもしれません。

I don't think the idea of 'solitary eating is shameful' existed back then -- or maybe I just didn't realize it.

私が『男子生徒』であったことも関係しているのかもしれません。

Maybe it had something to do with the fact that I was a 'boy student'.

-----

現在も、学校現場では、新型コロナ対策として「黙食」が続けられいるそうですが、それは理に叶っていると思います。

Even today, I hear that "silent meals" are still being continued in schools as a countermeasure against the new coronas, which makes sense.

私のソース(情報源)からも『子どもが学校で感染を拾って、それを家族に広めている』という話を聞いております。

I have also heard from my sources that "children are picking up the infection at school and spreading it to their families"

子ども(小学生、中学生)のいる家族では、この現実が、諦観(ていかん)とともに、受け入れられているようです。

Families with children (elementary and junior high school students) seem to accept this reality with resignation.

それでも、「感染の確率」を下げるための「黙食」には、意味があります。

Still, a "silent meal" to reduce the "probability of infection" makes sense.

家族の為だけでなく、子どもの無症状感染による後遺症(ブレインフォグ等)にも配慮しておくことにも、意義もあると思います。

It is also significant not only for the family, but also to take into account the aftereffects of asymptomatic infection (brain fog, etc.) in the child.

-----

で、私が提案するのは、もちろん、

And I would suggest, of course, that

「『読食』のススメ」

"lunch with reading"

です。

is.

今、教育現場では、すでに、一人一台のタブレット端末が導入が、完了しつつあります。

In the field of education, one tablet per student has already been introduced.

「孤食」ができて、「読書」もできて、「IT(Information Tech.) x OT(Operation Tech.)」が実践できて、その上「黙食」が実現されるという、素晴しい方法です。

It is a wonderful way to be able to eat alone, to read, to practice "IT (Information Tech.) x OT (Operation Tech.)," and on top of that, to realize "silent meal".

「iPadで、kindleを立ち上げて、太宰治や井上靖を読みながら、一人メシを食う」 ―― それはもう、至福の昼休み、"パラダイスランチ"じゃないですか。

Eating a meal alone while reading Osamu Dazai or Yasushi Inoue on your iPad with kindle app." - that is a blissful lunch break, a "paradise lunch".

―― って思うのは、私だけですか?

Am I the only one who thinks so?

2022/04,江端さんの忘備録

「なんで、江端は、未だにコーディングなんかしているだ?」と思われている方は多いと思います。

"Why is Ebata still coding?" I think there are many people who think that.

ここ数年、私は、プログラムを外注の方に作って頂いています。

For the past few years, I have had the program created by an outsourcer.

ソースコードも含めて、全品納品して頂いているのですが、

I've had all the items delivered to me, including the source code, however, I came to realize

―― それらのソースコードを、全く再利用(改修)できない

"I have not been able to reuse (modify) their source code at all"

と、思い知ってきたからです。

-----

はっきりと言いますが、『他人の書いたプログラム』は、はっきり言って「呪文」です。

To be clear, "programs written by others" are, to put it bluntly, "spellbinding.

自分の知らないプログラム言語は言うに及ばず、自分が熟知しているプログラム言語であっても、

Not only programming languages that I am not familiar with, but also even programming languages that I am familiar with, are not

- ライブラリが違う

- Libraries are different,

- プログラムの開発環境が違う

- Program development environments are different,

- プログラム言語のバージョン(仕様)が違う

- Versions (specifications) of the programming language are differnt,

ことがあり、決定的なことは、

In, addition, the crucial thing is that

- コーディングのアプローチ(思想)が違う

- Coding approaches (philosophy) are different.

という点が、絶望的に「呪文」なのです。

This point is hopelessly "spellbinding".

以前、私の師匠(エルカン)が、

Once, my mentor, "Erukan" said,

―― 他人のプログラムを読むことは、他人の頭を覗き込むような行為で、不快で嘔吐すら覚える

"Reading someone else's program is like looking into someone else's head. it's offensive and even vomit-inducing"

と言っていましたが、これは、けだし名言と言えます。

I think that this is a great quote.

-----

苦痛を伴わないプログラミングとは、スクラッチから自分1人で行うプログラミングです。

Pain-free programming is programming done by myself alone from scratch.

ただ、これは、昨今のデジタルサービスのスピードを考えれば、このようなプログラミングは『贅沢』です。

However, this is a 'luxury' of such programming, given the speed of digital services these days.

また、『非生産的』であることも、認めざるを得ません。

I also have to admit that it is 'unproductive'.

そのようなプログラミングが、贅沢で非生産的なことをやっているのであれば、私は、どこからリソースを削ってくればいいか?

If the programming is "luxury" and "unproductive", where can I get resources from?

そりゃ、『週末』と『睡眠時間』しか、ないでしょう。

The only thing I can use is "weekends" and "sleeping time".

-----

昔は、『週末』と『睡眠時間』を削ってプログラミングしていることを、普通にしゃべることができました。

In the past, I could usually talk about the programming on the 'weekends' and on less sleep.

最近は、このようなことを職場等で公言することは、『コンプライアンス的に問題がある』ということになっているようです。

These days, it seems to be a 'compliance issue' to publicly state such a thing in the workplace, etc.

そして、私も、この意見には賛成です。

And I agree with this opinion.

この手の話は、つまるところ『パワハラ』ですし、こういう自慢話は、聞いている側もムカつきます。

This kind of talk is, after all, "power harassment," and this kind of bragging is infuriating to listen to.

だから、これからは、『自分がやりたい仕事(試したいプログラム等)は、アンダー・ザ・テーブルで仕込む』ことが、普通になっていくと思います。

So, from now on, I think it will become the norm that 'the work I want to do (programs I want to try, etc.) will be prepared "under the table".

-----

ところで、この「アンダー・ザ・テーブル」は、プログラミングに限定されません。これは仕事一般に通じる話です。

By the way, this "under the table" is not limited to programming. This goes for work in general.

私が常に言っていることですが

I've always said.

「あなたがやりたい仕事は、公にせずに1人でやること」

"The work you want to do, do it alone, without making it public"

「そして公にできるチャンスを、虎視眈々と狙い続けること」

"Keep my eyes open for any opportunity to make it public"

が肝要です。

These are important.

自分のアイデアを、未完成のまま、不適当なタイミングで組織に開示すると『必ず潰されます』 ―― ロジカルに。

If you disclose your ideas to the organization in an unfinished state and at an inappropriate time, 'your idea will surely be crushed' -- logistically.

これは「組織の公理」と言っても過言ではありません。

It is no exaggeration to say that this is an "axiom of organization".

例えば、私には、ある自分のアイデアを3年間隠し続け、2年間かけて目立たないように少しづつ開示し、ようやく組織内で認識して貰えるに至ったサービス/製品があります。

For example, I have a service/product that I kept my idea hidden for three years, and after two years of discreetly disclosing it little by little, I finally got it to be recognized within the organization.

閑話休題

Now let's return to the main subject

-----

「なんで、江端は、未だにコーディングなんかしているだ?」に関しては、色々なことが言えますが、一言で言えば、

Why is Ebata still coding?" A lot can be said about this, but in a nutshell

『ラクだから』

"Because, it is easy"

です。

2022/04,江端さんの忘備録

(その1)

(Part 1)

米国を含めた多国籍軍は、1991年に、湾岸戦争を開戦しました。

Multinational forces, including the United States, launched the Gulf War in 1991.

1990年、イラクのフセイン政権は、石油を大量に保有しているクウェートに対して攻撃を仕掛け、国連決議によって多国籍軍が、イラクに攻撃を開始しました。

In 1990, the Hussein regime in Iraq launched an attack against Kuwait, which had large oil reserves. In response, a multinational force, under a United Nations resolution, launched an attack on Iraq.

当時、戦争に忌避的だった米国の世論は、「ナイラ証言」によって、一気に開戦へと機運が高まりました。

Public opinion in the U.S., which at the time was averse to war, was quickly galvanized by the "Nayirah testimony" to start the war.

「ナイラ証言」とは、イラクによるクウェート侵攻の後、「ナイラ」を名乗る少女が行った証言で、その内容は過激なものでした(YouTubeに飛びます)。

The "Nayirah testimony" was a radical testimony given by a young girl who identified herself as "Nayirah" after the Iraqi invasion of Kuwait.

『イラク軍兵士がクウェートの病院から保育器に入った新生児を取り出して放置し、死に至らしめた』と、その経緯を涙ながらに語っていました(何度もニュースで流れたので、よく覚えています)。

'Iraqi soldiers removed a newborn from a Kuwaiti hospital in an incubator and left it to die,' he said tearfully (I remember it well because it was on the news many times).

現在、これが『偽証』であったこと、さらに、そのナイラなる少女が、当時クウェート駐米大使であったサウード・アン=ナーセル・アッ=サバーハの娘だった事実が明らかになっています。

It is now known that this was "perjury" and that the girl, Nayirah, was the daughter of Saud an-Nasser a-Sabah, then Kuwait's ambassador to the United States.

―― (米国民を含めて)世界は、その少女の偽証に見事に騙されて、戦争に突き進んでいったのです。

"The world (including the American people) was successfully deceived by the girl's perjury, and pushed forward to the war"

-----

(その2)

(Part 2)

米国と英国は、2003年に、イラク戦争を開戦しました。

In 2003, the United States and the United Kingdom launched a war in Iraq.

ブッシュ大統領は、開戦前後の演説で、戦争理由以下を挙げました。

President Bush cited the following reasons for the war, in his speeches before and after the war.

(1)生物・化学兵器等、大量破壊兵器を保有し続け、その事実を否定し、国連の武器査察団に全面的な協力を行わなかった

(1) Continued to possess weapons of mass destruction, including biological and chemical weapons, denied the existence of such weapons, and failed to cooperate fully with UN weapons inspectors

(2)イラクの一般市民をサッダーム・フセイン大統領の圧政から解放する

(2) Free Iraqi civilians from the oppressive regime of President Saddam Hussein.

ただし、国連安保理のなかでも、フランス、ドイツ、ロシア、中国らは軍事介入に反対しました。

However, even within the UN Security Council, France, Germany, Russia, and China opposed military intervention.

常任理事国の拒否権によって、国連軍は発動しませんでした。

Due to the veto power of the permanent members of the Council, the UN force was not activated.

米国、英国などは有志連合を組み、3月20日、空爆という先制攻撃に踏み切りました。

The United States, the United Kingdom, and other countries formed a coalition of the willing and launched a pre-emptive strike on March 20, bombing the country.

で、

As a result,

―― 生物・化学兵器等、大量破壊兵器を保有していたという証拠は、一つも見つかりませんでした。

"Not a single piece of evidence was found that Iraq possessed weapons of mass destruction, including biological or chemical weapons"

それを理由として、英国は当時のブレア首相が退陣に追い込まれました(ブッシュ大統領は退陣していません)

Because of this, then British Prime Minister Blair was forced to step down (President Bush did not step down).

-----

(その他)

(Other)

―― 米国は、1945年に、非戦闘員である広島市民と長崎市民の頭上に、摂氏3000度(太陽の表面温度の半分)の核爆弾を炸裂させました。

-- In 1945, the United States detonated a nuclear bomb at 3,000 degrees Celsius (half the surface temperature of the sun) over the heads of non-combatant citizens of Hiroshima and Nagasaki.

これが、連合国軍の分裂(冷戦)の始まりであり、満州、北方領土に侵攻中のソ連に対する、核兵器保有国としてのデモンストレーションであったことは、(我が国では)定説です(米国政府の公式見解とは異なる)。

It is a common belief (in Japan) that this was the beginning of the division of the Allied Forces (Cold War) and a demonstration by the nuclear weapon states against the Soviet Union, which was invading Manchuria and the Northern Territories (contrary to the official view of the US government).

-----

私は、ロシアのウクライナ侵攻、特に、市民への虐殺を、絶対的な意味で許せません。

I cannot tolerate, in an absolute sense, Russia's invasion of Ukraine, especially its massacres of its own citizens.

また、戦争当事者でない国の国民として、現時点で日本国内の報道は、概ね事実だろう、と考えています。

Also, as a citizen of a country that is not a party to the war, I believe that the reports in Japan at this time are probably generally true.

しかし、私が、それを大声で叫び出さない(コラムの執筆、寄稿等)で、個人的な支援に徹している理由は、

But the reason I don't shout it out loud (writing columns, contributing, etc.) and stick to personal support is

―― 世界各国の政府発表(プロパガンダ)に騙され続けてきた

"I have been continuously deceived by government announcements (propaganda) from all over the world"

という、過去の苦い思い出があるからです。

I have bitter memories of the past like the above.

-----

「政府がいつもウソをつく」とは思っていませんが、戦争(国防)に関しては、どの政府も高い頻度でウソをつきます。

I don't believe that "governments lie all the time," but when it comes to war (national defense), every government lies with high frequency.

そして、私も、結構、チョロい感じで騙されてきました。

And I, too, have been cheated, quite easily.

ちなみに、「個人的な支援」については、今はお話できません。

By the way, I cannot talk about "personal support" at this time.

2022/04,江端さんの忘備録

「野心的な目的をもつプロジェクトチームを統率してきたマネージャと」と「目の前のデータを、望むような形で計算することができるプログラマー」

"A manager who has led a project team with ambitious objectives" and "a programmer who can compute the data in front of him/her in any way they wants."

どちらに市場価値があり、どちらの市場規模が大きいのか?

Which has more market value and which has a larger market size?

私は、これまで、ずっと考え続けてきました。

I have been thinking about this for a long time.

-----

内館牧子さんの小説『終わった人』は、私の世代における最大級の『ホラー小説』です。

Makiko Uchidate's novel, "The Finished Man," is one of the greatest "horror novels" of my generation.

―― 日本最高学府の学歴や、一流会社のハイキャリアが、定年後の再就職の最大の障害になる

"Academic background from Japan's highest academic institution and a high career at a prestigious company become the biggest obstacles to re-entering the workforce after retirement"

という話が、登場します。

The story appears in the book.

この小説の主人公だって、『どんな仕事でもやります』と言っているのに、中小企業の会社の社長は、ことごとく採用を躊躇します。

Even the protagonist of this novel says, 'I'll do any job,' but the president of the small business firm hesitates to hire him at every turn.

その気持ち、とても理解できます。

I understand their feeling very well.

だって、社長としては、会社の経営に口を出されたら、嫌ですよね。

Even they would not like to be told how to run their companies.

しかし、再就職を希望するシニアは、会社の経営に口を出すつもりはなく、言われたことをやると思います。

However, I believe that seniors who want to be rehired will do what they are told, with no intention of meddling in the management of the company.

しかし、現場が忖度をしてしまうのです。

However, the people on the field make the conjecture.

これは『逆差別』―― ではなくて、『エリート差別』?

Is this "reverse discrimination" or "elite discrimination"?

-----

私が中小企業の社長であれば、どんなシニアが欲しいか? と考えると、

If I were the president of a small business, what kind of senior would I want?

■新人のように謙虚で、元気で、ちょっと弾けているところもあるけど、

- humble, energetic, and even a little bouncy in some ways, like a rookie.

■注意すれば直ぐに方向転換をし、あまり目立たずに、金に繋がる成果を上げても、それを吹聴しないで、淡々として、

- Change direction quickly if someone pay attention to them, and if achieve something that leads to money without being too obvious, don't blow it out of the water, just go about it nonchalantly, and don't even try to get you to pay attention.

■分からないことがあれば黙って勉強し、それでも分からなければ、若者に素直に頭を下げて教えを請うことができて、

- Study it quietly, and if don't understand, honestly bow down to the young man and ask him to help.

■メンタルでもフィジカルでも、ロバストな

- Robust, both mental and physical.

そんな「シニア」なら、欲しいと思います。

I would want such "seniors".

これからは、新人もシニアも『即戦力』で計られる時代であり、私たちシニアに求められているロールモデルは、

In the future, both newcomers and seniors will be measured by their "readiness to work," and we seniors are expected to be role models, like

『清濁併せ呑むことのできる、老獪な新人』

Newcomers who are required to be broadminded enough to associate with people of all sorts for the sake of working out a compromise.

だと思うのです。

I think.

-----

「野心的な目的をもつプロジェクトチームを統率してきたマネージャと」と「目の前のデータを、望むような形で計算することができるプログラマー」

"A manager who has led a project team with ambitious objectives" and "a programmer who can compute the data in front of him/her in any way they wants."

どちらに市場価値があり、どちらの市場規模が大きいのか?

Which has more market value and which has a larger market size?

市場価値については、私は分かりません。

I do not know about market value.

しかし、市場規模が大きいのは、『命じられた業務を、サクっとやりとげるシニア』だと思うのです。

However, I think the largest market is for "seniors who can quickly complete tasks that are assigned to them.

2022/04,江端さんの技術メモ

https://teratail.com/questions/2m8dsx1urnslib

一応動いているソースコード

// main.go

package main

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"net/url"

	"github.com/gorilla/websocket"
)

var upgrader = websocket.Upgrader{}

type GetLoc struct {
	ID    int     `json:"id"`
	Lat   float64 `json:"lat"`
	Lng   float64 `json:"lng"`
	TYPE  string  `json:"type"` // "PERSON","BUS","CONTROL
	POPUP int     `json:"popup"`
	//Address string  `json:"address"`
}

func echo2(w http.ResponseWriter, r *http.Request) {
	conn2, err := upgrader.Upgrade(w, r, nil) //conn2でwebsocketを作成
	if err != nil {
		log.Println("websocket connection err:", err)
		return
	}
	defer conn2.Close()

	for {
		gl2 := new(GetLoc)
		err := conn2.ReadJSON(&gl2)
		if err != nil {
			log.Println("ReadJSON:", err)
			break
		}
		fmt.Println("echo2:", gl2)
		//time.Sleep(time.Second * 10)
	}

}

var addr = flag.String("addr", "0.0.0.0:5000", "http service address") // テスト

func dummyClient() {
	_ = websocket.Upgrader{} // use default options

	flag.Parse()
	log.SetFlags(0)
	u := url.URL{Scheme: "ws", Host: *addr, Path: "/echo2"}
	log.Printf("connecting to %s", u.String())

	c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
	if err != nil {
		log.Fatal("dial:", err)
	}
	defer c.Close()

	for {
		gl := new(GetLoc)

		gl.ID = 101
		gl.Lat = 181.0
		gl.Lng = 181.0
		gl.TYPE = "BUS"
		gl.POPUP = 101

		err := c.WriteJSON(gl)
		if err != nil {
			log.Println("write:", err)
			break
		}
	}

}

func main() {
	http.Handle("/", http.FileServer(http.Dir(".")))

	http.HandleFunc("/echo2", echo2)
	//go dummyClient()

	log.Println("server starting...", "http://localhost:5000")
	log.Fatal(http.ListenAndServe("localhost:5000", nil))
}
// index.html

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>

</head>
<body>
    <form>
        <button id="open">open</button>
        <button id="send">send</button>
        <button id="close">close</button>
    </form>

    <script>  

        var ws;

        // websocketのオープン(この段階で接続完了)
        ws = new WebSocket('ws://localhost:5000/echo2')  // ユーザ登録画面

        // websocketのオープンイベントが発生したら
        ws.onopen = function(evt) {
            // 何もしない
            print("OPEN");
            console.log("OPEN");
            return false;
        }

        // "send"ボタンをクリックしたら
        document.getElementById("send").onclick = function(evt) {
            if (!ws) {
                return false;
            }
 
            var obj = {id:101,lat:181.0, lng:181.0,type:"BUS", popup:101}
            var json_obj = JSON.stringify(obj);            
            ws.send(json_obj);
            return false;
         };
        
        // "close"ボタンをクリックしたら
        document.getElementById("close").onclick = function(evt) {
            if (!ws) {
                return false;
            }
            // websocketを閉じる
                
            ws.close();
            console.log("CLOSE")
            return false;
        };
   
    </script>
</body>
</html>

2022/04,江端さんの技術メモ

leafletの地図上に、マウスでクリックするとマーカーが出てきて、マーカーをクリックするとマーカーが消える、というJavaScript

var map = L.map("map", {
        attributionControl: false,
        zoomControl: false
        }).setView(new L.LatLng(35.654543, 139.795534), 18);
        // }).setView(new L.LatLng(35.598563, 139.475528), 18); 広袴

        L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
         detectRetina: true,
         maxNativeZoom: 18
        }).addTo(map);

        var leafletView = new PruneClusterForLeaflet(1,1);  // (120,20)がデフォルト

        //地図のclickイベントでonMapClick関数を呼び出し
        map.on('click', onMapClick)
        
        function onMapClick(e) {
            //地図のclickイベント呼び出される
            //クリック地点の座標にマーカーを追加、マーカーのclickイベントでonMarkerClick関数を呼び出し
            var mk = L.marker(e.latlng).on('click', onMarkerClick).addTo(map);
            console.log("click:",e.latlng)
        }

        function onMarkerClick(e) {
            //マーカーのclickイベント呼び出される
            //クリックされたマーカーを地図のレイヤから削除する
            map.removeLayer(e.target);
            console.log("remove:",e.target)
        }