Skip to content

Instantly share code, notes, and snippets.

@alepez
alepez / gist:6e422d83ae26599be03f0ed8a05d546f
Created November 16, 2024 14:27
coding-gym-ice-cream-parlor-boilerplate
use std::{
cmp::{max, min, Ordering},
io::BufRead as _,
};
fn solve(m: usize, flavors: Vec<usize>) -> (usize, usize) {
(1, 1)
}
fn main() {
@alepez
alepez / kubectl-remote-port-forwarding.md
Created September 25, 2024 14:13
kubernetes k8s kubectl remote port forwarding

You are debugging a program which is running in a container.

The program usually connects to some remote tcp port (e.g. for it's output, telemetry, logging...).

For faster debugging, you want to make it connect to a service which is running locally on your workstation.

Usually, you can do this with ssh remote port forwaring. But you're on k8s and you don't have access to the container directly with ssh.

Currently (2024), kubectl can do local port forwarding (like ssh -L), but it does not support remote port forwarding (like ssh -R).

// 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: