Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@Techcable
Techcable / extract_table.py
Created April 4, 2025 19:21
Parses a markdown table into a CSV file
#!/usr/bin/env -S uv run --script
# Extracts data from the first markdown table found in the input file,
# converting it into CSV
# /// script
# dependencies = [
# "marko~=2.1"
# ]
# ///
import csv
import sys
@Techcable
Techcable / makechawan.fish
Last active March 31, 2025 15:53
Build chawan browser on macOS (https://sr.ht/~bptato/chawan/)
#!/usr/bin/env fish
set --local openssl_prefix $(brew --prefix openssl)
set --local libssh_prefix $(brew --prefix libssh2)
set -gx CFLAGS "-I$openssl_prefix/include -I$libssh_prefix/include -lssl -lssh2"
set -gx LDFLAGS "-L$openssl_prefix/lib -L$libssh_prefix/lib -lssl -lssh2"
if not test -f ./nim.cfg; or not test -f ./README.md
echo "ERROR: Should be in chawan root directory" >&2;
@Techcable
Techcable / back2dir.fish
Created February 7, 2025 21:18
Return to the most recently used directory when starting the fish shell
# Return to the most recently used directory when starting fish shell
#
# Ported from this xontrib: https://github.com/anki-code/xontrib-back2dir
#
# Uses fish "universal variables" for storage
#
# TODO: Is using universal variables (as opposed to a dedicated file)
# going to slow things down or hurt SSD?
# Right before the first pompt is shown, we go back to the last directory
#!/usr/bin/env python3
# A nice little script to hash the contents of tarfiles
# Works in parallel
import shutil
import os
import re
import sys
import subprocess
from math import ceil
@Techcable
Techcable / magic_method_lookup.py
Created January 29, 2025 01:58
Examples of how `str(x)` differs from `x.__str__()`
"""
Examples of how `str(x)` differs from x.__str__`()
This behavior is documented here: https://docs.python.org/3.11/reference/datamodel.html#special-lookup
The reason for this is performance, so `x + y` can avoid a dictionary lookup and/or `__getattribute__` call
"""
def override_str(*args):
return "bar"
@Techcable
Techcable / state_population.2020
Created January 4, 2025 19:00
United States Population by State, According to 2020 Census (taken from Wikipedia)
state,census2020
California,"39,538,223"
Texas,"29,145,505"
Florida,"21,538,187"
New York,"20,201,249"
Pennsylvania,"13,002,700"
Illinois,"12,812,508"
Ohio,"11,799,448"
Georgia,"10,711,908"
North Carolina,"10,439,388"
@Techcable
Techcable / maybe_const_fn.rs
Created September 10, 2024 22:51
Defines the `maybe_const_fn` macro
//! Defines the [`maybe_const_fn`] macro.
/// Mark a function as `const` if a `cfg!(...)` attribute evaluates to true.
///
/// This has the same effect as using `#[rustversion::attr(version_test, const)]`,
/// but is implemented as a declarative macro instead of a procedural one.
///
/// It is subject to some minor limitations (see below).
///
/// If these are unacceptable,
@Techcable
Techcable / range_utils.rs
Last active September 7, 2024 04:00
Utilities for range types. Consider using the `rangetools` crate instead.
//! Utilities for range types.
//!
//! Consider using the `rangetools` crate instead.
use crate::num::PrimInt;
use std::fmt::Debug;
use std::ops::{Bound, RangeBounds, RangeInclusive};
/// An iterator over an arbitrary implementation of [`RangeBounds`].
///
@Techcable
Techcable / LICENSE.md
Created March 23, 2024 23:08
License file for dual-licensing under Apache-2.0 and BlueOak-1.0.0

License

This project is dual-licensed under the either the Apache License 2.0 or the Blue Oak Model License 1.0.0, at your option.

Both licenses are OSI Approved. Copies are available in the licenses/ directory.

Automatic Contributor License

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

@Techcable
Techcable / LICENSE.txt
Created August 27, 2023 01:42
The Apache 2.0 License with LLVM Exception (SPDX ID: `Apache-2.0 WITH LLVM-exception`)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.