commit 226db86c65867e4de58df4fd4148886f7bb7a933
parent e7457f889685e018fb9b4b6f8c0713913bf06720
Author: ling0x <ling0x@users.noreply.github.com>
Date: Mon, 21 Sep 2026 16:29:53 +0100
simplifications
Diffstat:
7 files changed, 67 insertions(+), 121 deletions(-)
diff --git a/commands/markdown.txt b/commands/markdown.txt
@@ -0,0 +1,12 @@
+lowdown
+
+sudo pacman -S lowdown
+
+View markdown in terminal:
+lowdown -t term README.md | less -R
+
+View markdown in html browser:
+lowdown -t html doc.md > /tmp/doc.html
+
+View markdown in pdf:
+lowdown -t ms | groff -ms -T pdf
+\ No newline at end of file
diff --git a/networking/cybersecurity.txt b/networking/cybersecurity.txt
@@ -0,0 +1,15 @@
+Tools:
+
+- Open Snitch (stop attacks from connection to outside networks)
+- Bandwhich/Nethogs (netwok requests monitoring)
+- WireShark (packet inspection)
+- nftables (setup firewall rules to block all incoming connection)
+- nmap (port scan to confirm/validate firewall rules setup by nftables)
+
+Normally you'd want to use both tcpdump and wireshark:
+
+# on the remote box, no GUI needed
+sudo tcpdump -i eth0 -s 0 -w /tmp/cap.pcap 'port 443'
+
+# locally
+wireshark /tmp/cap.pcap
+\ No newline at end of file
diff --git a/networking/nmap.txt b/networking/nmap.txt
@@ -0,0 +1,4 @@
+Test my nftables:
+
+from another machine, run `nmap -Pn -p- <ip-address>`, then check which
+ports are filtered and which ports are open, in order to validate nftables.
+\ No newline at end of file
diff --git a/references/rules_of_programming.txt b/references/rules_of_programming.txt
@@ -1,6 +1,6 @@
-# Rob Pike's 5 Rules of Programming
-
-## Rob Pike's 5 Rules of Programming
+-------------------------------------------------------------------------------
+Rob Pike's 5 Rules of Programming
+-------------------------------------------------------------------------------
Rule 1. You can't tell where a program is going to spend its time. Bottlenecks
occur in surprising places, so don't try to second guess and put in a speed hack
diff --git a/system_design/case_study/typescript_channels.txt b/system_design/case_study/typescript_channels.txt
@@ -1,134 +1,48 @@
-# TypeScript Channels Pattern
+-------------------------------------------------------------------------------
+TypeScript Channels/Signals Pattern
+-------------------------------------------------------------------------------
-## What It Does
-
-`createChannel` creates a pub-sub mechanism that links a websocket listener to a
-component, allowing updates triggered by network events to propagate to the UI
-without tight coupling between the two.
-
-## The Implementation
+The Implementation
```typescript
-/**
- * Creates a channel/link between a websocket listener and a component.
- * This allows you to keep listeners separate from components but update
- * a component's rune whenever a listener event fires.
- *
- * This is good for simply linkages between a websocket event and a page
- * update or rerender.
- */
-export type Unsubscribe = () => void;
-
export type Channel<T> = {
- subscribe(fn: (v: T) => void): Unsubscribe;
+ subscribe(fn: (v: T) => void): () => void;
next(value: T): void;
};
export function createChannel<T>(): Channel<T> {
const subs = new Set<(v: T) => void>();
return {
- subscribe(fn: (v: T) => void): Unsubscribe {
+ subscribe(fn) {
subs.add(fn);
return () => subs.delete(fn);
},
- next(value: T): void {
+ next(value) {
for (const fn of subs) fn(value);
},
};
}
```
-## How It's Used
-
-### 1. Create a channel with your data type
-
-```typescript
-// Create a channel for tracking websocket messages
-const messageChannel = createChannel<Message>();
-
-// Create a channel for connection status
-const connectionChannel = createChannel<ConnectionStatus>();
-```
-
-### 2. Subscribe in a React component
+Example
```typescript
-function MessageDisplay() {
- const [messages, setMessages] = useState<Message[]>([]);
-
- const unsubscribe = messageChannel.subscribe((msg) => {
- setMessages((prev) => [...prev, msg]);
- });
+const messages = createChannel<string>();
- // Cleanup on unmount - Note the inner function!
- // useEffect accepts an effect function. If that function returns another function,
- // React treats the inner function as the cleanup for that effect.
- // • Mount: React runs the outer function (the effect body).
- // • Unmount: React runs the returned function (the cleanup).
- useEffect(() => () => unsubscribe(), []);
- // Equivalent, more explicit: the *effect* returns a *cleanup* function; React runs it on unmount
- // (and before re-running the effect if deps change — here `[]` means mount once, cleanup on unmount).
- // useEffect(() => {
- // return () => {
- // unsubscribe();
- // };
- // }, []);
+// producer: a websocket handler that knows nothing about the UI
+ws.onmessage = (e) => messages.next(e.data);
- return <div>{messages.map((m) => <div key={m.id}>{m.text}</div>)}</div>;
-}
+// consumer: a component that knows nothing about the websocket
+useEffect(() => messages.subscribe((m) => setLog((p) => [...p, m])), []);
```
-### 3. Emit from your websocket handler
-
-```typescript
-// WebSocket connection established
-ws.onopen = () => {
- connectionChannel.next({ type: "connected" });
-};
-
-// New message received
-ws.onmessage = (event) => {
- const msg = JSON.parse(event.data);
- messageChannel.next(msg);
-};
-
-// Connection closed
-ws.onclose = () => {
- connectionChannel.next({ type: "disconnected" });
-};
-```
-
-### 4. Benefits
-
-**Decoupling**
-
-- WebSocket logic knows nothing about React components
-- Components don't need to import or know about the websocket
-- Easy to swap implementations (e.g., change backend without touching UI)
-
-**Testability**
-
-- Components test with a mock channel instead of real websocket
-- Handlers test without starting a server
-
-**Reusability**
-
-- Same channel used by multiple components
-- Same handler used with different channels
-
----
-
-## Pattern: Channel Listener Pattern
-
-```
-┌─────────────┐ Channel Subscribe ┌─────────────┐
-│ WebSocket │ ────────────────────────────► │ UI │
-│ Handler │ │ Component │
-└─────────────┘ └─────────────┘
- │ │
- ▼ ▼
- .next(message) subscribe(fn)
-```
+Explanation
-The pattern decouples event sources from event consumers using a pub-sub
-channel.
+A channel is just a set of callbacks plus two operations: `subscribe` adds one
+and hands back a function that removes it, and `next` calls every callback with
+a value. That is the whole primitive — no buffering, no replay, no async. Its
+value is decoupling: the producer only knows how to emit, the consumer only
+knows how to listen, and neither imports the other. Unsubscribing is the one
+thing you must not forget, which is why `subscribe` returns the cleanup
+function directly — in React, returning it from `useEffect` is all the teardown
+you need.
diff --git a/system_design/design_patterns/abstraction.txt b/system_design/design_patterns/abstraction.txt
@@ -1,4 +1,6 @@
-# Abstraction
+-------------------------------------------------------------------------------
+Abstraction
+-------------------------------------------------------------------------------
The use of abstractions is one of the most important concepts in computer
science. For example, one aspect of good programming practice is to formulate a
@@ -8,9 +10,9 @@ Different programming languages provide different forms and levels of support
for abstraction, such as Rust's trait definitions and module system with
explicit pub visibility boundaries.
-## Abstractions provided by a computer system
-
-<img src="/whiteboards/abstraction_of_computer_system.png" alt="Abstraction" width="100%">
+-------------------------------------------------------------------------------
+Abstractions provided by a computer system
+-------------------------------------------------------------------------------
We are probably familiar with several of the abstractions seen in computer
systems. On the processor side, the instruction set architecture provides an
@@ -30,6 +32,4 @@ computer, including the operating system, the processor, and the programs. The
idea of a virtual machine was introduced by IBM in the 1960s, but it has become
more prominent recently as a way to manage computers that must be able to run
programs designed for multiple operating systems (such as Microsoft Windows, Mac
-OS X, and Linux) or different versions of the same operating system.
-
-<img src="/whiteboards/five_abstraction_levels.png" alt="Abstraction" width="100%">
+OS X, and Linux) or different versions of the same operating system.
+\ No newline at end of file
diff --git a/system_design/design_patterns/decomposition.txt b/system_design/design_patterns/decomposition.txt
@@ -1,3 +0,0 @@
-# Decomposition
-
-