Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@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.
@Techcable
Techcable / listfiles.sh
Created August 19, 2023 06:04
Simple shell script to list files
#!/bin/bash
if [[ "$#" -ne 2 ]]; then
echo "ERROR: Invalid number of arguments" >&2;
echo >&2;
echo "Usage: ./listfiles.sh <directory> <outfile>" >&2;
exit 1;
fi
TARGET_DIR="$1";
#!/bin/sh
confirm() {
local prompt="$1";
local default;
case "$2" in
true | True | yes)
default="True";
;;
false | False | no)
@Techcable
Techcable / byte_format.py
Created August 18, 2023 03:19
Minature python library which formats bytes for user display
from decimal import Decimal
from enum import IntEnum
from numbers import Real
class ByteUnit(IntEnum):
BYTE = 1
KILLIBYTE = 1024**1
MEGABYTE = 1024**2
GIGABYTE = 1024**3
@Techcable
Techcable / convert_bookmarks.py
Created June 25, 2023 05:37
Convert Firefox bookmarks json -> raindrop.io CSV
"""Converts firefox's JSON bookmarks format to the CSV format raindrop.io expects
See here for docs on raindrop: https://help.raindrop.io/import/#csv
"""
from __future__ import annotations
from typing import (
ClassVar, Iterable, NewType, Any, Iterator
)
from enum import Enum, nonmember as enum_nonmember
@Techcable
Techcable / klib.wrap
Last active January 16, 2023 22:43
Meson Wrapfile for klib
# Website: https://attractivechaos.github.io/klib/
# Source: https://github.com/attractivechaos/klib
#
# Meson Wrap Gist:
# Meson Wrap Version: 1
[wrap-git]
url = https://github.com/attractivechaos/klib.git
revision = head
patch_directory = klib
@Techcable
Techcable / fend-unitfmt.janet
Created November 16, 2022 02:13
A Janet script to wrap fend and format units [WIP]
(import sh)
(import spork)
(def- metric-prefixes ["K" "M" "G" "T" "P" "E"])
(defn- makeunit [&named name base-prefix binary]
(default binary false)
(assert (keyword? name))
(assert (not (empty? (string name))))
(assert (string? base-prefix))