Skip to content

Instantly share code, notes, and snippets.

View a10y's full-sized avatar
🇺🇲
DC

Andrew Duffy a10y

🇺🇲
DC
View GitHub Profile
macro_rules! make_encoding_ids_rec {
($count:expr) => {};
($count:expr, $encoding:ident $($tts:tt)*) => {
pub const $encoding: u16 = $count;
make_encoding_ids_rec!(($count+1u16) $($tts)*);
}
}
macro_rules! make_encoding_ids {
($($encodings:ident),*) => {
@a10y
a10y / send-zc.c
Created August 15, 2024 14:39
io_uring zerocopy example
/* SPDX-License-Identifier: MIT */
/* based on linux-kernel/tools/testing/selftests/net/msg_zerocopy.c */
/* gcc -luring -O2 -o send-zc ./send-zc.c */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <errno.h>
#include <error.h>
#include <limits.h>
@a10y
a10y / eclipse.py
Created March 31, 2024 00:50
Marimo notebook of 2024 Solar Eclipse
import marimo
__generated_with = "0.1.76"
app = marimo.App()
@app.cell
def __():
from astropy.time import Time
from astropy.coordinates import EarthLocation, get_sun, get_moon, AltAz
#include <stdlib.h>
#include <arm_neon.h>
#include <arm_acle.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/time.h>
#include <time.h>
@a10y
a10y / leaky.rs
Created March 25, 2024 15:20
Exploring memory leaks with Rust
use std::hint::black_box;
fn main() {
// Leak the reference in a loop.
println!("begin leaking memory");
for _ in 0..10 {
let data = Box::new("hello world".to_string());
let _ = black_box(Box::leak(data)); // Needed to avoid allocs being optimized away by the compiler.
}
println!("done leaking memory");
@a10y
a10y / simple_executor.rs
Created March 25, 2024 02:40
Simple current-thread async executor in Rust
#![feature(noop_waker)]
#![feature(local_waker)]
use std::collections::{HashMap, VecDeque};
use std::fmt;
use std::fmt::Formatter;
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::ptr::null_mut;
@a10y
a10y / pinfun.rs
Created March 24, 2024 19:41
Small exploration of Rust Pinning
use std::fmt;
use std::fmt::Formatter;
use std::marker::PhantomPinned;
use std::pin::{pin, Pin};
struct MyField {
name: String,
name_ptr: Option<*mut String>,
__pinned: PhantomPinned,
}
@a10y
a10y / mqtt_ddot.go
Created December 31, 2023 00:21
MQTT connection for DDOT CCTV Cameras
package main
import (
"bytes"
"fmt"
"github.com/eclipse/paho.mqtt.golang/packets"
)
func main() {
connectPkt := bytes.NewBuffer([]byte{
@a10y
a10y / pathMatcher.ts
Created September 29, 2023 12:10
Path matching in TypeScript to allow type-safe extraction of path params as union type
// ID for the parameter
type ParamId<T> = T;
type ParamKey<Component> = Component extends `:${infer NameWithPattern}`
? `param_${ParamId<NameWithPattern>}`
: never;
type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}`
? ParamKey<Component> | ParamKeys<Rest>
: ParamKey<Path>;
@a10y
a10y / scoop.py
Created September 16, 2023 01:35
# Pull data from SAM.gov, extract all attachments, push to S3 storage
import subprocess
import json
import os
from pathlib import Path
from multiprocessing import Pool