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 / tcp_stream.rs
Created January 14, 2025 00:12 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::fmt;
use std::net::{TcpStream, SocketAddr, ToSocketAddrs};
use std::io::prelude::*;
use std::collections::*;
#[derive(Debug)]
pub enum Method {
GET,
POST,
PUT,
@RandyMcMillan
RandyMcMillan / not_random.rs
Created January 13, 2025 21:36 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
let num1 = vec![2, 3];
let num2 = vec![2, 3];
let address1 = &num1 as *const Vec<i32>;
let address2 = &num2 as *const Vec<i32>;
let number1 = address1 as i32;
let number2 = address2 as i32;
println!("{}", number1 % 13);
println!("{}", number2 % 13);
@RandyMcMillan
RandyMcMillan / usize_alloc.rs
Last active January 11, 2025 15:36 — forked from rust-play/playground.rs
usize_alloc.rs
use std::alloc::{alloc, dealloc, Layout};
//use std::fmt::Pointer;
fn main() -> () {
// Number of elements to allocate
const NUM_ELEMENTS: usize = 1024;
// Size of each element in bytes
const ELEMENT_SIZE: usize = 64; // Assuming 4 bytes per element (e.g., 32-bit integer)
// Calculate total size in bytes
@RandyMcMillan
RandyMcMillan / usize_alloc.rs
Last active January 11, 2025 14:54 — forked from rust-play/playground.rs
usize_alloc.rs
use std::alloc::{alloc, dealloc, Layout};
//use std::fmt::Pointer;
fn main() -> () {
// Number of elements to allocate
const NUM_ELEMENTS: usize = 100;
// Size of each element in bytes
const ELEMENT_SIZE: usize = 1024; // Assuming 4 bytes per element (e.g., 32-bit integer)
// Calculate total size in bytes
@RandyMcMillan
RandyMcMillan / usize_alloc.rs
Last active January 11, 2025 14:55 — forked from rust-play/playground.rs
usize_alloc.rs
use std::alloc::{alloc, dealloc, Layout};
//use std::fmt::Pointer;
fn main() -> () {
// Number of elements to allocate
const NUM_ELEMENTS: usize = 100;
// Size of each element in bytes
const ELEMENT_SIZE: usize = 64; // Assuming 4 bytes per element (e.g., 32-bit integer)
// Calculate total size in bytes
@RandyMcMillan
RandyMcMillan / usize_alloc.rs
Last active January 11, 2025 14:39 — forked from rust-play/playground.rs
usize_alloc.rs
use std::alloc::{alloc, dealloc, Layout};
//use std::fmt::Pointer;
fn main() -> () {
// Number of elements to allocate
const NUM_ELEMENTS: usize = 100;
// Size of each element in bytes
const ELEMENT_SIZE: usize = 8; // Assuming 4 bytes per element (e.g., 32-bit integer)
// Calculate total size in bytes
@RandyMcMillan
RandyMcMillan / usize.rs
Last active January 11, 2025 14:55 — forked from rust-play/playground.rs
usize.rs
use std::alloc::{alloc, dealloc, Layout};
//use std::fmt::Pointer;
fn main() {
// Number of elements to allocate
const NUM_ELEMENTS: usize = 100;
// Size of each element in bytes
const ELEMENT_SIZE: usize = 4; // Assuming 4 bytes per element (e.g., 32-bit integer)
// Calculate total size in bytes
@RandyMcMillan
RandyMcMillan / get_matching_enum.rs
Last active January 10, 2025 16:27 — forked from rust-play/playground.rs
get_matching_enum.rs
//#[allow(dead_code)]
enum Point {
Nothing,
TuplePoint(i32, i32),
StructPoint {
x: i32,
y: i32
}
}
@RandyMcMillan
RandyMcMillan / bitcoin_supply.rs
Last active January 10, 2025 16:28 — forked from rust-play/playground.rs
bitcoin_supply.rs
fn main() {
let mut sum: u64 = 0;
for x in 0..=32 {
// Calculate the term inside the summation
let term: f64 = (50.0 * 1e8) / (2.0_f64.powi(x as i32));
println!("{} {}", x, term.to_string());
// Take the floor of the result
let floor_term: u64 = term.floor() as u64;
// Add it to the sum
sum += floor_term;
@RandyMcMillan
RandyMcMillan / clap_basic.rs
Last active January 10, 2025 15:27 — forked from rust-play/playground.rs
clap_basic.rs
use std::path::PathBuf;
use clap::{arg, command, value_parser, ArgAction, Command};
fn main() {
let matches = command!() // requires `cargo` feature
.arg(arg!([name] "Optional name to operate on"))
.arg(
arg!(
-c --config <FILE> "Sets a custom config file"