Coding

Gsutil Need Pip Install Pyopenssl

Need to create some signed-url links, using following command.

gsutil signurl -d 2d service-account-key.json gs://my-gcs-bucket/my-object

But the response keeps auguing

The signurl command requires the pyopenssl library (try pip install pyopenssl or easy_install pyopenssl)

Already check those variables and install pyopenssl thousand times.

CLOUDSDK_PYTHON=path/to/python
CLOUDSDK_PYTHON_SITEPACKAGES=1

After checking the source code under platform/gsutil/gslib/commands/signurl.py

try:
  from OpenSSL.crypto import FILETYPE_PEM
  from OpenSSL.crypto import load_pkcs12
  from OpenSSL.crypto import load_privatekey
  from OpenSSL.crypto import sign
  HAVE_OPENSSL = True
except ImportError:
  HAVE_OPENSSL = False
  ...

The load_pkcs12 has been removed from PyOpenSSL==23.3.0, so I install the previous version and get works.

抓網站內容做成電子書 (epub)

alt

買了 BOOX note5 之後, 覺得電子紙螢幕呈現效果真舒服, 所有要長時間閱讀的東西都想丟進去. 另外發現雖然系統用 Android 11, 理論上可以裝所有 Android App, 包含瀏覽器, 不過在裝了一堆 App 發現都是虛幻, 排版與文字呈現還是用 epub 格式最好.

本次範例使用 EbookLib, requests

以及 mark_mew 大大的關於我幫新公司建立整套部屬流程那檔事 為範例 感謝 mark_mew 大大分享自身經驗

另外粗粗產生出來的 epub 還是有很多排版問題要修, 像是圖片不見了, script tag 跑出來了, 在過一層 strip_tags 應該會好一點. 看來最適合的還是轉小說進去 (?

這次網頁數量不多用 requests 抓抓就好, 就不寫 scrapy 了, 抓別人網站注意禮貌

程式分成四段, 第四段跟 ebooklib 範例程式只有差異在產生 sections 部分

  • 抓內容網址
  • 抓內容 -> local file
  • 建立章節
  • 寫成 epub
from ebooklib import epub
from lxml.html import fromstring
from tqdm import tqdm
import os
import requests

# 抓內容的網址
urls = []
headers={
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
}
page_urls = [
    'https://ithelp.ithome.com.tw/users/20141518/ironman/4653',
    'https://ithelp.ithome.com.tw/users/20141518/ironman/4653?page=2',
    'https://ithelp.ithome.com.tw/users/20141518/ironman/4653?page=3',
]
for url in tqdm(page_urls):
    response = requests.get(url, headers=headers)
    tree = fromstring(response.text)
    urls += [s.strip() for s in tree.xpath('//h3[@class="qa-list__title"]/a/@href')]

# 抓內容
for url in tqdm(urls):
    fname = url.split('/')[-1]
    with open(fname, 'w') as wf:
        response = requests.get(url, headers=headers)
        wf.write(response.text)

# 建立章節
def build_sections():
    sections = []
    for fname in tqdm(sorted(os.listdir('./ebooks'))):  # 利用檔案名稱排章節順序
        if '.' in fname:
            continue
        with open('./ebooks/' + fname) as f:
            tree = fromstring(f.read())
            title = tree.xpath('//h2[@class="qa-header__title ir-article__title"]/text()')[0].strip()
            content = ''.join(list(tree.xpath('//div[@class="qa-panel__content"]')[0].itertext()))
            content = content.replace('\n', '<br/>')
            section = epub.EpubHtml(title=title, file_name=fname, lang='zh-hant')
            section.content = content
            sections.append(section)
    return build_sections

# 寫成 epub
from ebooklib import epub

book = epub.EpubBook()

# set metadata
book.set_identifier('ithome_ironman_4653')
book.set_title('關於我幫新公司建立整套部屬流程那檔事')
book.set_language('zh-hant')
book.add_author('mark_mew')


# create chapter
sections = build_sections()

# add chapter
for section in sections:
    book.add_item(section)

# define Table Of Contents
book.toc = [
    epub.Link(section.file_name, section.title, section.title)
    for section in sections
]

# add default NCX and Nav file
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())

# define CSS style
style = 'BODY {color: white;}'
nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style)

# add CSS file
book.add_item(nav_css)

# basic spine
book.spine = ['nav'] + sections

# write to the file
epub.write_epub('關於我幫新公司建立整套部屬流程那檔事.epub', book, {})

初老工程師的焦慮

往雲裡去

2022 年滿 32 歲,對目前職涯感到有點迷惘,生活中有很多焦慮,寫下來或許會好一點。

學不動的焦慮 #

4/1 在新公司待滿一個月了,換工作這段期間總是有很多對未來的想法。

今年也看到很多厲害同事都在往理想的目標邁進:

  • 有出國工作的
  • 換到 FAANG
  • 生活重心在育兒上面或即將轉到育兒上面
  • 辭職轉專職顧問的
  • 開書店的

在祝賀與羨慕的同時,心裡不免有些焦慮,我到底想要什麼。

這幾年打算走 individual contributor 這條路,我覺得這條路比較適合我, 尤其在前一間公司看到很多年資比較大的工程師,在發揮影響力的同時,也把家庭顧的很好。

但在現在公司看到都是一群年輕,技術能力扎實,溝通能力強,人又謙虛的同事, 心裡也是有點焦慮。我的競爭優勢在哪?是不是要開始找養老公司了?是不是還是要轉管理職?

視野實現一半的焦慮 #

環境跟人很重要,多與人交往,這兩年的變動都跟同事提供的視野有關。

在 SNS 看到人家說「很多人在 25 ~ 30 歲想找自我,找到最後才發現自己喜歡錢」 我稍微不幸一點,31 歲才發現自己喜歡錢,剛好這幾年大環境變動,薪資水準提升很快, 雖然不比半導體業,至少也是有領到人家地板價。

同事給我的視野還有出國唸書,以軟體工程來講,我覺得出國是最好的方向, 拿到灣區平均 offer,兩三年就可以回本,同時也在科技前沿工作,進可攻退可守。

健康不行了 #

健檢紅字越來越多,眼睛健康越來越差,已經有老花症狀,飛蚊症也變嚴重。 主因我想還是每天上班看螢幕八小時,下班娛樂主要還是看電腦,經歷每天 12 小時的摧殘。 或許也應該思考副業或轉職可能性,三十歲後健康每況愈下,老得很快,希望下一次大衰退不要來得太早。

買房、買車 #

買車就是負資產,但還是好方便喔 XDD 焦慮自己前幾年沒存太多,頭期還是出不起,但也只能慢慢累積。

已經克服的焦慮 #

文章最後總要留點正向的東西

Imposter syndrome

前幾次換工作真的焦慮到爆,為什麼達不到主管的期待?後來漸漸了解:

  1. 每個人經歷不盡相同,過去的經驗不一定能快速換來對公司的貢獻
  2. 說者無心聽者有意。有些事不需要想太多,大部分的情況只要態度正確,就沒有大問題(在對的時間做對的事情)
  3. 氣場不合,他就是不喜歡你。做該做的事情,盡可能正直,他人的主觀想法不容易扭轉,做好該做的事情。
  4. 主管標準比較高。依照自己的節奏做事,不可能一直衝刺的,跟主管討論這方面的期待吧。

人際交往的焦慮

  1. 以前做了很多刻意的表演,才發現人與人互動真誠、正直、自然這幾點都很重要,刻意裝是沒有用的。

Jupyterlab With System Monitor

alt

Try to switch to jupterlab, the cpu/mem graph looks greeeat. https://github.com/jtpio/jupyterlab-system-monitor

But install n-times, the graph still no showing.

Thanks my colleague Bill, indicate the version issue of nbresuse

Reinstall the package, finally works!

$ brew install node
$ pip install jupyterlab
$ pip install nbresuse==0.3.6
$ jupyter labextension install jupyterlab-topbar-extension jupyterlab-system-monitor
$ jupyter notebook --generate-config

Generate the jupyter config and fill the display config

c.NotebookApp.ResourceUseDisplay.mem_limit = 16 * 1024 ** 3
c.NotebookApp.ResourceUseDisplay.track_cpu_percent = True
c.NotebookApp.ResourceUseDisplay.cpu_limit = 8

Learning the Norman Layout 4 months

About 4 months after changing the typing layout to Norman. I think I will type with Norman last a long time (unless I’m interesting w/ another one).

I forgot QWERTY #

Typing bopomofo (Chinese typing, and it’s interesting story is another challenge on ErgoDox, so first, I flash my ErgoDox’s firmware to use Norman, then I can still type bopomofo on my laptop’s keyboard. I will have some time will type with QWERTY. I can change both layout in minutes on that time.

Learning the Norman Layout 2 weeks

My shoulder #

One day I’m looking for a split keyboard try to make my shoulder feel better at work.

I need to keep the round shoulder posture almost all day. Make my body curl and back pain sometimes.

What I found is ErgoDox EZ, and received my new keyboard after 10 days.

ErgoDox #

ErgoDox is a split, ortholinear, fully programmable keyboard with thumb key matrix. So you can put any keys on any position to facilitate the thumb usage. And it’s need somtime to get used it.

Terminal Notify

最近公司 build tool 因為專案爆肥越來越慢,build code 要花個十分鐘左右,不太行啊, 泡咖啡時間變長了呀逼