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 / 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?;
@RandyMcMillan
RandyMcMillan / nested_b_tree.rs
Created August 12, 2025 11:47 — forked from rust-play/playground.rs
nested_b_tree.rs
use std::collections::BTreeMap;
fn main() {
// Let's create a nested B-tree structure:
// A BTreeMap where keys are strings (e.g., "country")
// and values are another BTreeMap (e.g., "city" -> population).
let mut world_populations: BTreeMap<String, BTreeMap<String, u64>> = BTreeMap::new();
// Add some data for "USA"
let mut usa_cities = BTreeMap::new();
usa_cities.insert("New York".to_string(), 8_468_000);
@RandyMcMillan
RandyMcMillan / palindromes.rs
Last active July 29, 2025 16:57 — forked from rust-play/playground.rs
palindromes.rs
fn is_palindrome(n: u64) -> bool {
if n < 10 {
return true; // Single-digit numbers are palindromes
}
let s = n.to_string();
s == s.chars().rev().collect::<String>()
}
fn generate_palindromes_up_to(limit: u64) -> Vec<u64> {
let mut palindromes = Vec::new();
@RandyMcMillan
RandyMcMillan / tokio_echo_server.rs
Last active July 26, 2025 12:01 — forked from rust-play/playground.rs
tokio_echo_server.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?;
@RandyMcMillan
RandyMcMillan / rust_to_swift.md
Created July 17, 2025 12:48 — forked from surpher/rust_to_swift.md
Building binaries from Rust to iOS/macOS (PactSwift specific)
@RandyMcMillan
RandyMcMillan / bash_c_example.sh
Created July 16, 2025 20:03 — forked from 84adam/bash_c_example.sh
Bash-C Hello World: Compile and run a C program from a single Bash script
#!/bin/bash
# bash_c_example.sh
# Directory to store the C source file and the executable
EXAMPLES_DIR="$HOME/bash_c_examples"
# Ensure the directory exists, create it if not
mkdir -p "$EXAMPLES_DIR"
# Check if hello_world.c and hello_world executable already exist
@RandyMcMillan
RandyMcMillan / git_vfs.rs
Last active July 15, 2025 16:48 — forked from rust-play/playground.rs
git_vfs.rs
use std::collections::HashMap;
use std::io::{self, Read, Write};
#[derive(Debug, PartialEq)]
enum GitVfsError {
NotFound,
AlreadyExists,
InvalidOperation,
}