Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@folkertdev
folkertdev / main.rs
Created May 19, 2023 22:16
A rust example that writes a message with ancillary data (a control message) and then reads it from the error queue
use std::io::{Error, ErrorKind};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use std::os::unix::io::AsRawFd;
use tokio::io::unix::AsyncFd;
use tokio::io::Interest;
pub(crate) fn cerr(t: libc::c_int) -> std::io::Result<libc::c_int> {
match t {
@folkertdev
folkertdev / init.vim
Last active August 10, 2023 18:38
public init.vim
let mapleader=","
" unset the mouse
set mouse=
au BufRead,BufNewFile *.elm set filetype=elm
" copy to system clipboard
" see http://askubuntu.com/questions/347519/unable-to-copy-from-vim-to-system-clipboard
set clipboard=unnamedplus
@folkertdev
folkertdev / ioctl_ethtool.rs
Created July 20, 2022 13:18
Get timestamp capabilities of a network interface using ioctl in rust
#[repr(C)]
#[derive(Default)]
struct ethtool_ts_info {
cmd: u32,
so_timestamping: u32,
phc_index: u32,
tx_types: u32,
tx_reserved: [u32; 3],
rx_filters: u32,
rx_reserved: [u32; 3],
@folkertdev
folkertdev / bad_morphic
Created February 6, 2022 20:00
Roc+Morphic join point problem
program {
mod "UserApp" {
type "jY\xe2\xcd\xd2\xfd/t" = type_10 where {
type type_0 = "UserApp"::"jY\xe2\xcd\xd2\xfd/t";
type type_1 = "UserApp"::"jY\xe2\xcd\xd2\xfd/t";
type type_2 = (type_0, type_1);
type type_3 = ();
type type_4 = (type_3);
type type_5 = heap_cell;
type type_6 = (type_5);
@folkertdev
folkertdev / Cargo.toml
Created September 9, 2021 20:45
Wasmer bug
[package]
name = "wasmer-bug"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
wasmer = "2.0.0"
wasmer-wasi = "2.0.0"
@folkertdev
folkertdev / bicubic.c
Created September 2, 2021 13:46
bicubic interpolation in C
float cubic_interpolate(
float p0, float p1, float p2, float p3, float ratio, float cubic_coeff_a) {
float cca = cubic_coeff_a;
float coeffects_0 = ((cca * (ratio + 1) - 5 * cca) * (ratio + 1) + 8 * cca) * (ratio + 1) - 4 * cca;
float coeffects_1 = ((cca + 2) * ratio - (cca + 3)) * ratio * ratio + 1;
float coeffects_2 = ((cca + 2) * (1 - ratio) - (cca + 3)) * (1 - ratio) * (1 - ratio) + 1;
float coeffects_3 = ((cca * ((1 - ratio) + 1) - 5 * cca) * ((1 - ratio) + 1) + 8 * cca) * ((1 - ratio) + 1) - 4 * cca;
@folkertdev
folkertdev / bilinear.c
Created September 2, 2021 13:42
bilinear interpolation in C
/// Sources:
//
// - https://chao-ji.github.io/jekyll/update/2018/07/19/BilinearResize.html
void bilinear_interpolation(float *data, uint32_t input_width,
uint32_t input_height, uint32_t output_width,
uint32_t output_height, float *output) {
float x_ratio, y_ratio;
if (output_width > 1) {
x_ratio = ((float)input_width - 1.0) / ((float)output_width - 1.0);
@folkertdev
folkertdev / setjmplongjmp.md
Created August 29, 2021 10:38
setjmp/longjmp in LLVM IR

Using setjmp/longjmp in LLVM IR

Using the setjmp and longjmp LLVM instrinsics did not work as expected. There is an undocumented difference between the C implementation and the LLVM intrinsics.

setjmp/longjmp in C

setjmp/longjmp (sjlj for short) is a mechanism in C that is used to handle errors, potentially deep in the call stack.

With setjmp, the current stack frame is saved to some location in memory. Then down the line a lngjmp can jump back to where setjmp was called. The stack is then restored, and the return value of the setjmp call is different between the first call, when normal execution brought use there, and a subsequent call that is the result of a jump. The different return value allows us to distinguish how we got to the setjmp and act accordingly.

@folkertdev
folkertdev / Issue4.elm
Created December 30, 2019 19:00
bug in elm-image
module Issue4 exposing (suite)
import Bytes exposing (Bytes)
import Bytes.Encode as Encode
import Expect
import Image
import Test exposing (test)
suite =
@folkertdev
folkertdev / villages.smv
Last active January 7, 2019 10:47
nusmv villages
MODULE main
VAR
truck : 0..320;
location : { a, b, s,c };
nextLocation : { a, b, s,c};
stockAtA : -1..120;
stockAtB : -1..120;
stockAtC : -1..200;
DEFINE