20240528

Closed port 443 of the VPS instance I created yesterday for now.

It's interesting that though I use the same VPS plan (2 GB RAM, 2 vCPUs, 60 GB SSD) as my Mastodon server, the newly created one for a simple dashboard web application's CPU usage is around 20%. The mastodon one only uses around 2%. I'm not sure if I made some mistakes or Mastodon is highly optimized. Another factor can be OS; I use Amazon Linux for the new one whereas I chose Ubuntu for the existing one. I'll keep an eye on the metricsto see if I get the answer for that.

Port 22, 80, and 443

I know that (although it can be changed,) SSH uses port 22, HTTP uses port 80, and HTTPS uses port 443, but I have little knowledge of them and decided to dig a little bit deeper.

Port 22: SSH (Secure Shell)

SSH Academy: The story of the SSH port is 22

the Secure Shell protocol is a method for securely sending commands to a computer over and unsecured network. SSH uses cryptography to authenticate and encrypt connections between devices[1].

Tatu Ylönen, the inventor of the Secure Shell (SSH) protocol shared an interesting story of how the project got port 22 in the web page.

He was thinking about replacing both telnet (port 23) and ftp (port 21) with SSH and found that port 22 was free.

I figured having that port number might be one of those small things that would give some aura of credibility.

From the early stage of the internet, IANA (Internet Assigned Numbers Authority) has been responsible for allocation and management of port numberes, and Tatu sent an email to ask for the port number, and they just assigned the number to SSH!.

In RFC 1340 published in July 1992, port 22 was unassigned.

ftp-data         20/tcp    File Transfer [Default Data]      [96,JBP]
ftp-data         20/udp    File Transfer [Default Data]      [96,JBP]
ftp              21/tcp    File Transfer [Control]           [96,JBP]
ftp              21/udp    File Transfer [Control]           [96,JBP]
                 22/tcp    Unassigned                           [JBP]
                 22/udp    Unassigned                           [JBP]
telnet           23/tcp    Telnet                           [112,JBP]
telnet           23/udp    Telnet                           [112,JBP]

It continued to be empty in RFC 1700, and port numbers stopped maintained by RFC. RFC 3232 states that RFC 1700 and its predecessors would no longer be updated via RFCs but through the IANA's online registry.

IANA: Service Name and Transport Protocol Port Number Registry

On this registry, port 22 is assigned to ssh (RFC 4251 The Secure Shell (SSH) Protocol Architecture).

Port 80: HTTP, Port 443: HTTPS

Similarly, the port numbers are maintained/managed by IANA.

RFC 2616 Hypertext Transfer Protocol – HTTP/1.1

HTTP communication usually takes place over TCP/IP connections. The default port is TCP 80.

RFC 2818 HTTP Over TLS

When HTTP/TLS is being run over a TCP/IP connection, the default port is 443.

actions/cache in GitHub Actions

Problem: We prepare a test database by running all migrations every time CI runs tests in GitHub Actions. It takes too much time!

Browsed Caching dependencies to speed up workflows

Workflow runs often reuse the same outputs or downloaded dependencies from one run to another. For example, package and dependency management tools such as Maven, Gradle, npm, and Yarn keep a local cache of downloaded dependencies.

At first glance, the action: cache is for caching dependencies and that sort, so dumping database and reusing it is not the expected usage.

I googled the caching of database dump in GitHub Actions, but could not find popular articles about that. Unfortunately, we currently don't have sufficient resources to look into this carefully, I decided not to utilize the action cache for the time being. It seems to be beyond the basic usage, and I don't think we can manage it properly even if we make it work.

However, I found one thing we did not take advantage of: caching pip dependencies

actions/setup-python: Caching packages dependencies

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
  with:
    python-version: '3.9'
    cache: 'pip' # caching pip dependencies
- run: pip install -r requirements.txt

I’ll see if it works -> we use docker in GitHub Actions environment as a walkaround, and the step setup-python does not exist. I will try to use it later.


1974A. Phone Desktop

It's been a while since I solved a problem last time, so I tackled a very easy problem today.

package main

import (
    "fmt"
)

func minRequiredScreens(x int, y int) int {
    var numPagesFilledWithBig int
    if y%2 == 0 {
        numPagesFilledWithBig = y / 2
    } else {
        numPagesFilledWithBig = y/2 + 1
    }

    vacanciesForSmall := numPagesFilledWithBig*15 - y*4
    remainingSmall := x - vacanciesForSmall

    if remainingSmall <= 0 {
        return numPagesFilledWithBig
    } else if remainingSmall%15 == 0 {
        return numPagesFilledWithBig + remainingSmall/15
    } else {
        return numPagesFilledWithBig + remainingSmall/15 + 1
    }
}

func main() {
    var t int
    fmt.Scan(&t)
    for i := 0; i < t; i++ {
        var x, y int
        fmt.Scan(&x, &y)
        fmt.Println(minRequiredScreens(x, y))
    }
}

Poke 800 Yogurt 300 California rools 300 Veggie sticks 400

Total 1800 kcal


TODO:


index 20240527 20240529