Skip to content

Instantly share code, notes, and snippets.

View frectonz's full-sized avatar

Fraol Lemecha frectonz

View GitHub Profile
import {
Dispatch,
ReactNode,
useContext,
useReducer,
createContext,
} from "react";
export interface StoreProviderProps {
children?: ReactNode;
function replaceZeros(input: string): number {
let zeroes = 0;
const res = input
.split("")
.reduce((acc: string[], curr, index, digits) => {
const next = digits[index + 1];
if (curr === "0" && next === "0") {
zeroes++;
@frectonz
frectonz / maxSubArray.go
Created January 2, 2023 11:06
From cassido's January 2, 2023 Newsletter
package main
import "fmt"
func main() {
res1 := maxSubArray([]int{-4, 2, -5, 1, 2, 3, 6, -5, 1}, 4)
fmt.Println(res1)
res2 := maxSubArray([]int{1, 2, 0, 5}, 2)
fmt.Println(res2)
}
@frectonz
frectonz / missingBits.go
Last active January 23, 2023 16:13
From cassido's January 23, 2023 Newsletter
package main
import (
"fmt"
"strconv"
)
func main() {
val1 := missingBits([]int{1, 2, 3, 4, 20, 21, 22, 23})
fmt.Println(val1)
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 {
@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]);
}
@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 / 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 / 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 / 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>();