20240617

chatgpt.com/backend-api stopped responding…

It seems I'm not eligible for DL online renewal as it's too early? will wait for a few months to get the notice.

AWK

math.utah.edu: AWK Language Programming - Getting Started with awk

The basic function of awk is to search files for lines (or other units of text) that contain certain patterns. When a line matches one of the patterns, awk performs specified actions on that line. awk keeps processing input lines in this way until the end of the input files are reached.

Programs in awk are different from programs in most other languages, because awk programs are data-driven; that is, you describe the data you wish to work with, and then what to do when you find it. Most other languages are procedural; you have to describe, in great detail, every step the program is to take. When working with procedural languages, it is usually much harder to clearly describe the data your program will process. For this reason, awk programs are often refreshingly easy to both write and read.

When you run awk, you specify an awk program that tells awk what to do. The program consists of a series of rules… Each rule specifies one pattern to search for, and one action to perform when that pattern is found.

Syntactically, a rule consists of a pattern followed by an action. The action is enclosed in curly braces to separate it from the pattern. Rules are usually separated by newlines. Therefore, an awk program looks like this:

pattern { action }
pattern { action }
...

There are several ways to run an awk program. If the program is short, it is easiest to include it in the command that runs awk, like this:

awk 'program' input-file1 input-file2 ...

where program consists of a series of patterns and actions, as described earlier.

When the program is long, it is usually more convenient to put it in a file and run it with a command like this:

awk -f program-file input-file1 input-file2 ...

math.utah.edu: AWK Language Programming - Glossary

Pattern: Patterns tell awk which input records are interesting to which rules. A pattern is an arbitrary conditional expression against which input is tested. If the condition is satisfied, the pattern is said to match the input record. A typical pattern might compare the input record against a regular expression.

Action: A series of awk statements attached to a rule. If the rule’s pattern matches an input record, awk executes the rule’s action. Actions are always enclosed in curly braces.

OK now it's time to write my first awk program. I have this Python file c.py created yesterday.

def convert_time(s: str) -> str:
    hh, mm = s.split(":")
    if hh == "00":
        return f"12:{mm} AM"
    elif hh == "12":
        return f"12:{mm} PM"
    elif 0 < int(hh) < 12:
        return f"{hh}:{mm} AM"
    else:  # 12 < int(hh) < 24
        return f"{str((int(hh) - 12)).zfill(2)}:{mm} PM"


for _ in range(int(input())):
    s = input()
    print(convert_time(s))

An AWK program '/return/ {print}' prints all the return statements in the file.

$ awk '/return/ {print}' c.py
        return f"12:{mm} AM"
        return f"12:{mm} PM"
        return f"{hh}:{mm} AM"
        return f"{str((int(hh) - 12)).zfill(2)}:{mm} PM"

As I browsed gnu.org: Concatenation (The GNU Awk User’s Guide), it's possible to tweak the output.

$ awk '/return/ {print "found return statement: " $0}' c.py
found return statement:         return f"12:{mm} AM"
found return statement:         return f"12:{mm} PM"
found return statement:         return f"{hh}:{mm} AM"
found return statement:         return f"{str((int(hh) - 12)).zfill(2)}:{mm} PM"

Printing only the return values

$ awk '/return/ {print $2}' c.py
f"12:{mm}
f"12:{mm}
f"{hh}:{mm}
f"{str((int(hh)

Now, I have very basic knowledge of awk. Though Python scripts might be more straightforward solutions in most cases, performing simple actions with minimal setup is cool, might be useful when troubleshooting servers.

1948A. Special Characters

for _ in range(int(input())):
    n = int(input())

    if n % 2 == 1:
        print("NO")
    else:  # n % 2 == 0:
        s = ""
        for i in range(n // 2):
            s += "AA" if i % 2 == 0 else "BB"
        print("YES")
        print(s)

Network File System (NFS)

Network File System - IBM Documentation

The Network File System (NFS) is a mechanism for storing files on a network. It is a distributed file system that allows users to access files and directories located on remote computers and treat those files and directories as if they were local.

Amazon Web Services: Using Network File System to mount EFS file systems

Amazon Elastic File System (EFS) is an implementation of the Network File System (NFS) protocol. Specifically, Amazon EFS supports NFSv4.0 and NFSv4.1 (recommended) to mount the file system and use it with various NFS clients.

When using EFS with Amazon EKS (or other services such as EC2), the NFS protocol is used to mount the EFS file system to the pods in EKS, enabling persistent and shared storage across multiple pods. It seems I don't need to worry about the NFS clients when using Amazon EFS, as it wraps the implementation.

cf. Amazon EFS (20240612)

DNS Propagation

Lenovo US - How does a DNS Resolver Work and How to Set it Up

A DNS server is a broader term that encompasses various types of servers involved in the DNS system. A DNS resolver is a specific type of DNS server responsible for translating domain names into internet protocol (IP) addresses.

Adding A/AAAA records

DNS resolvers will not query the A/AAAA records unless they receive a request for that information.

A client initiates a request to access the domain and checks its local DNS cache for it. If the record is not in the cache or has expired, it forwards the request to a DNS resolver.

When a DNS resolver (ISP or public DNS service such as Google DNS) receives the request, it checks its cache. Same as the client, it queries the authoritative DNS server for the domain to obtain the latest A/AAAA records.

Cloudflare | DNS server types

The authoritative nameserver is usually the resolver’s last step in the journey for an IP address. The authoritative nameserver contains information specific to the domain name it serves (e.g. google.com) and it can provide a recursive resolver with the IP address of that server found in the DNS A record, or if the domain has a CNAME record (alias) it will provide the recursive resolver with an alias domain, at which point the recursive resolver will have to perform a whole new DNS lookup to procure a record from an authoritative nameserver (often an A record containing an IP address)

Updating A/AAAA records

When you update the A or AAAA records, DNS resolvers will continue using the cached old IP address until the TTL expires. After TTL expiration, resolvers will query the authoritative DNS server for the updated record.

I know the big picture, but am not familiar with the terminologies: DNS recursive resolver (DNS recursor), DNS root nameserver, TLD nameserver, and authoritative nameserver. will try to understand them tomorrow. I'm sleepy now…


Bagels 800 Yogurt 200 Protein shake 200 Inari 500

Total 1700 kcal


TODO:


index 20240616 20240618