Skip to content

Instantly share code, notes, and snippets.

View BartMassey's full-sized avatar

Bart Massey BartMassey

View GitHub Profile
@BartMassey
BartMassey / thue-morse.py
Created March 31, 2025 17:37
Test/benchmark of Wikipedia Thue-morse implementations
# Implementations from Wikipedia
# https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence
from math import ceil, log2
from sys import argv
def thue_morse_fast(n):
def generate_sequence(seq_length):
"""Thue–Morse sequence."""
value = 1
@BartMassey
BartMassey / niceness.rs
Created December 6, 2024 21:16
Advent of Rust 2024 Day 4 — niceness
//! # [*Advent of Rust 2024* Day 4]: Kids and Niceness
//! Bart Massey 2024
//!
//! This code is licensed under the "MIT License". License terms
//! are [here](https://opensource.org/license/mit).
//!
//! This code is a demo of how to solve the given problem with reasonable
//! programming style and correctness,
//!
//! [*Advent of Rust 2024* Day 4]: https://www.rustfinity.com/practice/rust/challenges/aor-2024-4
@BartMassey
BartMassey / idr.rs
Last active October 11, 2024 00:06
Demos of various trait impls to make iteration easier.
struct V([u64; 3]);
impl std::ops::Deref for V {
type Target = [u64; 3];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> IntoIterator for &'a V {
@BartMassey
BartMassey / github-unghost.sh
Last active June 4, 2024 15:11
Mark all notifications as read ("Ghost notification" remover)
#!/bin/sh
# Mark all notifications as read, including "ghost" notifications.
# Works on Linux, requires a "classic" auth token be present in `~/.github-oauthtoken`
# and also that `gh` is installed. You could presumably use `gh auth login` instead
# if you want to authenticate that way.
#
# Works for me, use at your own risk.
#
# https://github.com/orgs/community/discussions/6874
# https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#mark-notifications-as-read
@BartMassey
BartMassey / blocksstates.py
Created March 13, 2024 03:26
Compute the number of states for an n-block Blocks World planning problem.
import math, sys
# Number of blocks to manipulate
nblocks = int(sys.argv[1])
# Number of ways to order a stack of nstack blocks.
def orderings(nstack):
return math.factorial(nstack)
# Generate all partitions of nblocks. A partition of nblocks
import numpy as np
import scipy.signal as ss
tau = 2 * np.pi
# Filter coefficients from
#
# cs = ss.iirfilter(1, (990, 1010), btype='bandpass', output='sos', fs=48000)
#
# Filter coefficient order is b0, b1, b2, a0, a1, a0. Filter
// egui hello world example, modified per
// https://www.reddit.com/r/learnrust/comments/v64f0q/egui_label_not_appearing/
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use csv::{self};
use eframe::egui;
struct MyApp {
filename: String,
@BartMassey
BartMassey / rpl.sh
Created March 15, 2022 21:50
Local "Rust Playground" script
#!/bin/sh
# Local "Rust Playground"
# Bart Massey 2021
# Requires `cargo-add` and this additional shell function:
# function rpl {
# DIR="`$HOME/bin/mi/rpl \"$@\"`" &&
# echo "dir '$DIR'" >&2 &&
# pushd $DIR &&
# if [ -f src/main.rs ]
# then
#!/usr/bin/python3
# Transform text to one-sentence-per-line format.
# Bart Massey 2021-01-20
import re, sys
blank = re.compile("^[ \t]*$")
dot = re.compile("[.] ")
text = open(sys.argv[1], "r").read().splitlines()
@BartMassey
BartMassey / spawn-fail.patch
Created December 8, 2021 10:07
Rust std patch to allow thread spawn to return an error rather than panicking when out of memory for an alt signal stack
diff --git a/library/std/src/sys/unix/stack_overflow.rs b/library/std/src/sys/unix/stack_overflow.rs
index 1e8d1137ac8..eade97af5c6 100644
--- a/library/std/src/sys/unix/stack_overflow.rs
+++ b/library/std/src/sys/unix/stack_overflow.rs
@@ -1,28 +1,26 @@
#![cfg_attr(test, allow(dead_code))]
-use self::imp::{drop_handler, make_handler};
+use crate::io;