Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
h4k1m0u / SerenityOS.md
Last active June 3, 2024 18:44
Notes about SerenityOS

File structure

  • Libraries: Userland/Libraries/{LibC, LibGUI...}
  • Games: Userland/Games/{Snake, Solitaire...}
  • Applications: Userland/Applications/{Calculator, Calendar...}

Ninja

SerenityOS is built using CMake and Ninja.

  • Target: output files of the build process (executables, libraries).
  • Use Ninja with CMake: cmake -G Ninja (generates a build.ninja file)
  • Build target: ninja
@h4k1m0u
h4k1m0u / electronics-notes.md
Last active May 28, 2024 17:40
Notes about electronic components

Electronic components

  • Breadboard: Rectangular plastic board with tiny holes to insert electronic components in them.
  • Jump wire: Electrical wire used to interconnect components.
  • Transistor: Used to amplify current, switch on/off the flow of current, and to construct logic gates.
  • Diodes: Allows the flow of current in one direction & blocks the other direction (like a valve).
  • Resistors: Limits the flow of current.
  • Capacitor: Stores and releases electricity (like a temporary battery).
  • LED: emits light when current flows through it.
  • Arduino devices:
  • Sensors: Used to monitor physical phenomena (e.g. temperature, humidity, motion, light...).

C++ syntax

List initialization

Advantage: Doesn't allow narrowing, i.e. the following throws an error:

int i {2.0f};

Direct and copy initialization

Advantage: Doesn't create a copy (practical for objects):

@h4k1m0u
h4k1m0u / USB-notes.md
Last active April 20, 2024 21:26
Notes about USB

Below some notions about USB that could be useful to access USB devices programatically with [libusb]. For more details refer to [USB2.0 specification][usb2-specification].

Terminology

  • Host: Computer.
  • USB device: Peripheral connected to computer via USB.
  • Hub: USB device providing additionnal connections to the USB.
  • IRQ (Interrupt request): a hardware signal from device requesting attention from host.
  • Pipe: Logical abstraction for associating device's endpoint and host's software. There two types of pipes:
    • Stream pipe: data no USB-defined structure.
  • Message pipe: data has a USB-defined structure.
@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 March 10, 2024 14:32
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.

Extensions