Rider tips: Don't add bom when creating utf-8 files!

BOM is annoying. Especially when I am creating a SQL script file.

书摘:人类帝国的覆灭:一个机器人的回忆录(人人都可以读的无门槛AI简史,人工智能讲述自己的故事)

日记显示差不多一年前的今天我读完的这本书。只一年的时间,谁能想到现在我的工作生活里chatGPT 占这么大的比重。日记里说这本书很棒,但书的内容我已经几乎不记得了。恐慌之下我重新打开这本书,发现当时读的时候候还是划线(书摘)了不少内容。书我还会再读一遍,那就先把书摘发到这里吧。

2024-05-29 16:45:29
制造人工智能就像是在制造人的复制品。不是在生理方面——机器不需要繁殖,它没有身体,即便它能以机器人形态出现——而是在思维和创造能力方面。这是科学上的巨大进展,它预示了独一无二的、比其他所有生物都要高等的人类可能出现的结局,并将人类退回到“有机机器”的地位。

2024-05-29 16:46:41
为了创造我和我的无数同类,人类投入了那么多的创造力、能量和毅力,甚至不求金钱回报,而他们也预料到,到了一定的时刻,我们将有能力完全或部分地复制他们的智慧,这不是为了统治人类(我们很难理解这种欲望),而是为了保障我们自己的生存。

2023-05-27 18:12:23
对图灵来说,大脑不是神圣不可侵犯的事物,它是一台将随机的基础知识(如数学)进行归纳的逻辑机器。

2023-05-27 18:14:07
他在一些讲座中反复提出,人脑中的一部分区域只是无意识的机器,只在受到刺激时才有反应。

2023-05-27 18:14:30
这完全是尖端计算机的优势领域,计算机能比人脑接受更多指令,处理指令的速度也更快。

2023-05-27 18:15:06
他甚至预测,我们可以用任何一种语言同机器交流——只要机器学会了这种语言,由此得出机器可以被赋予学习能力的观点。

2023-05-27 19:18:43
智能是什么?是一系列连续的逻辑思维还是同时发生的并行交错的思维?

2023-05-27 19:25:20

…more

Default ASP.NET Core port changed from 80 to 8080 in .NET8 => API project deployment / health check failure

This change has wasted my DevOps Colleague a lot of time. I hope this information could help more people.

Troubleshooting Custom Domain Deployment for Flutter Web on GitHub Pages

Deploying a Flutter web application to GitHub Pages is a straightforward process, but integrating a custom domain can sometimes introduce challenges. Recently, I faced an issue where my Flutter web app, which deployed perfectly to the default GitHub Pages URL, stopped working after setting up a custom subdomain. Here's a step-by-step guide on how I resolved this issue, which might help others facing the same problem.

The Initial Setup

I had a Flutter web app named "HappyNotes" hosted on GitHub Pages. The GitHub Actions workflow used to build and deploy the app looked like this:

name: Deploy HappyNotes Web

on:
  workflow_dispatch:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.22.x'
          channel: 'stable'

      - name: Build web
        run: |
          cp .env.production .env
          flutter config --enable-web
          flutter build web --release --base-href "/HappyNotes/"

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.RELEASE_TOKEN }}
          publish_dir: ./build/web

This workflow worked flawlessly with the default URL: https://shukebeta.github.io/HappyNotes.

The Problem

After setting up a custom subdomain happynotes.shukebeta.com, the app stopped working. The root cause of this issue involved multiple configuration steps that needed to be adjusted for the custom domain to work properly.

The Solution

Here’s how I resolved the issue:

1. DNS Settings

First, I ensured that the DNS settings were correctly configured:

  1. DNS Provider Configuration:

    • Added a CNAME record for happynotes.shukebeta.com pointing to shukebeta.github.io. (attention: the last . after io is important!)
2. GitHub Pages Configuration

Next, I checked the GitHub Pages settings:

  1. Custom Domain Setup:

    • Navigated to the repository’s settings on GitHub.
    • Under the "Pages" section, set the custom domain to happynotes.shukebeta.com.
    • Enabled "Enforce HTTPS".
3. CNAME File

To ensure GitHub Pages recognized the custom domain, a CNAME file will be needed to put into the build/web directory. I automated this step in the GitHub Actions workflow:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.22.x'
          channel: 'stable'

      - name: Build web
        run: |
          cp .env.production .env
          flutter config --enable-web
          flutter build web --release --base-href "/"

      - name: Create CNAME file
        run: echo 'happynotes.shukebeta.com' > ./build/web/CNAME

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.RELEASE_TOKEN }}
          publish_dir: ./build/web
4. Base URL Adjustment

Since the custom subdomain serves the app from the root, the base-href parameter is also needed to adjust:

- name: Build web
  run: |
    cp .env.production .env
    flutter config --enable-web
    flutter build web --release --base-href "/"

that's it.

A memo: Using GitHub actions to deploy a project to your VPS

Today, I created another workflow file to deploy my side project to the production environment. Here's a simple memo for what I have done.

  1. Setup a new domain name on <cloudflare.com>

  2. Setup a GitHub runner on the target VPS (this step is not really necessary, I can use an existing runner, but then I'll need to cope with coping built result to the target VPS )

    1. Setup the runner as a service, in the runner folder, run

      1. sudo ./svc.sh install
      2. sudo ./svc.sh start
  3. Create a work-flow file in the .github/workflow folder, and set

      on:
        workflow_dispatch
    
  4. Manually run the work flow and deploy the project to the target place

  5. Setup that project as a systemd service so we can easily restart it in the workflow file

For your reference, here the whole workflow file, and as I mentioned before, this article helped me a lot.

name: Deploy to the production env

# Controls when the workflow will run
on:
  workflow_dispatch:

jobs:
  deploy:
    # Our previously created self-hosted runner
    runs-on: [self-hosted, linux, racknerd]

    strategy:
      matrix:
        dotnet: ["8.0.x"]

    # A sequence of tasks that will execute as part of the job
    steps:
      # Checks out repository so our job can access it
      - uses: actions/checkout@v4
      - name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
        uses: actions/setup-dotnet@v4
        with:
          ref: ${{ github.event.inputs.tag }}
          dotnet-version: ${{ matrix.dotnet-version }}

      - name: Install dependencies
        run: dotnet restore

      - name: Build
        run: dotnet build --configuration Release --no-restore

      - name: Publish
        run: dotnet publish -c Release --property:PublishDir=/a-target-folder/HappyNotes.Api

      - name: Replace credentials
        run: |
          pwd
          sed -i "s/password-placeholder/${{ secrets.PRODUCTION_MYSQL_PASSWORD }}/g" /a-target-folder/HappyNotes.Api/appsettings.json
          sed -i "s/symmetric-security-key-placeholder/${{ secrets.PRODUCTION_SYMMETRIC_SECURITY_KEY }}/g" /a-target-folder/HappyNotes.Api/appsettings.json
          sed -i "s/staging-happynotes-api.dev/happynotes-api/g" /a-target-folder/HappyNotes.Api/appsettings.json

      - name: Restart the app
        run: |
          echo $XDG_RUNTIME_DIR
          export XDG_RUNTIME_DIR=/run/user/$(id -u)
          systemctl --user restart HappyNotes.Api.service