Skip to content

Instantly share code, notes, and snippets.

@folkertdev
folkertdev / comparison.svg
Created June 26, 2024 08:50
implicit coordinates are relative zero
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@folkertdev
folkertdev / example.py
Created June 18, 2024 09:37
tsp async pyo3 experiment
from dataclasses import dataclass
import tsp_python
from tsp_python import AsyncStore, OwnedVid, ReceivedTspMessageVariant, FlatReceivedTspMessage
class ReceivedTspMessage:
@staticmethod
def from_flat(msg: FlatReceivedTspMessage):
match msg.variant:
case ReceivedTspMessageVariant.GenericMessage:
@folkertdev
folkertdev / main.rs
Created June 14, 2024 14:48
PEXT experiment for lzma/xz variable width integer decoding
pub fn decode2(buf: &[u8], size_max: usize, num: &mut u64) -> usize {
let number = unsafe { core::ptr::read_unaligned(buf.as_ptr().cast()) };
let bits = unsafe { core::arch::x86_64::_pext_u64(number, 0x7F7F_7F7F_7F7F_7F7Fu64) };
let bytes_used = (number & !0x7F7F_7F7F_7F7F_7F7Fu64).count_ones();
*num = bits | (buf[8] as u64) << 56;
(size_max > 0) as usize + bytes_used as usize
}
@folkertdev
folkertdev / README.md
Created March 9, 2024 17:06
Creating a zip file with a unix extra field

run and validate with

rm -f extrafield.zip && python add_unix_extra_field.py && zipinfo -v extrafield.zip

this should show

Archive:  extrafield.zip
@folkertdev
folkertdev / crc32.c
Created February 19, 2024 14:43
a vectorized crc32 implementation (from the zlib-ng repository)
// compile with
//
// $ clang -shared -o libcrc32.so -Wall -Werror -fpic -march=native -O3 crc32.c
//
// This command only works on x86_64 systems that support the pclmulqdq instruction.
#include <immintrin.h>
#include <wmmintrin.h>
#include <smmintrin.h> // _mm_extract_epi32
#include <inttypes.h>
#include <stdio.h>
@folkertdev
folkertdev / main.roc
Created July 19, 2023 16:43
brainfuck interpreter using tail calls
app "brainroc"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br",
}
imports [
pf.File,
pf.Path,
pf.Stdout,
pf.Task,
]
@folkertdev
folkertdev / main.roc
Created July 19, 2023 12:05
brainroc
app "brainroc"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br",
}
imports [
pf.File,
pf.Path,
pf.Stdout,
pf.Task,
]
@folkertdev
folkertdev / mio_error_event.rs
Created June 7, 2023 19:42
mio responding to a message arriving on the error queue (EPOLLPRI)
use std::net::SocketAddr;
use std::os::unix::io::AsRawFd;
use std::thread;
use mio::net::UdpSocket;
use mio::{Events, Interest, Poll, Token};
const SOCKET_TOKEN: Token = Token(0);
fn main() {
@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