Skip to content

Instantly share code, notes, and snippets.

View mibmo's full-sized avatar

mib mibmo

View GitHub Profile
@mibmo
mibmo / Dockerfile
Last active April 11, 2022 09:24
Ideal Rust containerfile
ARG PKG_NAME=example
ARG RUST_VERSION=1.53.0
FROM docker.io/rust:${RUST_VERSION}-alpine AS build
ARG PKG_NAME
WORKDIR /build/
# fetch package dependencies
RUN apk add build-base cmake musl-dev openssl-dev
@mibmo
mibmo / resolv.conf
Created December 28, 2021 00:24
DNS configuration for the privacy conscious and uptime paranoid.
# dns.watch
nameserver 84.200.69.80
nameserver 2001:1608:10:25::1c04:b12f
nameserver 84.200.70.40
nameserver 2001:1608:10:25::9249:d69b
# quad9
nameserver 9.9.9.9
nameserver 2620:fe::fe
nameserver 149.112.112.112
@mibmo
mibmo / README.md
Created May 28, 2022 19:22
Completely wipe user directory with one command from the run box.

Opens a background process that completely wipes all files in the user profile directory.

To run, copy the command below and paste into the Run box (opened through Windows + R).

powershell.exe Start-Process powershell.exe -NoNewWindow -argument '-nologo -noprofile -executionpolicy bypass -command Remove-Item $env:userprofile\* -Recurse -Force'

Contributions

I've very little experience with Windows; optimizations & fixes are very welcome!

@mibmo
mibmo / hanoi.rs
Last active October 25, 2023 13:53
Rust recursive towers of hanoi
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,
@mibmo
mibmo / copy.sh
Created January 15, 2024 14:55
Copy files to a destination one at a time.
#!/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
@mibmo
mibmo / piapprox.java
Created January 18, 2024 13:38
Pi approximation in Java
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;
@mibmo
mibmo / print-wide.py
Created January 23, 2024 21:55
Print wrapper for halfwidth characters in Python 3
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)
@mibmo
mibmo / abs_diff.rs
Created February 5, 2024 22:08
Generic absolute difference helper function in Rust (for e.g. Durations or just anything implementing PartialOrd + Sub)
fn abs_diff<T: std::ops::Sub<Output = T> + PartialOrd>(a: T, b: T) -> T {
if a <= b {
b - a
} else {
a - b
}
}
@mibmo
mibmo / pretty_print_table.rs
Last active February 23, 2024 06:52
Print a Python table (list of lists)
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),
@mibmo
mibmo / Cargo.toml
Created July 21, 2024 12:11
Trying some JSON parsing with winnow
[package]
name = "json-parser"
version = "0.1.0"
edition = "2021"
[dependencies]
winnow = { version = "0.6.14", features = ["simd", "debug"] }