TIL
content
communication & networking
- a good mental model to think about networking is, it’s essentially just communication
- when learning about server-client stuff, e.g., json RPC, i kept thinking it’s on top of http.
- it could be http, but http here is just a mode of transport.
- and json rpc is just a specification defining a messaging format, a way of communication
- json rpc is transport-agnostic, it can run on websocket, TCP, even stdin/out
what is a tab /t
-
What a tab means
- A tab is not a visible glyph and not a fixed number of spaces.
- It means: advance the cursor to the next tab stop
-
Tabs are column-relative: its visual width depends on the current column.
- Example with tab stops every 4 columns:
- at column 0, \t = 4 spaces
- at column 1, \t = 3 spaces
- at column 2, \t = 2 spaces
- at column 3, \t = 1 space
- Example with tab stops every 4 columns:
parsing yaml might cause security vulnerabilities
- yaml allows code execution in parsing
- yaml can have deep nested attributes, causing parser to consume compute resources and leading to DoS
in less, type / to search, then press -i to toggle case sensitivity
- e.g.,
/pathfinds allpath, pressing-ifindspath/Path/PATH/....
iptables is just a program to configure firewall rules, it’s not a different thing from firewall
- it’s deprecated but still widely used,
nftablesis the successor.
firewalld is written in python
TTY options makes the process think it’s running in a terminal, which enables proper terminal behavior
- coloring, formatting, cursor positioning, ctrl-z/c (signal handling)
docker exec -iopens interactive stdindocker exec -itgives stdin and above mention stdout benefits
a process can be disowned
- run
sleep 1000followed bydisown, nowsleepwill persist after shell is closed disownremoves child process from shell’s child process table, so when shell exits, said child process will not receiveSIGHUP
Dict key in Python can’t be mutable object because of hash
- key is being hashed with a salt when a key is added to a dict
- dict key can’t be immutable object with mutable object inside either, e.g.,
(1, [2, 3]) - The Python Dictionary Object — A Peek Under the Hood
python’s self is just a convention, any word works
class MyClass:
def __init__(me, name):
me.name = name
def get_name(hi):
return hi.name
c = MyClass("hi")
print(c.get_name())Go’s go keyword is analogous to & at the end of shell commands
-
Go’s
gokeyword is analogous to&at the end of shell commandsgo MyFunc()in Go ~=MyFunc() &in shell scripts
-
go MyFunc()in Go ~=MyFunc() &in shell scripts
SIGHUP
- signal, hang up
- it’s usually used a signal to process to reset, reload config
- can be caught, or ignore by the program
SIGTERM→ graceful shutdownSIGKILL→ force stop
localhost, 127.0.0.1, and 0.0.0.0
-
localhostmaps to127.0.0.1and::1(IPv6)- the three are the same thing
-
127.0.0.1is the loopback address- it means “only this machine”
- if something is on
127.0.0.1:5173, it’s only accessible from this machine
-
0.0.0.0is the wildcard address- it means all IP addresses
-
more practical examples
- a remote machine has a web app on
127.0.0.1:8080, it can’t only be accessed from the machine - a remote machine has a web app on
0.0.0.0:8080, and the machine has a tailscale IP of100.84.151.31, the web app can be accessed from100.84.151.31:8080
- a remote machine has a web app on
-
when i run
bun run dev --host 0.0.0.0, i see:
➜ Local: http://localhost:5173/
➜ Network: http://10.65.117.113:5173/
➜ Network: http://100.84.151.31:5173/
➜ Network: http://192.168.64.1:5173/
➜ press h + enter to show help
-
which means, the machine has 3 different network interfaces, and they can all access the web app
-
SIGHUP- signal, hang up
- it’s usually used a signal to process to reset, reload config
- can be caught, or ignore by the program
SIGTERM→ graceful shutdownSIGKILL→ force stop
-
SIGHUP- signal, hang up
- it’s usually used a signal to process to reset, reload config
- can be caught, or ignore by the program
SIGTERM→ graceful shutdownSIGKILL→ force stop