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 / hamming_distance.rs
Last active January 19, 2025 21:15 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / hamming_distance.rs
Last active January 19, 2025 21:22 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / hamming_distance.rs
Last active January 19, 2025 21:39 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / get_blocktemplate.rs
Created January 25, 2025 03:30 — forked from portlandhodl/main.rs
Get Block Template Rust Example 1
use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
use bitcoincore_rpc::{Auth, Client, RpcApi};
use serde_json::Value;
struct AppState {
btc_client: Client,
}
#[get("/blocktemplate")]
async fn get_block_template(data: web::Data<AppState>) -> impl Responder {
@RandyMcMillan
RandyMcMillan / hamming_distance.rs
Last active January 25, 2025 16:05 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / hash_to_string_hamming_distance.rs
Last active January 25, 2025 16:45 — forked from rust-play/playground.rs
hash_to_string_hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / print_type.rs
Last active January 26, 2025 13:46 — forked from rust-play/playground.rs
print_type.rs
use std::any::Any;
use std::fmt::Debug;
fn print_type_name<T: Any + Debug>(value: &T) {
println!("Type of {:?} is: {}", value, std::any::type_name::<T>());
}
fn main() {
let i: i32 = 42;
print_type_name(&i);
@RandyMcMillan
RandyMcMillan / walk_dir.rs
Last active January 26, 2025 19:26 — forked from rust-play/playground.rs
walk_dir.rs
use std::fs;
use std::path::Path;
fn main() {
let input = "/usr/share/doc";
fn action(path: &str) { println!("\t{}" , path); }
fn walk(path: &str) {
println!("Listing {} ..." , path);
@RandyMcMillan
RandyMcMillan / hashmap.rs
Created January 27, 2025 16:32 — forked from rust-play/playground.rs
hashmap.rs
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone)]
struct HashMap<K, V>
where
K: Eq + Hash + Clone,
V: Clone,
{
// Buckets for storing key-value pairs
@RandyMcMillan
RandyMcMillan / factorial_gamma.rs
Last active February 25, 2025 13:12 — forked from rust-play/playground.rs
factorial_gamma.rs
fn gamma(n: f64) -> f64 {
// For simplicity, we'll use a basic approximation method.
// For higher accuracy, consider using a more sophisticated algorithm or a crate
// like `special_function` (if it provides Gamma).
// We can use integration techniques like the trapezoidal rule or Simpson's rule for approximation.
// Here's a basic trapezoidal rule example:
let mut result = 0.0;
let a = 0.0;