LLM
Fetch

Fetch

Fetch VS XHR

Comparison Fetch XHR
IndexedDB

IndexedDB

Refs

  1. IndexedDB指南

概念

  • IndexedDB是一个事务型数据库系统,类似于基于 SQL 的 RDBMS。
  • 不同的是RDBMS使用固定列表,IndexedDB是一个基于JavaScript的面向对象的数据库。
  • IndexedDB 是一种低级API,用于客户端存储大量结构化数据(包括, 文件/ blobs)。该API使用索引来实现对该数据的高性能搜索。
  • 虽然 Web Storage 对于存储较少量的数据很有用,但对于存储更大量的结构化数据来说,这种方法不太有用。IndexedDB 提供了一个解决方案。
Read more
OpenAI
Javascript FAQ

Javascript FAQ

Float precision

1
console.log(0.1 + 0.2) // 0.30000000000000004

Solution: Strip

1
2
3
4
5
function strip(number) {
return parseFloat(number.toFixed(12));
}

console.log(strip(0.1 + 0.2)) // 0.3

Solution: Decimal.js

  • The decimal.js package is 283kb at the time of writing. So decimal.js is not appropriate for frontend.
1
2
3
4
5
const Decimal = require('decimal.js')

let m = new Decimal(0.1)

console.log(m.add(0.2).toNumber()) // 0.3
Authentication

Authentication

Refs

Authentication Schemes

Basic

  • This is the simplest form of HTTP authentication, where the client sends the username and password in base64 encoded text as part of the HTTP header. The server then checks the username and password against a user database and sends a response indicating whether the authentication was successful or not. This scheme is not very secure, as the password is transmitted in clear text and can be intercepted by anyone who is listening on the network.

Bearer

  • A token-based scheme that is set in the Authorization header in the format Bearer <token>.
  • “Bearer” means the client is the bearing the token.
  • Bearer token mostly uses JWT.

Digest

  • This is a more secure form of HTTP authentication that uses a cryptographic hash to protect the password. When the client sends the username and password, the server sends a challenge that includes a nonce value. The client then computes a hash of the password and other information, including the nonce, and sends the hash back to the server. The server then checks the hash to authenticate the user.

OAuth2

  • See my OAuth2 blog.
Flarum

Flarum

Install

Apache

  • Server: Apache2.4 + PHP 7.4.33. Make sure they are installed and connected.

  • Database: Install Mysql5. Create a database for flarum, e.g. flarum.

  • Configure PHP:

    • Enable fileinfo, gd2 and pdo_mysql.
  • Install Composer, which a php package management tool like npm.

  • Install Flarum:

    • Create a folder named flarum, cd into it and run composer create-project flarum/flarum ..
    • If vendor packages failed to install due to network issues, install behind a proxy:
      • Turn on your proxy and run set HTTP_PROXY=http://127.0.0.1:7078
      • run composer install
  • Configure Apache:

1
2
3
4
5
6
7
8
DocumentRoot "D:\tmp\flarum\public"
<Directory "D:\tmp\flarum\public">
Options Indexes FollowSymLinks
AllowOverride All // It must be set to ALL otherwise error: the requested resource was not found
Require all granted
</Directory>

LoadModule rewrite_module modules/mod_rewrite.so
  • Configure Flarum:
    • in flarum installation folder, edit config.php:
      • 'url' => 'http://localhost' change to 'url' => 'http://[domain or ip]'
    • install chinese langauge pack:
      • composer require flarum-lang/chinese-simplified
      • php flarum cache:clear
Docker

Docker

Why Docker

  • Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.

Concepts

  • Container

    • is a runnable instance of an image. You can create, start, stop, move, or delete a container using the DockerAPI or CLI.
    • can be run on local machines, virtual machines or deployed to the cloud.
    • is portable (can be run on any OS).
    • is isolated from other containers and runs its own software, binaries, and configurations.
  • Image

  • The image contains the container’s filesystem, it must contain everything needed to run an application

Dockerfile

  • A Dockerfile contains a script of instructions that Docker uses to create a container image.
ChatGPT
Wordpress