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 / 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"
@wperron
wperron / main.rs
Created October 31, 2022 14:42
print the printable portion of ascii character space
use std::io::{self, Write};
fn main() {
write_ascii(std::io::stdout()).unwrap();
}
fn write_ascii<W: Write>(mut w: W) -> Result<(), io::Error> {
let chars = (0x20 as u8..0x7e + 1 as u8)
.into_iter()
.map(|b| char::from(b))
@wperron
wperron / main.rs
Created September 26, 2022 12:08
Return a string corresponding to the ordinal of the given integer using Rust's pattern matching
fn main() {
println!("Hello, world!");
}
pub fn ordinal(num: isize) -> String {
let one = num % 10;
let ten = (num / 10) % 10;
match (one, ten) {
(o, t) if t == 1 && o > 0 && 0 <= 3 => format!("{}th", num),
@wperron
wperron / main.rs
Created August 1, 2022 13:17
Get the number of ones in all positive integers less than or equal to N
fn main() {
println!("{}", number_of_ones(14));
}
/// Given an integer n, count the total number of 1 digits appearing in all non-negative integers less than or equal to n.
///
/// Example:
///
/// ```bash
/// > numberOfOnes(14)