Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
h4k1m0u / TCP-IP-model.md
Created April 13, 2024 18:46
Notes about OSI and TCP/IP models

OSI model

For systems interconnections in a network, and has 7 layers (from top to bottom):

  • Application: Closest to user, e.g. HTTP, FTP...
  • Presentation: Encryption/Decryption, Compression/decompression, e.g. jpeg, mpeg...
  • Session: e.g. sync file transfers with checkpoints (to avoid restarting from beginning on failure).
  • Transport: Flow and error control, e.g. TCP, UDP
  • Network: breaks/assembleds data into packets, routing, e.g. IP
  • Data link: connects devices that are physically in the same network, e.g. Ethernet, MAC
  • Pyhsical: bit (raw data), e.g. cables
@h4k1m0u
h4k1m0u / Soundfront2-notes.md
Last active April 11, 2024 20:31
Notes on the soundfront2 and midi formats

SF2 format

  • File format (binary) storing multiple instruments.
  • Stores instrument samples to play MIDI.
  • Samples are stored:
    • For each note of an instrument (e.g. all piano keys).
    • Possibly multiple velocities by key (how hard the note was struck).
  • [Polyphone][polyphone] can be used to read sf2 files.
  • [soundfont-fluid][soundfont-fluid] and [freepats-general-midi][freepats-general-midi] provide free samples in sf2 format (installed to /usr/share/soundfonts/).
  • Jack2: is an audio server like pulseaudio and alsa but professional audio production thanks to its low latency:
@h4k1m0u
h4k1m0u / Raylib-notes.md
Created April 6, 2024 11:11
Very basic 2D game example made with Raylib

Dependencies

$ sudo pacman -Sy raylib

How to run

$ mkdir build
$ cd build
$ cmake .. && make -j
@h4k1m0u
h4k1m0u / Miniaudio-notes.md
Created April 6, 2024 10:46
Play a sound corresp. to a synthetic note (from sine wave) from soundcard using miniaudio
  • Modes:
    • Playback: Emit sound from speaker by writing data to output buffer (in callback).
    • Capture: Extract sound from microphone by reading data from input buffer (in callback).
  • Sample: Single unit of audio data (when format = f32, a sample is a float in [-1, 1]).
  • Frame (PCM Frame): Groups of samples having as many samples as the number of channels (stereo: 1 frame = 2 samples, mono: 1 frame = 1 sample).
  • Sample rate: Number of frames processed each second expressed in Hz (e.g 44100 Hz).
  • Device: Abstraction for a physical device.
  • Callback: Function used to deliver data to/from the device async.
  • Data source: Used for retrieving audio data from a source (e.g. decoder, waveform for generrating sine waves...).
  • Decoder: Used for reading audio files (wav, mp3, flac).
@h4k1m0u
h4k1m0u / Box2D-notions.md
Last active March 25, 2024 22:30
Notions in Box2D-2.4 taken from its HelloWorld example

From the [hello world example][hello-world]:

  • Coordinate system: y-axis points upwards and gravity downwards.
  • Units: meters, kilograms, and seconds
  • Area density: mass / area, and expressed in kg/m^2
  • Fixture: Used to attach a shape to the body
  • Shape: its coords are local to the body
  • Static body: mass ~> oo (stored = 0 in box2d)
  • Dynamic body: moves in response to forces
  • FPS: 60 frames/sec = freq => delta_t = 1/60 sec
  • Constraint solver: Iterates over constraints a number of times (two phases: velocity and position phases)
@h4k1m0u
h4k1m0u / Gnome-notions.md
Last active May 5, 2025 20:43
Notions about Gnome to develop extensions in GJS (from https://gjs.guide/extensions/)

D-Bus

  • Interprocess communication (IPC) system for apps.
  • Runs as a service.
  • Two buses:
    • System bus: e.g. to notify about hardware connect/disconnect. Its service: systemctl status dbus.
    • Session bus: Specific to user sessions, e.g. communication between Gnome components. Its service: systemctl --user status dbus.
  • dbus-run-session <cmd>: Starts a new session bus and run cmd in that session (to have access to the session dbus for IPC):
    • e.g gnome-shell --nested: Start Gnome within an existing session (for dev. & testing) without affecting the primary UI.
@h4k1m0u
h4k1m0u / Conan2-Test.md
Last active April 3, 2024 18:25
Script using Conan2 as a package manager for third-party libraries

Setup

  • Conan2 was installed on Archlinux by building its [AUR package][conan-aur].
  • We follow Conan's [official docs][conan-getting-started] to setup CMake to use Conan:
$ conan install conanfile.txt --output-folder=build --build=missing
$ cd build
$ cmake -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" ..
$ make -j
@h4k1m0u
h4k1m0u / count_occurrences.sh
Last active July 22, 2023 16:44
Count occurrences of each number in a json file
cat file.json | sed -e 's/[^0-9]//g' -e '/^$/d' | sort | uniq -c
@h4k1m0u
h4k1m0u / Youtube.md
Last active May 8, 2025 18:03
Youtube

Yewtube

Query Youtube from a TUI & play videos using MPV

Installation

$ pip install yewtube
$ vim .bashrc
    export PATH="$PATH:...:/home/hakim/.local/bin"
$ yt
@h4k1m0u
h4k1m0u / Unity.md
Last active May 13, 2023 19:21
Basic notions in Unity

Unity editor

  • Project (bottom): Game assets (sprites, sounds, scripts, fonts...)
  • Hierarchy (left): Assets in scene (i.e. current level)
  • Inspector (right): Edit game object (position, rotation, scale, and to add components)
  • Coordinate system: Left-handed with y-up

Notions

  • Game objects: Scene objects (characters, props, scenery, camera...)
  • Components: Functional part of a game object, e.g. SpriteRenderer (A game objects can have multiple components)
  • Script class: Blueprint for creating a new component