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
package main | |
import ( | |
"fmt" | |
"go/ast" | |
"go/parser" | |
"go/token" | |
"log" | |
"os" | |
) |
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::Display; | |
#[derive(PartialEq, Eq, Debug)] | |
enum Result { | |
Absent, | |
OutOfPlace, | |
Correct, | |
OutOfBounds, | |
} |
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
fn main() { | |
println!("{:?}", case_permutation(String::from("ab2"))); | |
} | |
pub fn case_permutation(str: String) -> Vec<String> { | |
let mut permuts: Vec<String> = vec!["".to_string()]; | |
for c in str.chars() { | |
let mut tmp = vec![]; | |
let lower = c.to_ascii_lowercase(); |
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
fn main() { | |
println!("{:?}", wrap(2, 3, 4)); | |
} | |
fn wrap(l: i32, w: i32, h: i32) -> i32 { | |
2 * (l*w + w*h + h*l) | |
} |
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 lazy_static::lazy_static; | |
use std::collections::HashMap; | |
lazy_static! { | |
static ref NUM_MAP: HashMap<char, Vec<char>> = { | |
let mut m = HashMap::new(); | |
m.insert('2', vec!['a', 'b', 'c']); | |
m.insert('3', vec!['d', 'e', 'f']); | |
m.insert('4', vec!['g', 'h', 'i']); | |
m.insert('5', vec!['j', 'k', 'l']); |
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; | |
/// Given an array of strings, group the anagrams together in separate arrays. | |
/// An anagram is a word or phrase formed by rearranging the letters of another | |
/// word or phrase, using all the original letters exactly once. | |
/// | |
/// Example: | |
/// ``` | |
/// $ group_anagrams(["eat","tea","ten","poop","net","ate"]) | |
/// [["poop"],["net","ten"],["eat","tea","ate"]] |
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
# Credit to https://github.com/dxa4481/truffleHogRegexes/blob/master/truffleHogRegexes/regexes.json | |
# For the different secret key patterns | |
# | |
# Usage: awk -f secrets.awk path/to/your/project/**/*.(js|ts) | |
/(xox[pborsa]-[0-9]{12}-[0-9]{12}-[0-9]{12}-[a-z0-9]{32})/ {printf "%s:%s %s", FILENAME, NR, $0; nextfile} # Slack Token | |
/-----BEGIN RSA PRIVATE KEY-----/ {printf "%s:%s %s", FILENAME, NR, $0; nextfile} # RSA private key | |
/-----BEGIN DSA PRIVATE KEY-----/ {printf "%s:%s %s", FILENAME, NR, $0; nextfile} # SSH (DSA) private key | |
/-----BEGIN EC PRIVATE KEY-----/ {printf "%s:%s %s", FILENAME, NR, $0; nextfile} # SSH (EC) private key | |
/-----BEGIN PGP PRIVATE KEY BLOCK-----/ {printf "%s:%s %s", FILENAME, NR, $0; nextfile} # PGP private ke |
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
/// Given an array of integers, return the index of each local peak in the array. | |
/// A “peak” element is an element that is greater than its neighbors. | |
/// | |
/// Example: | |
/// | |
/// ``` | |
/// $ localPeaks([1,2,3,1]) | |
/// $ [2] | |
/// | |
/// $ localPeaks([1,3,2,3,5,6,4]) |
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
/// Given an array of objects A, and an array of indexes B, reorder the objects in array A with the given indexes in array B. | |
/// Example: | |
/// let a = [C, D, E, F, G, H]; | |
/// let b = [3, 0, 4, 1, 2, 5]; | |
/// $ reorder(a, b) // a is now [D, F, G, C, E, H] | |
fn main() { | |
let res = reorder(vec!["C", "D", "E", "F", "G", "H"], vec![3, 0, 4, 1, 2, 5]); | |
println!("{:?}", &res) |
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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
permuts := distinctPermutations([]int{1, 2, 2, 3, 4}, 3) | |
fmt.Println(permuts) | |
} |