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::fmt; | |
use serde::de::{self, Deserialize, Deserializer, Visitor, SeqAccess, MapAccess}; | |
#[allow(dead_code)] | |
struct Duration { | |
secs: u64, | |
nanos: u32, | |
} |
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
#![allow(unused)] | |
/* | |
Kata (6kyu): Scheduling (Shortest Job First or SJF) | |
Url: https://www.codewars.com/kata/scheduling-shortest-job-first-or-sjf | |
Scheduling is how the processor decides which jobs(processes) get to use | |
the processor and for how long. This can cause a lot of problems. | |
Like a really long process taking the entire CPU and freezing | |
all the other processes. One solution is Shortest Job First(SJF), |
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::time::{ Instant, Duration }; | |
fn benchmark<F: FnOnce()>(f: F) { | |
let t0 = Instant::now(); | |
f(); | |
let t1 = Instant::now(); | |
let dt = t1 - t0; | |
println!("{}", dt.as_millis()); | |
} |
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
#![forbid(unsafe_code)] | |
fn main() { | |
use std::collections::HashMap; | |
let mut map = HashMap::<Box<dyn DynHash>, _>::new(); | |
fn new<T: DynHash>(value: T) -> Box<dyn DynHash> { | |
Box::new(value) | |
} |
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::collections::HashMap; | |
static COLOR_TABLE: [(&str, (u8, u8, u8)); 147] = [ | |
("aliceblue", (240, 248, 255)), | |
("antiquewhite", (250, 235, 215)), | |
("aqua", (0, 255, 255)), | |
("aquamarine", (127, 255, 212)), | |
("azure", (240, 255, 255)), | |
("beige", (245, 245, 220)), | |
("bisque", (255, 228, 196)), |
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
extern crate rand; // 0.5.5 | |
use rand::{distributions::Uniform, Rng}; | |
#[derive(Debug, Clone)] | |
struct Individual { | |
score: Option<usize>, | |
value: String, | |
} | |
impl Individual { |
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
extern crate regex; | |
use regex::Regex; | |
fn main() { | |
let rg = Regex::new(r"(\d)-(\d)(\d)(\d)-(\d)(\d)(\d)(\d)(\d)-(\d)").unwrap(); | |
// Regex::captures returns Option<Captures>, | |
// first element is the full match and others | |
// are capture groups | |
let isbn : Vec<_> = rg.captures("3-598-21508-8").unwrap().iter().skip(1).map(|x| x.unwrap().as_str().parse::<u64>().unwrap()).collect(); | |
println!("{:?}", isbn); |
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
extern crate itertools; | |
extern crate tokio_core; | |
extern crate web3; | |
use itertools::Itertools; | |
use tokio::runtime::Runtime; | |
use web3::{ | |
futures::{self, Future, Stream}, | |
types::{Block, BlockId, BlockNumber, Transaction}, | |
}; |
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
#![feature(trait_alias)] | |
#[derive(Debug, Clone)] | |
struct Context { | |
a: A, | |
b: B, | |
} | |
#[derive(Debug, Clone)] | |
struct A(i32); | |
#[derive(Debug, Clone)] |
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
/* | |
Exercise about the Rust error handling. | |
Follow the instructions in the comments "Exercise" below. | |
References: | |
Book: https://doc.rust-lang.org/nightly/book/ch09-00-error-handling.html | |
Rust Standard Library: https://doc.rust-lang.org/stable/std/index.html | |
Crates IO: https://crates.io/ | |
random: https://rust-random.github.io/rand/rand/fn.random.html |