Skip to content

Instantly share code, notes, and snippets.

View oxalica's full-sized avatar
😪
tired everyday

oxalica

😪
tired everyday
View GitHub Profile
@oxalica
oxalica / merge_string.rs
Created April 13, 2025 13:13
Test the optimization potential for string literal merging
// [dependencies]
// bstr = "1"
// goblin = "0.9"
// rustc-hash = "2.1.1"
// suff_collections = "2"
use std::cmp::Reverse;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use bstr::{BStr, ByteSlice};
@oxalica
oxalica / chain.rs
Created April 11, 2025 06:59
Singly linked list of mutable references, without heap allocation
use std::fmt::Debug;
// This won't work:
// struct Node<?> { this: usize, next: Option<&? mut Node<?>> }
trait Chain: Debug {
fn out(&mut self) -> Option<(&mut usize, &mut dyn Chain)>;
}
impl Chain for () {
@oxalica
oxalica / iou_direct_socket_close_hang.rs
Last active November 6, 2024 20:15
io-uring closing direct socket does not wake the peer end
// On Linux 6.6.59, x86_64
// Cargo.toml:
// ```toml
// [package]
// name = "testt"
// version = "0.0.0"
// edition = "2021"
// [dependencies]
// io-uring = "0.7.1"
// ```
@oxalica
oxalica / polycircles.py
Created July 23, 2023 17:38
polycircles.py
import math
import cmath
def main():
end = 500
size = 800.0
r = size / 2 / 9
dash = 5
limit = r * 8.7
@oxalica
oxalica / rust-analyzer-outputs.log
Created July 8, 2023 22:19
Rust-analyzer spamming log ` Terminator should be none only in construction`
[ERROR hir_ty::mir::borrowck] Terminator should be none only in construction.
The body:
fn on_did_change_watched_files() {
let _0: ControlFlow<Result<(), Error>, ()>;
let self_1: &mut Server;
let params_2: DidChangeWatchedFilesParams;
let enabled_3: bool;
let interest_4: Interest;
let iter_5: Iter;
let level_6: Level;
@oxalica
oxalica / Cargo.toml
Last active July 7, 2023 18:54
regex-automata 0.3 performance regression
[package]
name = "regex_automata_regression_test"
version = "0.1.0"
edition = "2021"
[dependencies]
criterion = "0.5.1"
once_cell = "1.18.0"
regex-automata = "0.3.1"
regex-automata_0_2 = { package = "regex-automata", version = "0.2.0" }
@oxalica
oxalica / bf_interpreter.rs
Last active June 22, 2023 13:23
Interpreter benchmark
use anyhow::{bail, Context, Result};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use dynasm::dynasm;
use dynasmrt::{AssemblyOffset, DynasmApi, DynasmLabelApi, ExecutableBuffer};
criterion_group!(benches, quine);
criterion_main!(benches);
/// Ref: https://gist.github.com/blahgeek/dd58a29a37e97fdf29f0
const QUINE_SRC: &str = ">>>>++>++>++>++++>+++>+++++>++>++++>++++>+++>+>+++>+>++>++>++++++>+++++>+++>++++>++>+>+++>++++++>+++++>++>++++>++>+++++>++>++++>++>+++++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>+++++>++>+++++>+++>+++>++++++>++>++>++>++++>++++>++>+++++>++>++++>++>+++++>++>+>+>+>+>+>+>+>+>++++>+++>+>+>+>+>+>++>++++++>+++++>+++>+>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++>+>+>+>+>++++>+++>+>+>+>+>++>++++++>+++++>+++>+>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++++++>++++++>++++>+++>+++++>+++>++++>
@oxalica
oxalica / query_reachable.sh
Created February 15, 2023 14:40
Query all reachable nix store paths
#!/usr/bin/env bash
roots_file="$(mktemp)"
find /nix/var/nix/gcroots -type l | xargs realpath 2>/dev/null >"$roots_file"
sqlite3 --readonly --batch db.sqlite <<EOF
CREATE TEMPORARY TABLE roots (path TEXT);
.mode csv
.import $roots_file roots
WITH RECURSIVE closure(id) AS MATERIALIZED (
@oxalica
oxalica / keybase.md
Created September 8, 2022 20:46
keybase.md

Keybase proof

I hereby claim:

  • I am oxalica on github.
  • I am oxalica (https://keybase.io/oxalica) on keybase.
  • I have a public key whose fingerprint is F90F FD6D 585C 2BA1 F13D E8A9 7571 654C F88E 31C2

To claim this, I am signing this object:

@oxalica
oxalica / Main.hs
Created October 16, 2021 09:57
Script serializer
module Main where
import qualified Data.Map as M
import Text.Printf (printf)
import Control.Monad (ap)
data Script a = Script { genScript :: Int -> (Int, [Operation], a) }
instance Functor Script where
fmap f (Script gen) = Script $ fmap f . gen