Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
h4k1m0u / steganography_read.c
Created August 15, 2024 16:10
Use steganography to read/write a textual password from/to sequential pixels' least-significant bits
#include <limits.h>
#include <string.h>
#include <stdbool.h>
#include <gd.h>
#include "utils.h"
/**
* Print password written beforehand on image with steganography_write.c
* - GD documentation: https://libgd.github.io/manuals/2.1.1/files/preamble-txt.html
@h4k1m0u
h4k1m0u / sierpinski.c
Created July 27, 2024 09:06
Draw a Sierpinski triangle using Chaos game
#include <gd.h>
// C doesn't allow variable length arrays (even using a constant)
#define N_CORNERS 3
typedef struct {
int x;
int y;
} Point;
@h4k1m0u
h4k1m0u / read_bitmap.c
Created July 6, 2024 13:32
Parse bitmap image to find RGB values at given row and column
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/**
* Parse bitmap image to find RGB values at given row and column
* Bitmap format: https://en.wikipedia.org/wiki/BMP_file_format
* Tested input bitmap image saved in Gimp without color space information and in 24bits format
@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 .. &amp;&amp; make -j