This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git config --global url."[email protected]:".insteadof "https://github.com/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
NewerOlder