2016,江端さんの忘備録

(昨日の続きです)

(Continuation from yesterday)

私は、本を個人で購入する意義は、

I think that the significance of purchasing books personally

「本に自分のコメントを書き込むことができる(落書き、図表、他の資料の貼り付けなども含む)こと」

"I can write down my comments(graffiti, graphs, tables, other materials) in the book.

にあると思っています。

私の頭は、「本を読みながら手を動かすことで、要点を整理する」ようになっていますし、「ボロボロにするまで、何度も読み熟すことで、知識が定着する」ようになっています。

My brain is probably used to understanding the book summary by working my hands or fingers or shading the book by reading over and again to solidify my knowledge.

図書館で借りてきた本では、そのようなことが行えないのです(当たり前だ)。

The above acts are strictly prohibited for any book in the library(It's natural)

-----

という訳で、最近の私の本の購入ステップは、以下のようになっています。

So, now, the steps of my book purchase are as follows.

(Step 1)図書館の本を読む

(Step 1) I read a book in a public library.

(Step 2)本に書き込みたいくらいに、その本が気に入る

(Step 2)The book sits in my mind. I want to get the urge to write my comments down,

(Step 3)Amazonで、その本を購入する

(Step 3)I purchase the book from the Amazon site.

まあ、これで、書籍代金を1/10くらいにはできていると思います。

I think that the procedures save money in the tenth-value layer.

-----

ところが、最近、

But in the present, I am reading a book, which

■Amazonで入手できず、

- is impossible to purchase from the Amazon site,

■図書館の書架にも出ておらず(1970年くらいに発行された本)、

- is not opened on the book rack in the library (published in the 1970s),

■司書さんに倉庫から出して貰う必要のある

- is needed to ask the librarian to pick up from the storage of the library,

そういう本を読んでいるのですが、これが、本当に良い本だったりするんです

and it is a great book.

―― で、まあ、なんというか「困っている」のです。

So, let me say I am in trouble now.

私一人の為に、その本を1冊だけ再版して貰うことは、絶望的に難しい(というか無理にきまっている)と思いますしね。

I am afraid that it is desperately difficult to republish the only one book for me( Absolutely impossible)

-----

私は、電源や光源や落下や水没の心配をしなくて良く、書き込みが可能な、紙の本が好きです。

I like a writable paper book that does not need power or light, falling or submersion under water.

電子ブックの方がコストパフォーマンスが良いのは判っていますが、「1冊再版」というビジネスが本格的に始まってくれたら、本当に嬉しいと思っています。

I know that e-books suit every aspect: cost, usability, etc. However, the new business, "only one book published," will make me happy.

未分類

横浜市統計書によると2022年度の1日平均乗降人員18,339人(乗車人員:9,255人、降車人員:9,084人)である[3]。2020年度の1日平均乗降人員は16,535人であり[4]、京急線全72駅中30位。1988年をピークに乗降客数は減少し続けている。

https://ja.wikipedia.org/wiki/%E4%BA%AC%E6%80%A5%E5%AF%8C%E5%B2%A1%E9%A7%85

乗り場 系統 経由 行先 備考
富1 富岡西四丁目 横浜氷取沢高校 平日は朝夜のみ
富2 横浜氷取沢高校 能見台車庫前
富3 氷取沢 金沢文庫駅西口
富5 富岡西四丁目 富岡9期ニュータウン 朝夕のみ
富6 富岡西循環 京急富岡駅 日中のみ

 

Photo

未分類

スプリングコードの終端が切れてしまった場合

スプリングコード 最長90cm カラビナ付 [色指定不可] (100円ショップ 100円均一 100均一 100均)の通販はau PAY マーケット  - 100円雑貨&日用品卸−BABABA | au PAY マーケット-通販サイト

結束バンドで閉じることができます。

2024,江端さんの忘備録

今日、『ブックオフに行ってくる』という嫁さんに、『中古の金属バットを、買ってきて』と頼みました。

Today, I asked my wife, who said, "I'm going to a Book-Off," to buy me a used metal bat.

「野球」に興味を持った訳ではなく(私に限って、そんな訳があるはずがない)、不法侵入者撃退用にです。

Not because I'm interested in "baseball" (how could I be?), but to repel trespassers.

我が家の玄関の傘立には、義父から貰ったというゴルフクラブが置いてあるのですが、以前から『これは反撃能力が弱い』と思っていました。

There is a golf club in the umbrella stand at the entrance of our house that was given to me by my father-in-law, and I have always thought, 'This has a weak ability to fight back.

Amazonで購入しようかとも思ったのですが、『人を殴打するためのバット』に、定価を支払うのもなんだなぁ、と思いまして。

I thought about buying it on Amazon, but then I thought, why pay the list price for a "bat for beating people up"?

-----

『江端、一体、何考えているんだ?』と思われるかもしれませんが、この理由については、すでに以前に記載した通りです。

'Ebata, what the hell are you thinking?' You may be thinking, "What in the world is Ebata thinking?" but the reason for this has already been described.

という訳で ―― この平和な時代にあっても、「武装」という概念を持ち続けているシニアが存在していることを、覚えておいて下さいね。

これ以外にも、いくつかの撃退手段を準備しているのですが ―― ちょっと公にはできない内容なので、割愛させて頂きます。

In addition, I am preparing several other means of fighting back. However, I'll spare you the details. Because it is against public order and morals.

2024,江端さんの忘備録

『首相が妙な指導力を発揮すると、救助活動に関わる人や、被災している方に、どえらい迷惑をかけることになる』

"If the prime minister tries to show strange leadership, it will cause a lot of trouble for those involved in the rescue efforts and the people affected by the disaster."

ということは、東日本大震災の際、当時の首相が見事に証明してくれました。

The then Prime Minister beautifully proved this during the Great East Japan Earthquake.

(「総理を落ち着かせてくれ」で検索すると記事が出てきます)

(Search for "calm the PM" to find the article)

----

組織のトップは、

The head of the organization is,

(1)どんなにもどかしくても、前線に出でこないで、後方で災害全体を把握し続けなければならない

(1) No matter how frustrating it may be, they must not come out to the front lines but stay in the rear to keep track of the entire disaster.

そして、

and,

(2)我慢して、現場に判断を委ねなければならない

(2) They must be patient and let the field decide.

という姿勢が重要であることを示してくれた、素晴しい反面教師となりました。

The prime minister was a great role model at the time, showing us the importance of such an attitude.

----

そういう意味では、私は、今回の災害に対する現首相のスタンスを、それなりに評価しているんです。

In that sense, I appreciate the Prime Minister's stance on this disaster.

これを『指導力がない』と見るかどうかは、人それぞれかと思います。

I guess it depends on whether you see this as a 'lack of leadership' or not.

しかし、下っ端の管理職として、現場仕事を続けてきた私に言わせれれば、「土壇場で割り込み」を出してくる上司というのは、本当に迷惑な存在です。

However, as a lower-level manager who has continued to work in the field, I can say that bosses who offer "last-minute interruptions" are a real nuisance.

上司は、その職務にかかわるチェックをしなければなりませんが、最終フェーズで現場に乗りこまれたり、ましてや「提案」なんぞされると、本当に困るのです。

Supervisors have to check on their duties. However, I don't want them to join in the project's final phase, much less make "suggestions."

----

「口を出さないシニア」というのは、それだけで十分に価値があるものです。

A "senior who doesn't talk is well worth it."

日本語に不自由な外国人の居住者 ―― つまり"言語"の問題です。

 

2019,江端さんの忘備録

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

My new column is released today, so I am taking a day off.

Let's turn the world by "Number"(57) : Work style reform(16) "

Respect old spirit in the digital age --- Preparedness for senior use

-----

I found this(part 2) when I reviewed my diary, and I don't think I have to write the same again.

-----

ですので、今日は、もう一つの問題提起をしてみたいと思います。

So, I would like to pick up one more question today.

今回のコラムには書かなかったのですが、町内会には、"IT"以外にも問題があります。

Although I did not write in this column, there are problems other than "IT" in the neighborhood association.

日本語に不自由な外国人の居住者 ―― つまり"言語"の問題です。

Residents of foreigners who can not speak Japanese --- It is the problem of "language".

For Japan, which will actively accept foreign workers, it is self-evident that the neighborhood association will also have to get2019 people whose language is not native.

(続く)

(To be continued)

2024,江端さんの忘備録

(国際的な観点から)日本の物価が安い ―― これは、地味に私にインパクトを与えています。

The low cost of living in Japan (from an international perspective) -- has had a sobering impact on me.

インバンド需要によって、海外観光客の取り込みという点では良いことでしょう。

This would be a good thing for attracting international tourists due to in-band demand.

しかし、エネルギー輸入大国日本は、ご存知の通り、大打撃を受けています。

However, as you know, Japan, a major energy importer, has been hit hard.

-----

30年程前、私が一人でアジアを放浪していたというお話は何度かしたと思います。

携帯やメールのない時代の連絡方法

I have told you several times that about 30 years ago, I was wandering alone in Asia.

未整備なインフラ、清潔とは言えない環境、通じない言葉などの問題はありましたが、アジアは私の心の拠り所でした。

Despite the problems of undeveloped infrastructure, unclean environment, and language barriers, Asia was my spiritual home.

特に中国(大陸の方)は、「私の心の支え」といっても過言ではありませんでした。

In particular, China (the mainland) was "my heart and soul".

―― 何もかもが嫌になったら、中国大陸に逃げて、姉から毎月5000円を送金して貰いながら生きていこう

"If I get sick of everything, I'll run away to mainland China and live off my sister's monthly remittance of 5,000 yen."

当時の中国は、5000円もあれば、一ヶ月間くらいなら、余裕で宿泊と飲食を賄えるほど「安い国」だったのです。

At that time, China was such a "cheap country" that one could afford to stay, eat, and drink for a month or so with as little as \5,000.

-----

今、凄い勢いで、「私の心の支え」は壊れつつあります。

Now, "my heart and soul" is breaking down at a terrific rate.

今や日本は、経済大国第2位の国から、私の生きている間に、ランク外まで落ち込む可能性も出てきています。

Japan has gone from being the second-largest economy to possibly falling out of the ranks in my lifetime.

私の「換金レート差額を使った不労所得戦略」は完全に瓦解し、もはや逃げ場がないという事実が、今の私を苦しめています。

The fact that my "unearned income strategy using the exchange rate difference" has completely fallen apart, and there is no longer any way out is now hurting me.

-----

「お金に愛されないエンジニア」シリーズで、この「換金レート差額を使った不労所得戦略」の、過去と現在の話を書きたいのですが ―― 今、そんな時間は、全くありません。

I want to write about the past and present of this "unearned income strategy using the difference in exchange rates" in the "Engineers Unloved by Money" series -- but I don't have time for that right now.

2013,江端さんの忘備録

私が、リュックを背負って、アジアを歩き回っていた時のことです(「バックパッカー」と言われていました)。

バックパッカーの旅行者と一緒に、タイのバンコクを回っていた時、彼の仲間との待ち合わせに付きあったことがあります。

しかし、所定の時間になっても、その仲間は姿を現わしませんでした。このような旅では、よくあることでした。

しかし、その待ち合わせでは、確か「帰国フライトのチケット」の手渡しという重要な内容で、下手すると、彼は、帰国する手段を失うかもしれないという事態でした。

-----

私が驚いたのは、その後です。

「必ず何かのメッセージを残しているはずだ」と言いながら、彼はその周辺を探し出して、電柱から飛び出している針金に引っかかっている紙を見つけました。

「お、これだ、これだ」

その紙には、『落ち合う時間と場所の変更』を記載した手書きの文章が記載されていました。

-----

携帯電話もメールもない時代、ましてや海外における連絡手段が絶無であった時代において、

我々、海外一人旅の旅行者は、ほとんどこのような、―― 現代にあっては信じられないような原始的な方法で ―― 海外の旅を生き延びていたのです。

2024,江端さんの技術メモ

※fastapiの場合、スレッドでは上手くコンロールできない(らしい)ので、プロセス単位で管理します
(1)execute-commandというAPIから、pingを行う回数Xをjson形式入力して、"ping -n X kobore.net"を起動します。返り値はプロセス番号(pid)がjson形式で戻ります。
curl -X POST -H "Content-Type: application/json" -d "{\"count\": \"5\"}" http://localhost:8000/execute-command
(2)terminate-processというAPIから、上記のpidをjson形式で入力して、プロセスを強制終了します。返り値は、この成否(1/-1)がjson形式で戻ります。
curl -X POST -H "Content-Type: application/json" -d "{\"pid\": \"10164\"}" http://localhost:8000/terminate-process
(3)以下のファイルをtest.pyとして、uvicorn test:app --host 0.0.0.0 --reload を投入してfastapiサーバを起動します。
# curl -X POST -H "Content-Type: application/json" -d "{\"count\": \"5\"}" http://localhost:8000/execute-command
# curl -X POST -H "Content-Type: application/json" -d "{\"pid\": \"10164\"}" http://localhost:8000/terminate-process

import subprocess
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class ExecuteRequest(BaseModel):
    count: int  # pingコマンドの実行回数を指定

class TerminateRequest(BaseModel):
    pid: int  # 終了させるプロセスのPID

# 実行中のプロセスを格納する辞書
running_processes = {}

@app.post("/execute-command")
def execute_command(request: ExecuteRequest):
    count = request.count

    try:
        command = f"ping -n {count} kobore.net"  # pingコマンドの回数をcountに指定
        # コマンドを非同期で実行し、プロセスを取得
        process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        pid = process.pid  # プロセスのPIDを取得
        running_processes[pid] = process

        return {"pid": pid}  # PIDのみを返す
    except Exception as e:
        return {"message": f"コマンドの実行中にエラーが発生しました: {str(e)}"}


@app.post("/terminate-process")
def terminate_process(request: TerminateRequest):
    pid = request.pid
    print("pid in terminate-process", pid)

    try:
        # プロセスを取得し、終了させる
        process = running_processes.get(pid)

        process.terminate()  # プロセスを終了させる(SIGTERMを送信)
        process.wait()
        del running_processes[pid]  # プロセスを辞書から削除

        # 成功の場合は1を返す
        return {"status": 1}
    except Exception as e:
        return {"status": -1}  # 失敗の場合は-1を返す

if __name__ == "__main__":
    # FastAPIサーバーを開始
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

出力結果
C:\Users\ebata\fastapi7>curl -X POST -H "Content-Type: application/json" -d "{\"count\": \"100\"}" http://localhost:8000/execute-command
{"pid":1784}
C:\Users\ebata\fastapi7>curl -X POST -H "Content-Type: application/json" -d "{\"pid\": \"1784\"}" http://localhost:8000/terminate-process
{"status":1}
C:\Users\ebata\fastapi7>curl -X POST -H "Content-Type: application/json" -d "{\"pid\": \"1784\"}" http://localhost:8000/terminate-process
{"status":-1}


起動したプロセスを監視して、プロセスが予定通り/突然停止した場合、それを通知する仕組みを追加しました。

# curl -X POST -H "Content-Type: application/json" -d "{\"count\": \"5\"}" http://localhost:8000/execute-command
# curl -X POST -H "Content-Type: application/json" -d "{\"pid\": \"10164\"}" http://localhost:8000/terminate-process
# C:\Users\ebata\fastapi7>uvicorn test:app --host 0.0.0.0 --reload

import subprocess
import os
import time
import multiprocessing  # multiprocessingモジュールを追加
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class ExecuteRequest(BaseModel):
    count: int  # pingコマンドの実行回数を指定

class TerminateRequest(BaseModel):
    pid: int  # 終了させるプロセスのPID

# 実行中のプロセスを格納する辞書
running_processes = {}
process_monitor_processes = {}

@app.post("/execute-command")
def execute_command(request: ExecuteRequest):
    count = request.count

    try:
        command = f"ping -n {count} kobore.net"  # pingコマンドの回数をcountに指定
        # コマンドを非同期で実行し、プロセスを取得
        process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        pid = process.pid  # プロセスのPIDを取得
        running_processes[pid] = process

        # プロセスを監視するプロセスを起動
        monitor_process = multiprocessing.Process(target=monitor_process_status, args=(pid,))
        monitor_process.start()
        process_monitor_processes[pid] = monitor_process

        return {"pid": pid}  # PIDのみを返す
    except Exception as e:
        return {"message": f"コマンドの実行中にエラーが発生しました: {str(e)}"}


@app.post("/terminate-process")
def terminate_process(request: TerminateRequest):
    pid = request.pid
    print("pid in terminate-process", pid)

    try:
        # プロセスを取得し、終了させる
        process = running_processes.get(pid)

        process.terminate()  # プロセスを終了させる(SIGTERMを送信)
        process.wait()
        del running_processes[pid]  # プロセスを辞書から削除

        # 成功の場合は1を返す
        return {"status": 1}
    except Exception as e:
        return {"status": -1}  # 失敗の場合は-1を返す

def monitor_process_status(pid):
    while True:
        if not is_process_running(pid):
            # プロセスが存在しない場合
            # メッセージを生成して出力(または送信)
            message = {
                "status": "Process Disappeared",
                "pid": pid
            }
            print("Process Disappeared:", message)

            # プロセス監視プロセスを停止
            ### del process_monitor_processes[pid]
            break

        # 一定の待機時間を設定して監視を継続
        time.sleep(10)  # 10秒ごとに監視

def is_process_running(pid):
    #try:
    #    os.kill(pid, 0)  # PIDを使ってプロセスにシグナルを送信し、存在を確認
    #    return True
    #except OSError:
    #    return False
    try:
        # ここの部分Windows特有のやりかたなので、後で、例の、os.kill(pid,0)を試してみること
        # tasklistコマンドを実行してプロセス一覧を取得
        result = subprocess.check_output(["tasklist", "/fi", f"PID eq {pid}"], universal_newlines=True)

        # 結果から指定したPIDの行を検索
        lines = result.splitlines()
        for line in lines:
            if f"{pid}" in line:
                return True

        # 指定したPIDが見つからない場合
        # ここに、停止時のメッセージ送信を組み込めばO.K.のはず   

        return False
    except Exception as e:
        return False





if __name__ == "__main__":
    # FastAPIサーバーを開始
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

2024,江端さんの技術メモ

指定されたコマンド "ping -100 kobore.net" をFastAPIのエンドポイントから実行し、それが終了したらAPIを正常に終了させるコードは以下のようになります:

test.py

import subprocess
import threading
import os
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class CommandRequest(BaseModel):
    command: str

@app.post("/execute-command")
def execute_command(request: CommandRequest):
    command = request.command
    # コマンドを非同期で実行
    execution_thread = threading.Thread(target=execute_command_async, args=(command,))
    execution_thread.start()
    return {"message": f"コマンド '{command}' の実行を開始しました"}

def execute_command_async(command):
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    process.wait()  # コマンドの終了を待つ
    print(f"コマンド '{command}' の実行が終了しました")
    # os._exit(0)  # FastAPIサーバーを終了させる

if __name__ == "__main__":
    # FastAPIサーバーを開始
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

$ uvicorn test:app --host 0.0.0.0 --reload

 

C:\Users\ebata\fastapi7>curl -X POST -H "Content-Type: application/json" -d "{\"command\": \"ping -n 20 kobore.net\"}" http://localhost:8000/execute-command