Posts in category “Essays”

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 still 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

书摘:人性

作者:【美】戴尔·卡耐基

2015-01-02 07:36:22
在推销商品的时候,我们更多地应该考虑消费者的需求,而不仅仅只是个人的好恶。

2015-01-02 07:38:48
西蒙·福格从伯明翰大学毕业后的第二天就来到了《泰晤士报》总编办公室,询问说:“请问你们现在需要编辑吗?”
总编回答说:“不需要。”
西蒙·福格还不死心,继续问道:“记者呢?”
“不需要。”
“排版工呢?”
“不需要。”
“那校对员呢?”“抱歉,我们现在没有任何职位空缺。”
总编显然已经有些不耐烦了。
西蒙·福格想了想,突然从包里掏出了一块牌子,对总编说:“那我想,你们一定需要这个吧!”
总编抬起头一看,那块牌子上写着“额满,暂不雇用”几个字。
就因为这个牌子,总编留下了西蒙·福格。二十五年后,西蒙·福格成了《泰晤士报》的新总编。

2015-01-02 07:53:32
无论是推销商品,还是推销自己,都要建立在诚信之上。

2015-01-02 07:54:01
一件受消费者欢迎的商品,好质量是最基本的条件。一件商品如果质量不好,那么无论它具有多么吸引人的噱头,或者多么强大的功能,都不可能受到消费者的欢迎。

…more

书摘:《大教堂与集市》(中文版首次出版)

作者:ERIC S. RAYMOND

2014-12-13 16:28:31
如果你有正确的态度,有趣的事情自然会找到你

2014-12-13 16:29:17
“黑客”并不是媒体报道中的计算机违法分子,而是那种着迷于计算机技术并通过编程提供极具价值软件的人。

2014-12-13 16:30:24
软件膨胀到一定程度,由一个人或几个人继续开发维护就不太现实了,对大型软件来说,多人合作似乎是一种必然,但到底多少人合适,如何分工和组织,如何调动程序员的积极性,如何让软件不会因规模和复杂性而失控,从来都有着不同的方法和认识。

2014-12-13 21:04:08
开放式开发和分布式同行评审(peer review)

2014-12-13 21:12:40
多少双眼睛才能驯服复杂性、要命的最后期限,关于分支和伪分支更准确的定义,进化不利条件理论、孔雀、牡鹿和开源开发者动机的关系,开源的经济学动力,信息不对称效应,用开源做竞争武器。

2014-12-14 10:31:34
白象是一种罕有的白色亚洲象,常作为宗教或王室权利的象征,用来形容昂贵、无用且需要很高代价来维持或经营的事物。

2014-12-14 12:12:58
Linux几乎从一开始就发展出一条完全不同的路,其开发更像是仅通过互联网合作的大量志愿者的随意之作。在质量方面,没有严格的标准也没有一个强有力的机构来管理,他们只是执行一个简单得有点幼稚的策略:每周发布,并在接下来几天内获取数百个用户的反馈。他们创造了一种类似达尔文“物竞天择”的选择机制,被选择对象则是开发者们所做的种种软件修改。让所有人吃惊的是,这种方式工作得非常好。

2014-12-14 12:20:17

…more