This file contains 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
// Given a string, cycle the first letter of each word back one word, | |
// and cycle the last letter of each word forward one word. | |
// Example input: "who welld horly" | |
// Example output: "why hello world" | |
// Do this example by hand: | |
// Input: "bes le uoogit" | |
// Output: "" |
This file contains 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() { | |
println!("Sort numbers ascending"); | |
let mut numbers = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1]; | |
println!("Before: {:?}", numbers); | |
bubble_sort(&mut numbers); | |
println!("After: {:?}\n", numbers); | |
println!("Sort strings alphabetically"); | |
let mut strings = ["beach", "hotel", "airplane", "car", "house", "art"]; | |
println!("Before: {:?}", strings); |
This file contains 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::thread; | |
fn main() { | |
let numbers: Vec<usize> = vec![]; | |
let t = thread::spawn(move || { | |
let len = numbers.len(); | |
let sum = numbers.into_iter().sum::<usize>(); | |
sum / len | |
}); |
This file contains 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::{thread, time}; | |
use futures::future; | |
use std::time::Instant; | |
// Delay function will wait for n seconds | |
async fn delay(secs: u64) -> anyhow::Result<()> { | |
let ten_secs = time::Duration::from_secs(secs); | |
let now = time::Instant::now(); | |
// Wraps a sync call into a future |
This file contains 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 futures_util::{SinkExt, StreamExt}; | |
use serde::{Deserialize, Serialize}; | |
use tokio::sync::mpsc; | |
use tokio_tungstenite::{ | |
connect_async, | |
tungstenite::{Message, Result}, | |
}; | |
use url::Url; | |
const WS_URL: &'static str = "wss://ws-feed.exchange.coinbase.com"; |
This file contains 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
#[derive(Debug, PartialEq)] | |
enum CPFError { | |
InvalidDigitAtIndex(u32), | |
InvalidLength(u32), | |
Invalid, | |
} | |
fn get_dv(cpf: &Vec<u32>, digit_position: u32) -> u32 { | |
let mut count = digit_position; | |
let mut sum = 0; |
This file contains 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
#[derive(PartialEq, Debug)] | |
enum Language { | |
ENGLISH, | |
PORTUGUESE, | |
} | |
fn select_language(language: Language) -> Language { | |
match language { | |
Language::ENGLISH => println!("English selected"), | |
Language::PORTUGUESE => println!("Portuguese selectionado"), |
This file contains 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
type CbFunc = fn(); | |
fn main() { | |
call_func(print_hello); | |
call_func(|| println!("{}", "haloo :D")); // Closure | |
} | |
fn call_func(f: CbFunc) { | |
f(); | |
} |
This file contains 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::env; | |
use std::path; | |
use ggez::event::EventHandler; | |
use ggez::{event, graphics, Context, GameResult}; | |
const GRID_SIZE: (usize, usize) = (10, 10); | |
const GRID_CELL_SIZE: (usize, usize) = (64, 64); | |
const SCREEN_SIZE: (f32, f32) = ( | |
GRID_SIZE.0 as f32 * GRID_CELL_SIZE.0 as f32, |
This file contains 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::f32; | |
use std::f64; | |
let largest: u64 = 0xfffffffffffff; | |
let zero: u64 = 0x10000000000000; | |
let num = 1_000_000u64; | |
let flt = 123.4f64; // Double-like | |
let fp2 = 0.1f32; // Float-like | |
let fp3 = 12E+99_f64; //Exponents |
NewerOlder