Posts in category “Essays”

把博客的中文字体改成了汇文明朝体

这个博客使用了 Chyrp-lite 项目,当初之所以选择它,一方面觉得看上去还行,另一方面是因为它是 PHP 写的,而我曾经是一个老PHP程序员,这样万一遇到点什么小毛病可以自己改。我最近知道了一种新字体:汇文明朝体。怎么说呢,这个字体在八十年代相当流行。我那个时候读过的书,多是这种这种印刷体。不知道什么人把它搬到了互联网上,我先是把它用到了我最喜欢的读书app 多看阅读上,今天又琢磨把它移植到我的博客上。闲话少绪,说干就干, 在ChatGPT的帮助之下,把字体转成woff2格式,再改一个CSS文件,不到半小时就整好了。

--- a/themes/blossom/stylesheets/all.css
+++ b/themes/blossom/stylesheets/all.css
@@ -1,8 +1,16 @@
+@font-face {
+    font-family: 'Huiwen Mingchao font';
+    src: url('../../../fonts/汇文明朝体.woff2') format('woff');
+    font-weight: normal;
+    font-style: normal;
+    unicode-range: U+4E00-9FFF;
+}
 @font-face {
     font-family: 'Open Sans webfont';
     src: url('../../../fonts/OpenSans-Regular.woff') format('woff');
     font-weight: normal;
     font-style: normal;
+    unicode-range: U+0020-007E;
 }
 @font-face {
     font-family: 'Open Sans webfont';
@@ -58,8 +66,8 @@ html[lang="he"] {
     background-color: #208448;
 }
 body {
-    font-family: "Open Sans webfont", sans-serif;
-    font-size: 1rem;
+    font-family: "Huiwen Mingchao font", "Open Sans webfont", sans-serif;
+    font-size: 1.2rem;
     color: #1f1f23;
     line-height: 1.5;
     background-color: #f7f5ed;

小记:MacBook Pro Mid 2010 升级 512G 杂牌 SSD

最近 temu (拼多多海外版)很火,老是鼓动着我花钱。这不,满$150刀减$40的优惠券就在那儿晃啊晃,你说我是买啊还是买啊?当然是买买买了!正巧我的老MacBook Pro (Mid 2010) 硬盘才128G,而我的次老MacBook Pro(Mid 2015)硬盘也才256G,都该换了。但我并不想出太多血,所以下单了杂牌 Derlar 512G 和 1T硬盘各一支,又加了一个type-c接口的sd卡读卡器拼单,优惠后 $112.74 包邮。4月8号下的单,今天收到货,爽呆呆。

然而升级过程并非一帆风顺,中间冷汗也是流了不少。

我的这台机器,上次光驱换成128G SSD不久之后,老硬盘就不能识别了。我那会就把老硬盘拆掉当外置硬盘使用。

这次我打算先试试双硬盘,把新盘放到原来的硬盘位置,结果系统不认,小汗,不过因为之前老硬盘也出过时认时不认的问题,我并没有很担心。也许就是线坏了。把新盘换光驱位置,认出来了,开心!

但装系统仍然是个麻烦事。我的次老MacBook Pro是最新系统,而这台老MacBook Pro只支持到 High Sierra,我只好又把老SSD接回去,制作好USB引导盘。再把新硬盘装回去,眼看着顺利进入了系统安装界面,我就放心的出门散步去了。然而...

等我散步回来,机器是关机状态。不对啊。哦,其实不是关机状态,是无限重启状态。这可不是什么好现象。网上搜了一下,说啥的都有。最悲观的说法是硬盘不兼容。可别呀!

Option+Command+Shift+R 进去看了看,咦?新盘的文件系统我怎么用的是 Mac OS Extended (Journaled),记得从 High Sierra起改用APFS了不是?于是重新格式成APFS再安装一遍。漫长的等待之后,成了!

哼!想搞我,没那么容易。不过还是出了一身冷汗。毕竟退货啥的怪麻烦。

This site just moved to Oracle Cloud and upgrated to the latest chyrp-lite version (2023.01)

If you found anything unusal or incorrect, please press Ctrl+Shift+R to reload the page first. If you stil found something wrong, please leave a comment here or contact me at telegram https://t.me/shukebeta

Many thanks

Why did I decide to move/upgrade?

Previously, this site is hosted at my home, on an old dell laptop (4G ram/250G hdd). In general, it works great. However, sometimes, housewife displug this laptop and forget to plug it back. It didn't happen often but it happened several times. Two days ago, we went camping and my wife turned off the whole wiring board to avoid some danger in her mind!

As wife is always right, I decided to move this site to one of the free VM on oracle cloud. And, it is done today! By the way, I upgraded this site to a most recent release. Hope you guys love it.

ChatGPT 帮我发布书摘

我更喜欢用 多看阅读 来读电子书。一方面阅读体验好,另一方面它支持扫描pdf重排。另外,多看的书摘格式即使导出到Email也挺赏心悦目的。许是已经年老的缘故,我最近在收集一些旧文,以及把我历年的读书书摘集中发布在我的blog上。我的blog的编辑器是一个比较简陋的 markdown编辑器,为了确保发布后能有相对美观的格式,我总要手工编辑一下,怪累的。

今天闲来无事,复制粘贴手工发布了几篇书摘后我想,哎,何不让chatGPT帮我写个脚本来简化我的工作。说干就干,于是花了一两个小时,让chatGPT给我写了以下两个脚本:

第一个,负责整理书摘的格式,我给取了个名字就叫 shuzhai

#!/bin/bash

# Check if filename is provided as parameter
if [ $# -ne 1 ]; then
  echo "Usage: $0 filename"
  exit 1
fi

filename="$1"

sed -i '/^$/d' "$filename"
# Add "书摘:" prefix to the first line
sed -i '1s/^/书摘:/' "$filename"
# Add "作者:" prefix to the second line
sed -i '2s/^/作者:/' "$filename"

# Insert an extra empty line before the last non-empty line of the file
sed -i -e ':a' -e '$!{N;ba}' -e 's/\(\S.*\)\n/\1\n\n/' "$filename"

# Run the first sed command to add an extra empty line before the date time
sed -i 's/\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\) [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}/\n&/' "$filename"

# Run the second sed command to add two spaces at the end of each non-empty line
sed -i '/^$/!s/$/  /' "$filename"

第二个脚本,我叫它 publish_shuzhai_to_blog, 它调用前面的 shuzhai脚本,并自动将书摘内容发到我的blog站点。

#!/bin/bash

# Check if filename is provided as parameter
if [ $# -ne 1 ]; then
  echo "Usage: $0 filename"
  exit 1
fi

filename="$1"

if [ ! -f "$filename" ]; then
  echo "File not found: $filename"
  exit 1
fi

if ! [ -r "$filename" ]; then
  echo "File not readable: $filename"
  exit 1
fi

# Check that the file is a text file
if ! file "$filename" | grep -q "text"; then
  echo "Not a text file: $filename"
  exit 1
fi

# Create the logs directory if it doesn't exist
LOG_DIR=~/logs
if [ ! -d "$LOG_DIR" ]; then
  mkdir "$LOG_DIR"
fi

# Create an empty log file if it doesn't exist
LOG_FILE="$LOG_DIR/$(basename "$0").log"
if [ ! -f "$LOG_FILE" ]; then
  touch "$LOG_FILE"
fi

# read the text file and extract the first line as the POST_TITLE
POST_TITLE=$(head -n 1 $1)

# Check if the new file's title is the same as the last processed title
if [ -s "$LOG_FILE" ]; then
  LAST_TITLE=$(tail -n 1 "$LOG_FILE")
  if [ "$LAST_TITLE" = "$POST_TITLE" ]; then
    echo "Error: Duplicate title detected: $POST_TITLE"
    exit 1
  fi
fi

# format the file first
~/bin/shuzhai "$filename"

# re-read the first line as title, as we add "书摘:" as a prefix to the title
POST_TITLE=$(head -n 1 $1)

# Log the new title
echo "$POST_TITLE" >> "$LOG_FILE"

# set the URL of the blog site
BLOG_URL='https://blog.shukebeta.com/admin/add_post/'

# read the rest as the POST_BODY
POST_BODY=$(tail -n +2 $filename)

# build the data for the curl request
DATA=$(cat <<EOF
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="title"

${POST_TITLE}
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="body"

${POST_BODY}
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="status"

public
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="slug"


------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="created_at"

$(date +"%Y-%m-%d %H:%M:%S")
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="option[comment_status]"

open
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="tags"

中文, 书摘
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="option[category_id]"

3
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="feather"

text
------WebKitFormBoundaryEznVwciBsbYrRkwB
Content-Disposition: form-data; name="hash"

28ccc1f365e2781c9b0877badb3349cc5ce9945a
------WebKitFormBoundaryEznVwciBsbYrRkwB--
EOF
)

# send the curl request
curl -X POST "${BLOG_URL}" \
     -H 'origin: https://blog.shukebeta.com' \
     -H 'referer: https://blog.shukebeta.com/admin/' \
     -H 'cookie: there is only a place-holder, hahahaha' \
     -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryEznVwciBsbYrRkwB" \
     -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" \
     --data "${DATA}"

这两个脚本要是我自己来写,怕是要花一整天。感叹!

书摘:人人都能用英语

作者:李笑来

2015-03-23 23:21:41
多年以来,受影响最深的,并不是当时所学的BASIC,或者是后来所学的PASCAL,抑或再后来学的C、C++什么的;受影响最深的是一种思考方式──在运行程序之前,要反复浏览代码,在脑子里进行预演;而不是写完程序直接运行,出错了再说。这是节省时间提高效率的重要方式。

2015-03-23 23:22:51
人们只愿传播自己相信的知识──哪怕那所谓的知识根本就是错的。

2015-03-23 23:26:04
为什么我们竟然越学越差?
因为我们从未相信自己能够学会、学好!

2015-03-31 07:20:32
一个想法必须足够简单才可能被植入;越是简单的想法,在植入之后越是根深蒂固;因为拥有这个想法的人无法分辨这个想法是自己的还是被植入的……同样的道理,高考词汇大纲就是以这种方式,把那个极为简单的想法悄悄地“植入”到我们的大脑之中,进而使其根深蒂固,影响我们一生……

2015-03-31 21:42:07
教育这东西,从来都是在失败中发挥作用──所以成功必然是偶然。教育的古怪之处在于,如果把学生当做天才去教育,学生几乎注定不会成为天才,因为天才是靠自学的;但是,如果把学生当做弱智去教育,那学生肯定会变成弱智──因为人傻是被教出来的。

2015-03-31 21:46:30
事实上,“我也行”这三个字是绝大多数普通人最现实最有效的动力。

2015-03-31 21:46:59
人们常常误会因果关系:他们看到别人先去参加某个培训,后来获得了高分,于是就认为“那个培训班”和“获得高分”之间是因果关系;这和“认为鸡叫唤起了太阳”本质上没什么两样。

…more