HHTjim's Blog - Share&Record

Nginx Embedded GeoIP Library

Author: matrix Observed: 152 times Published on: June 5, 2025 Classification: odd | No comment »

Nginx can have a built-in IP address resolution function, without relying on third-party apis to download free geoip library files: https://git.io/GeoLite2-City.mmdb Advantages: convenience of nginx integration Disadvantages: relying on the accuracy of geoip library, there are problems with individual IP resolution in China Build Nginx supporting geoip2 module #Construction phase FROM nginx:latest AS builder# Install build dependenciesRUN apt-get update && apt-get install -y \ wget \ git \ gcc \ make \ libpcre3-dev \ zlib1g-dev \ libmaxminddb-dev \ && rm -rf /var/lib/apt/lists/*# Get nginx source code (same version as base image)RUN wget http://nginx.org/download/nginx- $(nginx -v 2>&1 | sed 's/^.*nginx\///' |......

Basic usage of golang generics

Author: matrix Observed: 244 times Published on: May 31, 2025 Classification: Golang | No comment »

Golang introduced generic support in version 1.18. Now the development and use versions are 1.23, and 1.24 is usually written with little knowledge. Recently, I saw that generic support was also added in version 1.30.0 of Gorm, which is good 😆 📝 Generic declaration Generics of ordinary functions func Print[T any](value T) { fmt.Println(value)} T refers to generic, uncertain type. When calling, specifying any refers to the constraint on T, here it refers to the special constraint without any constraint Generics in structs type Box[T any] struct { value T} Support the generics of field types of structures. Box is a generic structure, and the type of its field value is T Specify when instantiating //Example: Instantiate Box [int] boxInt:=Box [int] {value: 42} fmt. Println ("Box [int]:", boxInt. Value) Here, the type designation is not required. If the type is not specified, GO

Use LLM to automatically classify Gmail mail summary

Author: matrix Observed: 221 times Published on: April 30, 2025 Classification: odd | No comment »

I have subscribed to many blogs or dev related notifications in my mailbox. Occasionally, if I read them, there are still many unread messages leading to mail accumulation. But I don't want to unsubscribe 🙄 It's perfect to have mail summary service, which can automatically classify and summarize, mark read and label. zapier Zapier's automated workflow configuration can achieve results. Similar to IFTTT in the past, they now mainly provide services for paying users. I found that the component services used need to be charged after the final configuration 😆 Change to another Google Apps script https://script.google.com Google has many services. Apps script integrates various services within Google well. Apps script can write custom scripts to complete the functions I need. The syntax is JavaScript. New Project main.gs //LLM configuration const OPENAI_API_URL=“ https://openrouter.ai/api/v1/chat/completions "; ......

Vscode configuration Maple Mono Chinese and English equal width font

Author: matrix Observed: 2482 times Published on: March 19, 2025 Classification: odd | 2 comments »

https://font.subf.dev/zh-cn/ If the default font of vscode is mixed in Chinese and English, it will be uneven in width, that is, it cannot be aligned completely in the vertical direction. Maple Mono open source font can be displayed perfectly. Environment: macos install Font maple mono nf cn will contain nf icon and Chinese font. You can select the desired font set as required $ brew install --cask font-maple-mono-nf-cn Vscode configuration Add Maple Mono NF CN in front of font setting, and the system will give priority to matching this font. Don't like symbol (==,===,!=...) linking. You can configure linking rules to close:~/Library/Application Support/Code/User/settings. json: ..."editor.fontFamily": "Maple Mono NF CN, Menlo, Monaco, 'Courier New', monospace", "editor.fontLigatures": "'calt', 'ss04', 'ss01', ......

The Docker container mount directory file is not synchronized

Author: matrix Viewed: 930 times Published on: February 28, 2025 Classification: odd | No comment »

If you mount the front-end packaged files with the nginx docker container, the file may not be synchronized after the front-end project is rebuilt, such as this: docker run --restart=always -d --name suworld-nginx \-v /root/suworld-admin/dist/:/data/wwwroot/dist/ \-p 80:80 -p 443:443 nginx There are too many file changes in the dist generated by packaging. Docker file listening events will be lost, causing the dist directory attached to the container to be empty. The container must be restarted to temporarily solve the problem~ Solution It is too troublesome to restart the container every time. Fortunately, the mount parameter delegated can control the file synchronization mode docker run --restart=always -d --name suworld-nginx \-v /root/suworld-admin/dist/:/data/wwwroot/dist/:ro,delegated \-p 80:80 -p 443:443 nginx Note: ro indicates read-only delegat

Goroutine Loop Variable Trap

Author: matrix Viewed: 907 times Published on: January 31, 2025 Classification: Golang | No comment »

It's a classic Golang problem. If you don't pay attention to it, it's a pit Error case package mainimport ( "fmt" "time")func main() { for i := 0; i < 5; i++ { go func() { fmt.Println(i) // Captured the address of variable i} ()} time. Sleep (1 * time. Second)//Wait for all goroutines to finish executing} This is due to Go's closure behavior: closures capture the address of a variable, not its value. Solution 1. Transfer parameters to the closure package mainimport ( "fmt" "time")func main() { for i := 0; i < 5; i++ { go func(n int) { // Use the parameter n fmt. Println (n)} (i)//Pass i as a parameter} time. Sleep (1 * time. Second

Serialization of floating point number NaN JSON in Gin

Author: matrix Viewed: 1064 times Released on: December 24, 2024 Classification: Golang | No comment »

The calculation of divisor 0 was unintentionally put in. Since no panic was found, the page was blank. It seems that it is not captured by global recover~gin console displays Error #01: json: unsupported value: NaN Troubleshooting In breakpoint debugging, we found that json was dealing with problems. The error was pushed to the c.Error of gin, and gin was judged to be a private type error, so there was no panic~/go/pkg/mod/github. com/gin gonic/ gin@v1.10.0 /context.go func (c *Context) Render(code int, r render.Render) { c.Status(code) if !bodyAllowedForStatus(code) { r.WriteContentType(c.Writer) c.Writer.WriteHeaderNow() return } if err := r.Render(c.Writer); err ! = nil { // Pushing error to c.Errors ......

Meaning of the number type after parentheses in MySQL

Author: matrix Viewed: 987 times Published on: November 30, 2024-10 Classification: mysql | No comment »

When designing a database field, I seldom care about the meaning of the parentheses. I generally know that the data storage will not be affected, so I don't care. I was curious when I saw it today. In MySQL, the numbers (5, 11) in INT (5) and INT (11) do not actually limit the storage range or memory use of values, but display the width. This display width is only useful in fields with ZEROFILL This is not limited to the int type, but also includes tinyint, smallint, mediumint, bigint... For example, set the field type int (5) Storage 1 shows 00001 Storage 82 shows 00082 Storage 123456 shows 123456select id, type from table; ******************** 1. row ********************* id: 1type: 123456******************** 2. row ********************* id: 2type: 00008*************......