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; | |
use rand::{thread_rng, Rng}; | |
use rand::distributions::range::SampleRange; | |
use num::{Num, Zero, One}; | |
use std::ops::Add; | |
// Safely choose a random number | |
// Use the num crate to add one to the generic number | |
pub fn safe_range<N>(starting: N, ending: N) -> N where N: Num 6 PartialOrd + Copy + SampleRange { | |
let end_plus = ending + N::one(); |
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
let str_to_int = u64::from_str_radix(&"10", 10).expect("Not an integer"); | |
let int_string = "1000000".to_string(); | |
let parse_int: u64 = "1000000".parse().unwrap(); | |
let parse_int: u64 = "1000000".parse::<u64>().unwrap(); // Turbo fish syntax ::<>() | |
let padded = format!("{:08.2}", 1000.1234); // 00001000.12 | |
let pad_left = format!("{txt:=<width$}", txt="text", width=20); // left padded to a variable place with = as padding | |
let pad_right = format!("{:=>7}", "text"); // right padded to 7 places with = as padding | |
let justified = format!("{:=^width$}", "text", 12); // centered with = on both sides |
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 |
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
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
#[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
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
using UnityEngine; | |
public class ExplosionCenter : MonoBehaviour | |
{ | |
// Use this for initialization | |
void Start() | |
{ | |
Destroy(gameObject, this.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).length); | |
} |
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; |