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
| #[allow(dead_code)] | |
| fn main() { | |
| let file = std::fs::File::open("./file_chunker.rs").unwrap(); | |
| let chunker = FileChunker::new(&file).unwrap(); | |
| chunker | |
| .chunks(1024, Some('\n')) | |
| .unwrap() | |
| .iter() | |
| .for_each(|chunk| { |
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
| fn main() { | |
| let mut numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
| println!(" 0 1 (2 3 4 5]"); | |
| println!("Original vector: {:?}", numbers); | |
| #[allow(unused_variables)] | |
| for num in numbers.clone() { | |
| //print!("{} ", num); | |
| } | |
| //println!(); | |
| // We want to drain elements from |
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
| fn calculate_pi_vieta(iterations: u32) -> f64 { | |
| if iterations == 0 { | |
| return 0.0; // Or handle as an error/special case | |
| } | |
| let mut current_sqrt_term = 0.0f64; // Represents the nested sqrt part (e.g., sqrt(2), sqrt(2+sqrt(2))) | |
| let mut pi_approximation = 2.0f64; // Initialize with the leading '2' in the formula | |
| for i in 0..iterations { | |
| if i == 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 std::io; | |
| use std::fs; | |
| fn main() -> Result<(), Box<dyn std::error::Error>> { | |
| // Create a dummy config.toml file for demonstration purposes | |
| fs::write("config.toml", "key = \"value\"\nother_key = 123\nanother_string_key = \"hello world\"")?; | |
| let contents = fs::read_to_string("config.toml")?; | |
| println!("Contents of config.toml:\n{}", contents); | |
| println!("------------------------------------"); |
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 num_complex::Complex64; | |
| /// Calculates the next iteration of the given complex number z using the formula: | |
| /// Z_n+1 = (Z_n^3) / (Z_n^3 + 1) + c | |
| /// | |
| /// # Arguments | |
| /// * `z_n` - The current complex number Z_n. | |
| /// * `c` - The complex constant c. | |
| /// | |
| /// # Returns |
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
| HOSTNAME=`hostname` ssh-keygen -t rsa -C "$HOSTNAME" -f "$HOME/.ssh/id_rsa" -P "" && cat ~/.ssh/id_rsa.pub |
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 num_bigint::{BigInt, BigUint, Sign}; | |
| use num_traits::{One, Zero}; | |
| use std::str::FromStr; // For parsing BigUint from strings (e.g., hex) | |
| // --- RSA Core Functions --- | |
| /// Performs modular exponentiation: base^exp % modulus | |
| fn modpow(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint { | |
| // This is the core of RSA. `num-bigint` provides an optimized `modpow` method. | |
| base.modpow(exp, modulus) |
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::{ | |
| io::{self, Write}, | |
| path::Path, | |
| }; | |
| use tokio::io::AsyncWriteExt; // For async file writing | |
| const DEST_DIR: &str = "torrents"; | |
| #[derive(Debug, serde::Deserialize)] | |
| struct Torrent { |
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
| fn print_pascals_triangle_in_binary(num_rows: usize) { | |
| if num_rows == 0 { | |
| return; | |
| } | |
| let mut current_row: Vec<u64> = vec![1]; // Using u64 for larger numbers | |
| println!("{:b}", current_row[0]); // Print 1 in binary | |
| for r in 1..num_rows { | |
| let mut next_row: Vec<u64> = vec![1]; // First element is 1 |
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 num_bigint::{BigInt, BigUint, Sign}; | |
| use num_traits::{One, Zero}; | |
| use std::str::FromStr; // For parsing BigUint from strings (e.g., hex) | |
| // --- RSA Core Functions --- | |
| /// Performs modular exponentiation: base^exp % modulus | |
| fn modpow(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint { | |
| // This is the core of RSA. `num-bigint` provides an optimized `modpow` method. | |
| base.modpow(exp, modulus) |