Skip to content

Instantly share code, notes, and snippets.

View frectonz's full-sized avatar
❄️

Fraol Lemecha frectonz

❄️
View GitHub Profile
export class LaunchControl {
private serverUrl: string;
private lastSessionState: "start" | "end" | null;
private trackingId: string;
constructor(serverUrl: string, trackingId: string) {
this.serverUrl = serverUrl;
this.lastSessionState = null;
this.trackingId = trackingId;
}
@frectonz
frectonz / pies.ml
Last active June 5, 2023 11:31
From cassidoo's Jun 5, 2023 Newsletter
let sum = List.fold_left (fun acc x -> acc + x) 0
type result = { pies : int; uneaten_pieces : int }
let pies pieces piece_per_pie =
let total_pieces = sum pieces in
let pies =
if total_pieces mod piece_per_pie == 0 then total_pieces / piece_per_pie
else (total_pieces / piece_per_pie) + 1
in
@frectonz
frectonz / oneRow.ml
Last active May 29, 2023 10:12
From cassidoo's May 29, 2023 Newsletter
module KeyToRowMap = Map.Make (Char)
let qwertyKeyToRowMap =
let firstRow = ['q'; 'w'; 'e'; 'r'; 't'; 'y'; 'u'; 'i'; 'o'; 'p'] in
let secondRow = ['a'; 's'; 'd'; 'f'; 'g'; 'h'; 'j'; 'k'; 'l'] in
let thirdRow = ['z'; 'x'; 'c'; 'v'; 'b'; 'n'; 'm'] in
KeyToRowMap.empty
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 1 acc) m firstRow)
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 2 acc) m secondRow)
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 3 acc) m thirdRow)
@frectonz
frectonz / oddSquareSum.ml
Last active May 8, 2023 09:55
From cassido's May 05, 2023 Newsletter
let int_sqrt x = x |> float_of_int |> sqrt |> int_of_float
(**
* [oddSquareNumber n]
* returns the sum of all odd square numbers less than [n]
*
* it does this by going through all the odd numbers from [1] to [sqrt(n)]
* and adding the square of each number to the sum if the square is less
* than [n].
*)
@frectonz
frectonz / maxPointsOnLine.ts
Last active April 17, 2023 09:55
From cassido's April 17, 2023 Newsletter
type Point = [number, number];
const slope = ([x1, y1]: Point, [x2, y2]: Point) => (y2 - y1) / (x2 - x1);
const makeKey = ([x1, y1]: Point, [x2, y2]: Point) =>
`(${x1},${y1}) -> (${x2},${y2})`;
const splitKey = (key: string): [string, string] =>
key.split(" -> ") as [string, string];
function maxPointsOnLine(points: Point[]) {
const slopes = new Map<string, number>();
@frectonz
frectonz / convert_color.rs
Last active March 20, 2023 17:15
From cassido's March 13, 2023 Newsletter
use std::str::FromStr;
#[derive(Debug)]
struct Rgb {
r: u8,
g: u8,
b: u8,
}
impl FromStr for Rgb {
@frectonz
frectonz / fraction_math.rs
Last active March 13, 2023 17:05
From cassido's March 13, 2023 Newsletter
use anyhow::{anyhow, Error, Result};
use std::{fmt::Display, str::FromStr};
#[derive(Debug, PartialEq, Eq)]
struct Fraction {
top: isize,
bottom: isize,
}
impl FromStr for Fraction {
@frectonz
frectonz / scramble.ts
Last active March 6, 2023 14:23
From cassido's March 6, 2023 Newsletter
function scramble(sentences: string[]): string {
return sentences
.map((sentence) =>
sentence
.split(" ")
.map((word) => {
if (word.length <= 3) {
return word;
}
@frectonz
frectonz / repeated_groups.rs
Last active February 27, 2023 21:10
From cassido's February 27, 2023 Newsletter
pub fn repeated_groups(numbers: &[u32]) -> Vec<Vec<u32>> {
numbers
.iter()
.fold::<Vec<Vec<u32>>, _>(vec![], |mut acc, &n| {
if let Some(last) = acc.last_mut() {
if last[0] == n {
last.push(n);
} else {
acc.push(vec![n]);
}
type Query {
hello: String!
allPosts(query: PostsQuery): [Post!]!
featuredPosts(query: PostsQuery): [Post!]!
postsInCategory(categoryId: Int!, query: PostsQuery): [Post!]!
allTags(query: TagsQuery): [Tag]
viewer: User!
}
type Post {