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 / playground.rs
Created October 3, 2025 14:19 — forked from rust-play/playground.rs
Code shared from the Rust Playground
/// Calculates the value of the first identity's right-hand side: n - 1.
///
/// This function directly computes the right-hand side of the stated identity:
/// floor( (sum_{k=n}^inf 1/k^2)^-1 ) = n - 1.
///
/// # Arguments
/// * `n`: A positive integer (u64).
///
/// # Returns
/// The result (n - 1) as a u64.
@RandyMcMillan
RandyMcMillan / coldcore.rs
Last active September 27, 2025 16:40 — forked from rust-play/playground.rs
coldcore.rs
use clap::{Parser, Subcommand};
use std::path::PathBuf;
// --- Constants and Types ---
const VERSION: &str = "0.4.1";
// Placeholder structs for complex types like Wallet and GlobalConfig
// In a full implementation, these would be defined in separate modules (e.g., `config.rs`, `wallet.rs`)
// and would likely derive traits like `serde::Deserialize` and `serde::Serialize`.
@RandyMcMillan
RandyMcMillan / SwiftSync.md
Created September 22, 2025 15:21 — forked from RubenSomsen/SwiftSync.md
SwiftSync - smarter synchronization with hints

SwiftSync

Near-stateless, fully parallelizable validation of the Bitcoin blockchain with hints about which outputs remain unspent. All other inputs/outputs are efficiently crossed off inside a single hash aggregate that only reaches zero if validation was successful and the hints were correct.

15-minute talk summarizing the protocol

Introduction

Validation is at the heart of Bitcoin. Any improvements in validation speed will have a direct impact on the scalability of the system, including everything that is built on top of it. For this reason improving validation performance may be one of the most important things we can do.

@RandyMcMillan
RandyMcMillan / viete_pi.rs
Created September 20, 2025 13:06 — forked from rust-play/playground.rs
viete_pi.rs
use std::f64::consts::PI;
/// Calculates an approximation of Pi using Viète's formula.
///
/// The formula is based on an infinite product of terms involving nested square roots.
/// This function approximates the product up to a given number of iterations.
///
/// # Arguments
///
/// * `iterations` - The number of terms to include in the product. More iterations
@RandyMcMillan
RandyMcMillan / anyhow_match.rs
Last active September 11, 2025 13:02 — forked from rust-play/playground.rs
anyhow_match.rs
use anyhow::Result;
// The same function as before that might fail.
fn get_user_id(username: &str) -> Result<u32> {
if username.is_empty() {
anyhow::bail!("Username cannot be empty");
}
Ok(42)
}
@RandyMcMillan
RandyMcMillan / anyhow.rs
Created September 11, 2025 12:58 — forked from rust-play/playground.rs
anyhow.rs
use anyhow::Result;
// A function that returns a Result.
// We use 'anyhow::Result' as a shorthand for 'Result<T, anyhow::Error>'.
fn get_user_id(username: &str) -> Result<u32> {
// This is a simple, illustrative error case.
// We can use anyhow::bail! to create an immediate error.
if username.is_empty() {
// 'anyhow::bail!' is a macro that returns an error.
anyhow::bail!("Username cannot be empty");
@RandyMcMillan
RandyMcMillan / struct_partition_into_iter.rs
Last active August 23, 2025 12:01 — forked from rust-play/playground.rs
struct_partition_into_iter.rs
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f6b6cbb5fedbb3a745ee98fde30c8d06
// A basic struct that holds an array of 16-bit unsigned integers.
struct Numbers([u16; 10]);
// Implement the IntoIterator trait for our Numbers struct.
impl<'a> IntoIterator for &'a Numbers {
// We want to iterate over references to u16 values.
type Item = &'a u16;
// The type of the iterator we're returning.
type IntoIter = std::slice::Iter<'a, u16>;
@RandyMcMillan
RandyMcMillan / while_rc_strong_count.rs
Last active August 21, 2025 14:43 — forked from rust-play/playground.rs
while_rc_strong_count.rs
use std::rc::Rc;
fn process_shared(data: Rc<String>, storage: &mut Vec<Rc<String>>) {
storage.push(data.clone()); // Clones Rc, not String
}
fn main() {
let shared = Rc::new("shared".to_string());
let mut storage = Vec::new();
while Rc::strong_count(&shared) < 10 {
process_shared(shared.clone(), &mut storage);
println!("Rc count: {}", Rc::strong_count(&shared));
@RandyMcMillan
RandyMcMillan / impl_from_config_error.rs
Last active August 20, 2025 12:01 — forked from rust-play/playground.rs
impl_from_config_error.rs
#[allow(dead_code)]
#[derive(Debug)]
enum ConfigError {
MissingKey(String),
ParseError(std::num::ParseIntError),
}
impl From<std::num::ParseIntError> for ConfigError {
fn from(err: std::num::ParseIntError) -> Self {
ConfigError::ParseError(err)
}
@RandyMcMillan
RandyMcMillan / tokio_read_write.rs
Last active August 12, 2025 11:53 — forked from rust-play/playground.rs
tokio_read_write.rs
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let listener = TcpListener::bind("127.0.0.1:8080").await?;
println!("Echo server listening on 127.0.0.1:8080");
loop {
let (mut socket, addr) = listener.accept().await?;