Skip to content

Instantly share code, notes, and snippets.

@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
@oxalica
oxalica / tuple_getter.rs
Last active March 25, 2021 19:48
Extract value from nested tuple by given type
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=440c65898633c8dba89e0a036f049e95
use std::ops::Deref;
use std::marker::PhantomData;
#[repr(transparent)]
struct Getter<A, T>(T, PhantomData<A>);
impl<A, T, U> Deref for Getter<A, (T, U)> {
type Target = Getter<A, U>;
fn deref(&self) -> &Self::Target {
@oxalica
oxalica / bench-R5-2400G.txt
Last active January 23, 2021 16:33
Vec::retain: swap+truncate vs. drop+move
retain_std u64 almost_kept
time: [123.44 us 127.97 us 134.19 us]
Found 14 outliers among 100 measurements (14.00%)
2 (2.00%) low mild
5 (5.00%) high mild
7 (7.00%) high severe
retain_early_drop u64 almost_kept
time: [98.345 us 100.49 us 103.22 us]
Found 15 outliers among 100 measurements (15.00%)
@oxalica
oxalica / flake.nix
Created January 16, 2021 14:49
Rust wasm example development environment
{
inputs = {
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
flake-utils.url = github:numtide/flake-utils;
rust-overlay.url = github:oxalica/rust-overlay;
};
outputs = { nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachSystem ["x86_64-linux"] (system: let
pkgs = import nixpkgs {