Skip to content

Instantly share code, notes, and snippets.

View spikespaz's full-sized avatar
🦀
Science is the scrutiny of magic.

Jacob Birkett spikespaz

🦀
Science is the scrutiny of magic.
View GitHub Profile
use core::borrow::Borrow;
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::ops::Deref;
use std::borrow::Cow;
use self::BoxOrRef::{Borrowed, Owned};
pub enum BoxOrRef<'a, T: ?Sized + 'a> {
class BiMap {
#k_to_v = new Map();
#v_to_k = new Map();
set(key, value) {
if (this.#k_to_v.get(key) === value) return this;
this.deleteKey(key);
this.deleteValue(value);
this.#k_to_v.set(key, value);
this.#v_to_k.set(value, key);
@spikespaz
spikespaz / format_delimited.rs
Created June 12, 2025 03:07
Rust helper functions for formatting delimited items.
use core::cell::Cell;
use core::fmt::{Display, Formatter, Result};
struct FormatDelimited<'a, T, I, F>
where
I: IntoIterator<Item = T>,
F: Fn(&mut Formatter<'_>, &T) -> Result,
{
inner: Cell<Option<(I, F)>>,
sep: &'a str,
use facet::{
EnumType, Field, PointerType, Shape, StructKind, StructType, Type, UnionType, UserType,
};
pub trait RecursiveShape<'shape> {
fn shape_by_path(&self, path: &[impl AsRef<str>]) -> Option<&Shape<'shape>>;
fn field_by_path(&self, path: &[impl AsRef<str>]) -> Option<&Field<'shape>>;
}
My personal stance is that 1. all adjacent whitespace can be represented by a single token, 2. whitespace between expressions is significant, 3. whitespace adjacent to punctuation is parsed with the operator token, 4. no other whitespace is significant
# Overrides to keep packages building after Rust 1.80.0.
# There is a regression with type inference that primarily affects
# the `time` crate, so for packages that use it, go back one version.
# <https://github.com/NixOS/nixpkgs/issues/332957>
pkgs: pkgs0:
let
rustVersion = "1.79.0";
rustPlatform = pkgs.makeRustPlatform {
cargo = pkgs.rust-bin.stable.${rustVersion}.default;
rustc = pkgs.rust-bin.stable.${rustVersion}.default;
@spikespaz
spikespaz / eachNewer.nix
Last active April 5, 2025 19:09
Nix snippets not used
eachNewer = lib.filterAttrs (name: updatedPackage:
let
verNixpkgs = pkgs0.${name}.version;
verOverride = updatedPackage.version;
in if lib.versionOlder verNixpkgs verOverride then
true
else
lib.warn ''
package `${name}` has an overlay but the version in Nixpkgs is newer
(${verNixpkgs} >= ${verOverride})
@spikespaz
spikespaz / !GIT_SCRIPTS.md
Created August 29, 2024 06:29
Scripts for Git and friends

Git Scripts

Gist with files I have used for managing Git repositories

@spikespaz
spikespaz / vec_of_array.md
Created August 25, 2024 14:09 — forked from danielhenrymantilla/vec_of_array.md
Vec off arrays (or slices)

Question

how can I convert an array to a vec without cloning the values

Technically-correct answer

Make a Vec of references:

array.iter_mut().collect::<Vec<_>>();
@spikespaz
spikespaz / NIX_CODESTYLE.md
Last active April 1, 2024 08:11
Nix Pedantry (according to Jacob Birkett)