Skip to content

Instantly share code, notes, and snippets.

View wperron's full-sized avatar
🚀
Launching into orbit

William Perron wperron

🚀
Launching into orbit
View GitHub Profile
@wperron
wperron / handler.js
Created August 11, 2021 17:47
Get latest deno std version
addEventListener("fetch", (event) => {
event.respondWith(fetch("https://deno.land/std/version.ts"));
});
@wperron
wperron / main.rs
Created August 30, 2021 17:16
Longest prefix in a list of strings
use std::collections::HashMap;
#[derive(Clone)]
pub struct Node {
end: bool,
next: HashMap<char, Node>,
}
pub struct Trie {
root: Node,
@wperron
wperron / main.go
Created October 5, 2021 13:25
Distinct Permutations
package main
import (
"fmt"
)
func main() {
permuts := distinctPermutations([]int{1, 2, 2, 3, 4}, 3)
fmt.Println(permuts)
}
@wperron
wperron / main.rs
Created October 19, 2021 14:26
reorder
/// 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)
@wperron
wperron / main.rs
Last active November 8, 2021 16:07
Function that finds all the local maximas in a vector of unsigned integers
/// 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])
@wperron
wperron / secrets.awk
Last active April 15, 2022 21:57
Detecting secrets in source code with ✨ RegEx ✨
# 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
@wperron
wperron / main.rs
Created November 22, 2021 14:08
Find groups of anagrams in a list of strings
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"]]
@wperron
wperron / main.rs
Created November 29, 2021 16:45
Find all permutations of letters given a phone number
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']);
@wperron
wperron / main.rs
Created December 6, 2021 13:57
Calculate the area of a rectagular prism
fn main() {
println!("{:?}", wrap(2, 3, 4));
}
fn wrap(l: i32, w: i32, h: i32) -> i32 {
2 * (l*w + w*h + h*l)
}
@wperron
wperron / main.rs
Created January 10, 2022 13:33
Find all permutations of uppercase and lowercase characters in a string
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();