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
| <script type="text/javascript> | |
| function fisherYates ( myArray ) { | |
| var i = myArray.length, j, temp; | |
| if ( i === 0 ) return false; | |
| while ( --i ) { | |
| j = Math.floor( Math.random() * ( i + 1 ) ); | |
| temp = myArray[i]; | |
| myArray[i] = myArray[j]; | |
| myArray[j] = temp; | |
| } |
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
| // 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 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() { | |
| 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 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::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 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::{prelude::*, BufReader, Write}; | |
| use std::process::Command; | |
| use actix_multipart::Multipart; | |
| use actix_web::{post, web, App, Error, HttpResponse, HttpServer}; | |
| use futures::{StreamExt, TryStreamExt}; | |
| use tempdir::TempDir; | |
| #[post("/")] |
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
| let mut f = BufWrtier::new(File::create(filename).expect("Could not create file")); | |
| let text = include_bytes!("filename.txt"); | |
| f.write(text); | |
| let text2 = include_str!("filename.txt"); | |
| f.write(text2.as_bytes()); | |
| let data = vec![b"this will be represented as a vector of bytes"]; | |
| f.write(&data[..]); |
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::{BufReader, BufRead, BufWriter, Write}; | |
| use std::fs::File; | |
| use std::prelude::*; | |
| use std::io::{self, stdin, Read}; | |
| let sin = io::stdin(); | |
| let mut buf = String::new(); | |
| let mut name: String = String::new(); | |
| println!("Enter something"); |
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
| if cfg!(target_os = "windows") { /* ... */ } | |
| #[cfg(target_os = "linux")] // can be linux android windows macos ios | |
| #[cfg(target_pointer_width = 64)] // target 64 bit systems | |
| #[cfg(target_pointer_width = 32)] // target 32 bit systems | |
| // Compiler features | |
| #![feature(feature1, feature2, feature3)] | |
| #[cfg(feature = "foo")] | |
| // combining multiple conditions |
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 argparse; | |
| use argparse::{ArgumentParser, StoreFalse, StoreTrue, Store}; | |
| let mut vart = false; | |
| let mut varf = true; | |
| let mut vars = String::from(""); | |
| { | |
| let mut ap = ArgumentParser::new(); | |
| ap.set_description("Program description"); | |
| ap.refer(&mut vart).add_option(&["-t", "--true"], StoreTrue, "description"); | |
| ap.refer(&mut varf).add_option(&["-f", "--false"], StoreFalse, "description"); |
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
| // literals | |
| let byte_data = b"This is a string of bytes"; | |
| let raw_string = r##"This "can" have weird \"characters" in it 'no' problem"##; | |
| let raw_byte = br##"you can even mix and match"##; | |
| // Convert to bytes | |
| let data = "abcdefghijklmnopqrstuvwxyz"; | |
| let data_ref = data.as_bytes(); | |
| let data_owned = data.into_bytes(); |
NewerOlder