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."git@github.com:".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. |
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
| // main.rs - A minimal Crust program with tests | |
| // | |
| #![cfg_attr(not(test), no_std)] | |
| #![cfg_attr(not(test), no_main)] | |
| extern crate libc; | |
| #[cfg(not(test))] | |
| use core::panic::PanicInfo; |
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
| // --- Dependencies --- | |
| // This simple example relies only on standard library features. | |
| use std::error::Error; | |
| use std::fmt; | |
| // --- Error Handling --- | |
| /// A simple custom error type for parsing issues. | |
| #[derive(Debug)] | |
| struct ParseError { |
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
| // The core concept is that for a number 'n', if 'n % d == 0', then 'n' is divisible by 'd'. | |
| // Divisibility tests rely on properties of the digits. | |
| /// 🔢 Divisibility Tests Module | |
| mod divisibility_tests { | |
| // Helper function to get the sum of digits | |
| pub fn sum_digits(n: u64) -> u64 { | |
| let mut sum = 0; | |
| let mut num = n; | |
| while num > 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
| // Verbose Script: Corrected Floating-Point Comparison | |
| fn main() { | |
| // ---------------------------------------------------- | |
| // 1. Define Constants | |
| // ---------------------------------------------------- | |
| const PI: f64 = std::f64::consts::PI; | |
| let gamma_one_half: f64 = PI.sqrt(); | |
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
| import secrets | |
| from statistics import mean | |
| # secp256k1 parameters | |
| p = 2**256 - 2**32 - 977 | |
| b = 7 # y^2 = x^3 + 7 | |
| def is_quadratic_residue(n): | |
| """Return True if n is a quadratic residue mod p (including 0).""" | |
| if n == 0: |
NewerOlder