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 / prom-compare.js
Created May 11, 2023 13:24
Compare two different sets of prometheus metrics based on the output of the `/metrics` endpoint
#!/usr/bin/env deno run -A
import { readStringDelim } from "https://deno.land/[email protected]/io/read_string_delim.ts";
import * as path from "https://deno.land/[email protected]/path/mod.ts";
async function extractMetricNames(f) {
const filename = path.join(Deno.cwd(), f);
let fileReader = await Deno.open(filename);
let metrics = new Set();
@wperron
wperron / main.rs
Created May 3, 2023 19:47
Remove leading and trailing zeroes from a list of numbers
/// Given a non-empty array containing only non-negative integers, return the
/// list with trailing and leading zeroes removed.
///
/// Example:
///
/// ```
/// > removeZeroes([0, 0, 0, 3, 1, 4, 1, 5, 9, 0, 0, 0, 0])
/// > [3, 1, 4, 1, 5, 9]
///
/// > removeZeroes([0, 0, 0])
@wperron
wperron / main.rs
Created March 15, 2023 19:38
Doing math with fractions
use std::{collections::BTreeSet, fmt::Display, str::FromStr};
/// Write a function that can do the 4 basic operations (add, subtract, multiply
/// and divide) on two fractions. Return the most simplified form of the result.
/// You can assume a non-zero denominator in the input, and don’t use any
/// built-in implementations in your language of choice, if you can!
///
/// Example:
///
/// ```
@wperron
wperron / main.rs
Created March 7, 2023 14:41
scramble string, but still readable
use rand::seq::SliceRandom;
/// If you mix up the order of letters in a word, many people can slitl raed and urenadnstd tehm. Write a function that
/// takes an input sentence, and mixes up the insides of words (anything longer than 3 letters).
///
/// Example:
///
/// ```
/// > scramble(["A quick brown fox jumped over the lazy dog."])
/// > "A qciuk bwron fox jmepud oevr the lzay dog."
@wperron
wperron / main.rs
Created February 27, 2023 14:07
Given a list of numbers, return all groups of repeating consecutive numbers.
/// Given a list of numbers, return all groups of repeating consecutive numbers.
///
/// Examples:
///
/// ```
/// > repeatedGroups([1, 2, 2, 4, 5])
/// [[2, 2]]
///
/// > repeatedGroups([1, 1, 0, 0, 8, 4, 4, 4, 3, 2, 1, 9, 9])
/// [[1, 1], [0, 0], [4, 4, 4], [9, 9]]
@wperron
wperron / main.rs
Created February 20, 2023 17:10
balance parens
/// Given a string of parenthesis, return the number of parenthesis you need to add to the string in order for it to be balanced.
///
/// Examples:
///
/// ```bash
/// > numBalanced(`()`)
/// > 0
///
/// > numBalanced(`(()`)
/// > 1
@wperron
wperron / main.rs
Created December 19, 2022 17:17
Given a string, make every consonant after a vowel uppercase.
fn main() {
println!("{}", capitalize_post_vowels("Hello, World!".to_string()));
}
/// Given a string, make every consonant after a vowel uppercase.
fn capitalize_post_vowels(s: String) -> String {
let mut prev = false;
s.chars()
.into_iter()
@wperron
wperron / Cargo.toml
Created December 14, 2022 15:08
Breaking OpenTelemetry `global::shutdown_tracer_provider`
[package]
name = "tokio-lifetime"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
opentelemetry = { version = "0.18.0", features = ["rt-tokio"] }
opentelemetry-otlp = "0.11.0"
@wperron
wperron / main.rs
Created November 21, 2022 15:35
Write a function that takes a string of slashes (\ and /) and returns all of those slashes drawn downwards in a line connecting them.
use std::{io::stdout, io::Write};
fn main() {
indent_slashes(&mut stdout(), "\\\\\\\\//\\\\\\////").unwrap();
}
/// takes a string of slashes (\ and /) and returns all of those slashes drawn
/// downwards in a line connecting them.
///
/// Example:
@wperron
wperron / Gemfile
Created November 1, 2022 15:32
Server example for TraceResponse in opentelemetry-ruby
# frozen_string_literal: true
source "https://rubygems.org"
gem "faraday", "~> 0.16.1"
gem "opentelemetry-api"
gem "opentelemetry-common"
gem "opentelemetry-sdk-experimental", path: '../../sdk_experimental'
gem "sinatra", "~> 2.0"
gem "puma"