Skip to content

Instantly share code, notes, and snippets.

// You have an API which requires functions to be called in a defined order
// This may be a C API
mod no_order_constraint {
pub fn one() {
println!("one");
}
pub fn two() {
println!("two");
}
@alepez
alepez / build.sh
Last active November 22, 2022 17:52
Build clang libcxx libcxxabi instrumented with msan
wget https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-14.0.6.tar.gz
tar zxf llvmorg-14.0.6.tar.gz
cd llvm-project-llvmorg-14.0.6
rm -rf build
mkdir -p build
cd build
cmake \
-G Ninja \
@alepez
alepez / sdl-example.cpp
Created September 21, 2022 13:54
SDL Example C++
/// Simple DirectMedia Layer Example
/// If everything is correctly installed, you should see a black window
/// which is gradually filled with white, starting from the top.
#include <SDL2/SDL.h>
int main() {
auto sdl_init_result = SDL_Init(SDL_INIT_VIDEO);
if (sdl_init_result != 0) {
return 1;
@alepez
alepez / run-linux-arm-executable-inside-docker-on-x86-host.md
Created January 19, 2022 09:37
Run Linux ARM executable inside Docker on x86 host

Say that you have compiled an executable for a Linux ARM system and you want to test it inside a Linux x86 system. Docker is able to use qemu to enable execution of different multi-architecture containers.

Execute the register script that registers binfmt_misc handlers for all supported processors except the current one in it when running the container.

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
#include <stdio.h>
// a is an input parameter
// b is an input parameter
// return the result
int divide_1(int a, int b) {
return a / b;
}
// But what if we need to return an error code?
@alepez
alepez / nixos-encrypted-zfs.md
Created June 21, 2021 12:57
nixos on fully encrupted zfs

NixOs neon

Partitions

DISK=/dev/disk/by-id/ata-VBOX_HARDDISK_VBf3bca3fc-20a6ea2d
parted -s ${DISK} -- mklabel gpt
parted -s ${DISK} -- mkpart primary 512MiB -8GiB
parted -s ${DISK} -- mkpart primary linux-swap -8GiB 100%
parted -s ${DISK} -- mkpart ESP fat32 1MiB 512MiB
@alepez
alepez / nmea2kutils.sh
Created March 3, 2021 11:17
nmea2kutils
#!/bin/bash
init() {
ip link set can0 type can bitrate 250000
ip link set can0 up
}
rawdump() {
candump can0
}

Unmanaged C code:

typedef void(read_fun_t)(void* user_data, const char* data, int data_len);

int native_consume_all(native_handler handler, void* user_data, read_fun_t* read_fun);

Managed C++ code:

@alepez
alepez / VBoxFixWinSize.md
Created April 8, 2020 08:38
i3wm fix virtualbox resolution

VirtualBox gust screen resolution doesn't work well under i3wm, sometime it get stuck at some strange resolution.

This script can fix the window size.

From the guest side, we use VBoxManage to tell the guest that a new resolution is available.

Window is made floating, then the border is removed (it count as width/height), then the window is resized.

@alepez
alepez / nmea2kutils.sh
Created July 31, 2019 08:53
nmea2kutils
#!/bin/bash
init() {
ip link set can0 type can bitrate 250000
ip link set can0 up
}
rawdump() {
candump can0
}