Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@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.
@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