Skip to content

Instantly share code, notes, and snippets.

View BD103's full-sized avatar

BD103 BD103

View GitHub Profile
@BD103
BD103 / display_command.rs
Created April 29, 2025 13:03
Prettily formats a Rust `Command` into a `String`
/// Formats a [`Command`] into a user-friendly representation.
///
/// The output is formatted as `KEY1=value KEY2=value program arg1 --arg2`, where environmental
/// variables are first, the program is second, and the arguments are last.
fn display_command(command: &Command) -> String {
let envs = command.get_envs().filter_map(|(key, value)| {
let key = key.to_string_lossy();
value
.map(OsStr::to_string_lossy)
.map(|value| Cow::from(format!("{key}={value}")))
body {
transition: opacity 0.5 cubic-bezier !important;
}
body *:not(:hover) {
opacity: 0.9;
}
body *:hover {
opacity: 1.0;
@BD103
BD103 / purge-action-cache.sh
Last active April 29, 2025 13:06
Automatically purge the entire Github Actions cache using `gh` in the CLI.
gh cache delete --all
@BD103
BD103 / unsafe_thread_data_sharing.rs
Created January 2, 2023 16:37
By far the most unsafe code I've ever written to evade the borrow checker. This program shares a pointer address between two threads and mutates it.
use std::thread;
fn main() {
let mut data: u32 = 0;
// Get the memory address of data so it can share across threads
let raw_ptr_address = &mut data as *mut u32 as usize;
let thread1 = thread::spawn(move || {
// Get a pointer to the data from the address
@BD103
BD103 / chess.py
Created July 11, 2022 17:28
Simple Console Chess
from enum import Enum
class Cell(Enum):
EMPTY = 0
X = 1
O = 2
def __str__(self) -> str:
if self._name_ == "EMPTY":
@BD103
BD103 / python_match_statement.py
Last active March 14, 2022 15:19
A funky way to implement a switch statement in Python without all the elifs
"""
In Python 3.10, the match-case statement was added. You can use this instead.
Check your version of Python with:
$ python --version
"""
x = input("> ")
@BD103
BD103 / 01-extract-audio.py
Last active October 2, 2023 15:01
A script to extract the audio from Minecraft's asset folder
import json
import shutil
import os
version = input("Enter Minecraft version: ").strip()
index_file = f"{version}.json"
# Open version index and save the objects
@BD103
BD103 / uninstall-all.sh
Created October 20, 2021 21:49
Script to uninstall all Python packages
# Thanks to https://stackoverflow.com/a/40566052
python -m pip uninstall -y -r <(pip freeze)
@BD103
BD103 / Colors.java
Last active July 29, 2023 13:03
Console color codes organized in a nice little class
public class Colors {
public static String reset = "\033[0m";
public static String bold = "\033[1m";
public static String dim = "\033[2m";
public static String italic = "\033[3m";
public static String underline = "\033[4m";
public static String reverse = "\033[7m";
public static String dimAlt = "\033[8m";
public static String underlineAlt = "\033[21m";

FBC

FBC is a template class that lays down a framework for file-based classes.

What are file-based classes?

File-based classes are types that store their information in a file, then load it next time the program starts. This is helpful for custom databases and user data.

How do I create a child FBC class?