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; | |
| use std::time::Duration; | |
| fn main() { | |
| // this thread will die when the main thread has ended | |
| // but this spawned thread will start printing outputs while the main thread continues on | |
| thread::spawn(|| { | |
| for i in 1..10 { | |
| println!("hi number {} from the spawned thread!", i); | |
| thread::sleep(Duration::from_millis(1)); |
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::cell::RefCell; | |
| use std::rc::{Rc, Weak}; | |
| // Implementation of a basic tree with out a cyclical reference, using strong and weak references | |
| /* | |
| * Every node is going to own its children, but share them so we can access each node directly | |
| * to accomplish this, we make every child a Vec<T> and T is an Rc<Node> to maintain a reference count for the smart pointers | |
| * We also need to be able to modify nodes that are children of other nodes | |
| * to accomplish this we wrap each child Vec in RefCell<T> | |
| * We also need to track who is the parent of the node |
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
| /* | |
| Write a function to find the longest common prefix string amongst an array of strings. | |
| If there is no common prefix, return an empty string "". | |
| Example 1: | |
| Input: ["flower","flow","flight"] | |
| Output: "fl" |
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
| /* | |
| Write a function to find the longest common prefix string amongst an array of strings. | |
| If there is no common prefix, return an empty string "". | |
| Example 1: | |
| Input: ["flower","flow","flight"] | |
| Output: "fl" |
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
| /* | |
| Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. | |
| Symbol Value | |
| I 1 | |
| V 5 | |
| X 10 | |
| L 50 | |
| C 100 | |
| D 500 |
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 an array of integers, return indices of the two numbers such that they add up to a specific target. | |
| // You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
| // Example: | |
| // Given nums = [2, 7, 11, 15], target = 9, | |
| // Because nums[0] + nums[1] = 2 + 7 = 9, |
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
| // Enums 1 problem (doesn't compile) | |
| #[derive(Debug)] | |
| enum Message { | |
| // TODO: define a few types of messages as used below | |
| } | |
| fn main() { | |
| println!("{:?}", Message::Quit); | |
| println!("{:?}", Message::Echo); | |
| println!("{:?}", Message::Move); |
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
| // Clippy 1 problem (this does not compile because float comparison) | |
| fn main() { | |
| let x = 1.2331f64; | |
| let y = 1.2332f64; | |
| if y != x { | |
| println!("Success!"); | |
| } | |
| } | |
| // Clippy1 solution |
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
| console.clear(); | |
| // Creating action creators for 3 actions: creating a policy, creating a claim, deleting a policy | |
| // action creator: people dropping off a form | |
| const createPolicy = (name, amount) => { | |
| return { // action, a form in our analogy | |
| type: 'CREATE_POLICY', | |
| payload: { | |
| name: name, |
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
| // A delay function used for our queries | |
| const delay = ms => new Promise(res => setTimeout(res, ms)); | |
| // Recursively try the base query when the results are null | |
| // Delay time is 2 seconds and doubles each retry | |
| const baseRetry = ({lead_id}, numberOfRetry = 5, delayMs = 2000) => { | |
| return delay(delayMs).then(() => queryFunction({queryParam}).then((resp = {}) => { | |
| const { potentiallyNullValueFromQuery } = resp; | |
| if(numberOfRetry > 0 && !potentiallNullValueFromQuery ) { | |
| // Retry the query recursively, removing a number of retries remaining | |
| return queryFunction({queryParam}, numberOfRetry - 1, delayMs * 2); |