This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let xs = vec![1]; | |
let ys = xs.clone(); | |
let clos = move || xs; | |
assert_eq!(&(clos.clone())(), &ys); | |
assert_eq!(&clos(), &ys); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let xs = vec![1, 2, 3]; | |
let ys = vec![6, 5, 4]; | |
let mut i = 0; | |
let mut j = 0; | |
let iter = std::iter::from_fn(|| { | |
if i >= xs.len() { | |
return None; | |
} | |
let rv = Some((xs[i], ys[j])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
# This program is a copy of guff, a plot device. https://github.com/silentbicycle/guff | |
# My copy here is written in awk instead of C, has no compelling benefit. | |
# Public domain. @thingskatedid | |
# Run as awk -v x=xyz ... or env variables for stuff? | |
# Assumptions: the data is evenly spaced along the x-axis | |
# TODO: moving average |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
FROM_COMMIT="$1" | |
TO_COMMIT="$2" | |
git bisect start "$FROM_COMMIT" "$TO_COMMIT" | |
git bisect run ./bisect-test && git bisect reset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
echo '=== Changing `git init` to default to "main" branch.' | |
echo "+ Updating ~/.gitconfig" | |
cat <<'EOF' >> ~/.gitconfig | |
[init] | |
templateDir = ~/.config/git/template/ | |
EOF | |
ROOT_TEMPLATE_DIR="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eux | |
# usage: | |
# cd into where you keep your git repositories then run this script. | |
# if you want to only update a single repository, comment out the loop | |
# below and calling this script from within the project you want changed. | |
update() { | |
git stash | |
# If you use something like GitHub, you will also |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
announce() { | |
S="$1" | |
S_LEN="$(echo $S | wc -m)" | |
TERM_WIDTH="$(tput cols)" | |
TERM_WIDTH="$(( TERM_WIDTH - 6 ))" | |
printf "===%*s%*s===\n" $(( (TERM_WIDTH + S_LEN) / 2 )) "$S" $(( (TERM_WIDTH - S_LEN) / 2 )) "" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
FILTER="${FILTER:="."}" | |
TOOLCHAIN_BK="$(rustup toolchain list | rg default | awk '{print $1}')" | |
TOOLCHAIN_KIND_BK="$(echo "$TOOLCHAIN_BK" | rg -o '^(stable|nightly)')" | |
if [ "$TOOLCHAIN_KIND_BK" != "stable" ]; then | |
rustup install stable | |
rustup default stable | |
fi |