Skip to content

Instantly share code, notes, and snippets.

@alexheretic
alexheretic / rustbench
Last active September 5, 2019 12:30
Rust micro-benchmarks helper. Runs benchmarks multiple times taking best times & compares to a control. Requires stable and nightly toolchains installed, and `cargo +stable install benchcmp`.
#!/usr/bin/env bash
# shellcheck disable=SC2086
set -euo pipefail
if [ "${1:-}" == "--help" ] || [ "${1:-}" == "-h" ]; then
echo "Micro-benchmarks helper using: cargo +nightly bench"
echo " Setup a control / starting values to compare against"
echo " $ rustbench --control"
echo
@alexheretic
alexheretic / clean-dot-cargo
Last active April 12, 2024 17:23
Deletes ~/.cargo cached data older than 2 weeks
#!/usr/bin/env bash
## Deletes ~/.cargo cached data older than 2 weeks
set -eu
du_before=$(du -hd0 ~/.cargo/ | cut -f1)
# remove old crate caches & sources
find ~/.cargo/registry/cache/ -type f -ctime +13 -atime +13 -delete
@alexheretic
alexheretic / latest-stable-rustc.md
Last active March 28, 2023 17:13
Latest stable rust as a MSRV policy

Latest stable rust as a minimum

Minimum supported rust version (MSRV) policy that indicates the most recent stable rust release is the minimum whenever a new crate version is published. It is not required to bump a crate's major version after a new stable compiler is released.

For example crate_foo version 0.1.2 published on 2018-12-28 has MSRV 1.31.1 as this compiler was published on 2018-12-20.

The advantages of this approach is simplicity in maintaining a crate's code.

Workarounds for older compiler versions

If you are unable to update your compiler, you may be unable to update crate dependencies following this policy.

@alexheretic
alexheretic / table-flips.md
Last active August 7, 2024 15:33
A selection of ascii table flips

(╯°□°)╯︵ ┻━┻

(┛◉Д◉)┛彡┻━┻

(ノ≧∇≦)ノ ミ ┸━┸

(ノಠ益ಠ)ノ彡┻━┻

(╯ರ ~ ರ)╯︵ ┻━┻

@alexheretic
alexheretic / find-cargo-unused-dependencies.sh
Last active February 1, 2024 12:31
Brute force check for ununsed Cargo.toml dependencies
#!/usr/bin/env bash
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
@alexheretic
alexheretic / watch-mem-usage
Created May 19, 2023 15:50
Output the memory usage of a pid and measure the change.
#!/usr/bin/env bash
## Output the memory usage of a pid and measure the change.
set -euo pipefail
pid=$1
last_usage_mb=0
while true; do
mem_usage=$(ps -p "$pid" -o size=)