Skip to content

Instantly share code, notes, and snippets.

View RandyMcMillan's full-sized avatar
🛰️
Those who know - do not speak of it.

@RandyMcMillan RandyMcMillan

🛰️
Those who know - do not speak of it.
View GitHub Profile
@RandyMcMillan
RandyMcMillan / logic_gates.rs
Last active January 20, 2026 12:09 — forked from rust-play/playground.rs
logic_gates.rs
/// A collection of digital logic gate algorithms.
struct LogicGates;
impl LogicGates {
/// NOT gate: The output is the opposite of the input.
fn not(a: u8) -> u8 {
match a {
0 => 1,
_ => 0,
}
@RandyMcMillan
RandyMcMillan / varint_bitcoin.rs
Last active January 18, 2026 14:22 — forked from rust-play/playground.rs
varint_bitcoin.rs
/// A verbose example of Bitcoin's two variable integer types.
fn main() {
let value: u64 = 515;
// 1. CompactSize (Little-Endian) - Used in P2P/Transactions
let compact = encode_compact_size(value);
println!("Value: {}", value);
println!("CompactSize (LE-based) hex: {:02x?}", compact);
// 2. VarInt (Base-128 Big-Endian) - Used in LevelDB/Disk
@RandyMcMillan
RandyMcMillan / shannon_entropy.rs
Last active January 13, 2026 02:45 — forked from rust-play/playground.rs
shannon_entropy.rs
use std::collections::HashMap;
/// Calculates Shannon Entropy for a slice of data.
/// H = -sum(p(x) * log2(p(x)))
fn calculate_entropy(data: &[&str]) -> f64 {
let len = data.len() as f64;
if len == 0.0 {
return 0.0;
}
@RandyMcMillan
RandyMcMillan / rose_curves.rs
Last active January 10, 2026 15:59 — forked from rust-play/playground.rs
rose_curves.rs
use image::{ImageBuffer, Rgb};
use std::f64::consts::PI;
fn main() {
let grid_size = 11;
let cell_size = 200;
let padding = 20;
let width = grid_size * cell_size;
let height = grid_size * cell_size;
@RandyMcMillan
RandyMcMillan / guassian_pi_approx.rs
Last active January 8, 2026 15:25 — forked from rust-play/playground.rs
guassian_pi_approx.rs
use approx::assert_relative_eq;
fn gaussian_integral_approximation(start: f64, end: f64, steps: usize) -> f64 {
let dx = (end - start) / steps as f64;
let f = |x: f64| (-x.powi(2)).exp();
let mut sum = (f(start) + f(end)) * 0.5;
for i in 1..steps {
let x = start + (i as f64 * dx);
@RandyMcMillan
RandyMcMillan / async_trait_json.rs
Last active December 21, 2025 12:57 — forked from rust-play/playground.rs
async_trait_json.rs
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use anyhow::{Context, Result};
use std::time::Duration;
use tokio::task::JoinSet;
use std::sync::Arc;
// --- 1. Error Definitions ---
@RandyMcMillan
RandyMcMillan / RMS-Norm.rs
Last active December 20, 2025 14:30 — forked from rust-play/playground.rs
RMS-Norm.rs
use ndarray::{Array1, Array2, Axis}; // ndarray 0.16.1
use num_traits::Float; // num-traits 0.2.19
pub struct RmsNorm {
pub weight: Array1<f32>,
pub eps: f32,
}
impl RmsNorm {
pub fn new(dim: usize, eps: f32) -> Self {
@RandyMcMillan
RandyMcMillan / detach_process.rs
Last active December 17, 2025 21:44 — forked from rust-play/playground.rs
detach_process.rs
use clap::Parser;
use libc::{dup2, fork, setsid, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
use log::{info, error};
use std::fs::File;
use std::os::unix::io::AsRawFd;
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(author, version, about = "A detached Rust background service")]
struct Args {
@RandyMcMillan
RandyMcMillan / cmd.sh
Created December 14, 2025 15:49 — forked from colinhacks/cmd.sh
no-http-clones
git config --global url."[email protected]:".insteadof "https://github.com/"
@RandyMcMillan
RandyMcMillan / byzantine_quorum.rs
Last active December 3, 2025 15:12 — forked from rust-play/playground.rs
byzantine_quorum.rs
use std::collections::HashMap;
use rand::{seq::SliceRandom, thread_rng};
// --- BQS Constants ---
// Maximum number of Byzantine faults (f or b) the system can tolerate.
const F: u32 = 4;
// The required supermajority count for a client to accept a value as correct.
// A value is only considered valid if F + 1 servers report it, allowing the
// client to mask 'F' colluding malicious responses.