This file contains hidden or 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
let | |
letter = ''[a-zA-Z]''; # unused; just from semver's spec | |
positive-digit = ''[1-9]''; | |
digit = ''[0-9]''; | |
non-digit = ''[a-zA-Z-]''; | |
identifier-character = ''[a-zA-Z0-9-]''; | |
numeric-identifier = ''(0|${positive-digit}${digit}*)''; | |
alphanumeric-identifier = ''(${non-digit}${identifier-character}*|${identifier-character}+${non-digit}${identifier-character}*)''; | |
build-identifier = ''(${alphanumeric-identifier}|${digit}+)''; | |
pre-release-identifier = ''(${alphanumeric-identifier}|${numeric-identifier})''; |
This file contains hidden or 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
let | |
inherit (builtins) | |
attrValues | |
concatStringsSep | |
foldl' | |
head | |
length | |
mapAttrs | |
tail | |
typeOf |
This file contains hidden or 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/env bash | |
# syncthing share. some parent directory | |
targetShare="$PWD" | |
while true; do | |
if [ -d "$targetShare/.stfolder" ]; then break; fi | |
if [ "$targetShare" == "/" ]; then | |
echo "Could not find parent Syncthing share" | |
exit 1; | |
fi |
This file contains hidden or 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
[package] | |
name = "json-parser" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
winnow = { version = "0.6.14", features = ["simd", "debug"] } |
This file contains hidden or 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
def print_table(table, *fields, padding=2): | |
'''Pretty prints a table (iterable of iterables) with given header fields''' | |
data = [fields] + table | |
column_width = max(len(str(column)) for row in data for column in row) + padding | |
[print("".join(str(column).ljust(column_width) for column in row)) for row in data] | |
table = [ | |
("Ada", "Lovelace", 36), | |
("Bjarne", "Stroustrup", 73), | |
("Ken", "Thomson", 81), |
This file contains hidden or 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 abs_diff<T: std::ops::Sub<Output = T> + PartialOrd>(a: T, b: T) -> T { | |
if a <= b { | |
b - a | |
} else { | |
a - b | |
} | |
} |
This file contains hidden or 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
def halfwidth(text): | |
wide_map = {i: i + 0xFEE0 for i in range(0x21, 0x7F)} | |
wide_map[0x20] = 0x3000 | |
return text.translate(wide_map) | |
def print_halfwidth(*args, sep=" ", **kwargs): | |
text = sep.join(map(halfwidth, map(str, args))) | |
print(text, **kwargs) |
This file contains hidden or 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
public class PiApprox { | |
public static void main(String[] args) { | |
int precision = 16; | |
double targetPi = roundTo(Math.PI / 4, precision); | |
double pi = 0d; | |
int i = 0; | |
while (roundTo(pi, precision) != targetPi) { | |
int sign = i % 2 == 0 ? 1 : -1; | |
pi += 1d / (i++ * 2 + 1) * sign; |
This file contains hidden or 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/env bash | |
_basename=$(basename "$0") | |
[ $# -lt 2 ] && printf "Usage: %s SOURCE... DEST\nExample: %s iso/*.nkit.iso /mnt/games\n" "$_basename" "$_basename" && exit 1 | |
set -e | |
_dest="${!#}" | |
_total=$(($# - 1)) | |
_current=0 |
This file contains hidden or 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 solution = hanoi(3, 'A', 'B', 'C'); | |
for (i, hanoi_move) in solution.iter().enumerate().map(|(i, m)| (i + 1, m)) { | |
eprintln!("{i}: {hanoi_move:?}"); | |
} | |
} | |
#[derive(Debug)] | |
struct Move { | |
from: Peg, |
NewerOlder