Hegwin.Me

In silence I feel full; With speech I sense emptiness.

The Proof of Stirling's approximation

Stirling公式的证明

When describing the time complexity of an algorithm, we often use Big O notation to describe the growth of computation with the size of the problem. For a factorial $n!$ of positive integers, this time complexity is $O(n)$ if a general recursive implementation is used, which represents a linear increase in computational effort as $n$ grows. When $n$ is large,...

The Proof of Wallis' formula

Wallis公式的证明

I read a question on Zhihu "Is there a problem with a result containing 'π' but completely unrelated to the circle?", and I thought of Wallis' formula, which was proposed by John Wallis (1616-1703). The main application still lies in the proof of Sterling's formula. Although Wallis' formula itself seems to be an ordinary infinite product, but his result expresses...

HTTPS Certificate and CAA

关于HTTPS证书和CAA

Last time I talked about using Caddy as a reverse proxy HTTP server, so I don't have to worry about HTTPS certificates, but today I ran into a worrying thing. In addition to the web app of the blog you're reading, I also have some other gadgets hanging on the secondary domain name, such as [wow.hegwin.me](https://wow.hegwin.me/pets) is a warcraft pet...

Use Caddy as reverse proxy server with free HTTPS certificate

使用Caddy作为反向代理服务并获取HTTPS证书

Because of the data loss caused by the previous server OS image replacement, my blog service was stopped for several months, and in the middle of it, my father had a stroke, and I took care of it in my hometown for more than 4 months, so I haven't had time to take care of my personal blog. Today finally...

Windows 10 upgrade from Windows 7 dual boot with Ubuntu

Windows7 + Ubuntu 双系统下,如何升级到 Windows 10

I have a desktop computer purchased in 2014. It was a dual system of Windows 7 + Ubuntu 14.04 and I had been considering upgrading Windows 7 to Windows 10 for a long time, but there were potential problems with the process that made me hesitate to do so. I finally took the plunge and upgraded it recently, and I'll...

Format Your Output in Terminal with Ruby

Ruby命令行格式化输出

If we want to output content in the command line, generally speaking, Ruby basic methods are enough, such as `puts`, `print`, and `sprintf`; but if we want to output color in the terminal, table, and progress bar, etc., it will be more difficult to achieve. Here, I want to share gems that I feel good using in this situation: -...

Execute System Commands in Ruby

在Ruby中运行系统命令

There are several ways to invoke system commands in Ruby: 1. Backquotes `` or `%x()`, 2. The `system` method, 3. The `File` class, 4. The Open3 lib. The difference between backquotes and `%x()` and `system` is that: `system` only returns true/false; while `%x` returns the stdout of the command when the command execution succeeds, and an empty string `""` when...

Run specific version of bundler

运行特定版本的 bundler

Ruby Little (Useless) Trick (Skill) series. When you have two versions of bundler installed at the same time, say 2.0.1 and 1.17.2, by default `bundle exec` and other commands use the latest version of bundler; If you are maintaining an old program, then you may run into this magic problem due to the incompatibility of bundlers like this: ``` Bundler...

Hello World in Rust

第一个Rust程序

When learning a new programming language, there is a tradition of writing a simple program that outputs "Hello, World!" on the screen at first. Installation steps can be easily found on the official rust-lang website. Rust is a language that uses the `rustup` tool to manage versions and toolchains. In the official "Getting Started", we can see that the installation...

Different methods in Ruby to manipulate directories and files

Ruby中目录和文件操作的几种方式

Creating a directory: Method 1: You can create a directory using Dir.mkdir with an optional parameter to mark the permissions of the directory. For example, if I want to create a `ruby` subdirectory in the /Users/hegwin/Workspace directory, I can do this Dir.mkdir('/Users/hegwin/Workspace/ruby') After normal creation, Dir.mkdir will return the integer 0. This method is similar to the Linux command `mkdir`,...