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
| extern crate chrono; | |
| extern crate libc; | |
| #[macro_use] | |
| extern crate structopt; | |
| use std::fs; | |
| use std::path::PathBuf; | |
| use std::error::Error; | |
| use std::process; | |
| use std::os::unix::fs::PermissionsExt; |
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
| #include <copyfile.h> | |
| int main() | |
| { | |
| copyfile("test.txt", "copy.txt", 0, COPYFILE_ALL); | |
| } |
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
| ["Ruby", "Rust", "Python", "Cobol"].each do |lang| | |
| puts "Hello #{lang}!" | |
| end |
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
| #[macro_use] | |
| extern crate error_chain; | |
| use std::env; | |
| use std::fs::File; | |
| use std::io::{self, BufReader, Read, Write}; | |
| pub const BUFFER_CAPACITY: usize = 64 * 1024; | |
| error_chain! { |
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
| extern crate threadpool; | |
| extern crate num_cpus; | |
| use threadpool::ThreadPool; | |
| use std::sync::mpsc::channel; | |
| fn fib_real(number: u64) -> u64 { | |
| match number < 2 { | |
| true => number, | |
| false => run(number - 1) + run(number - 2), |
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
| #![feature(generators)] | |
| #![feature(generator_trait)] | |
| use std::ops::{Generator, GeneratorState}; | |
| fn fizzbuzz_println(upto: u64) { | |
| for i in 0..upto { | |
| if i % 3 == 0 && i % 5 == 0 { | |
| println!("FizzBuzz"); | |
| } else if i % 3 == 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
| fn main() { | |
| let test: String = "0.123".into(); | |
| let out = test.parse::<f64>().ok(); // parse test into Some(0.123) here | |
| // my failed attempt: | |
| // time_index: Some(fields[3].parse::<f64>().unwrap_or_default()), | |
| let out = test.parse::<f64>().ok(); // parse test into Some(0.123) here | |
| assert_eq!(out, Some(0.123)); | |
| } |
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::fs::File; | |
| use std::io::{BufReader, BufRead}; | |
| fn main() { | |
| let path = "/usr/share/dict/words"; | |
| let f = File::open(path).expect("Can't open file"); | |
| let buffered = BufReader::new(f); | |
| for line_result in buffered.lines() { | |
| let line = line_result.unwrap(); |
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::env; | |
| use std::io::BufWriter; | |
| use std::io::{self, Write}; | |
| const BUFSIZE: usize = 8192; | |
| fn main() { | |
| let expletive = env::args().nth(1).unwrap_or("y".into()); | |
| let mut writer = BufWriter::with_capacity(BUFSIZE, io::stdout()); | |
| loop { |
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 quicksort<E: PartialOrd + Clone>(list: &[E]) -> Vec<E> { | |
| let pivot = match list.get(0) { | |
| None => return vec![], | |
| Some(v) => v, | |
| }; | |
| let less: Vec<_> = list[1..].iter().filter(|&e| e <= pivot).cloned().collect(); | |
| let more: Vec<_> = list.iter().filter(|&e| e > pivot).cloned().collect(); | |
| [quicksort(&less), vec![pivot.clone()], quicksort(&more)].concat() | |
| } |