Skip to content

Instantly share code, notes, and snippets.

View supermacro's full-sized avatar
🎯
Focusing

Gio supermacro

🎯
Focusing
View GitHub Profile
const result = await this.getNotification(notificationId, clientId)
.andThen((notification) => this.executeSms(notification).map(() => notification))
.andThen((notification) => this.saveAndPublish(notification))
if (result.isOk()) {
return result.value
}
throw new Error(result.error)
@supermacro
supermacro / images.md
Last active November 6, 2024 15:23
Images

1

image


2

image

@supermacro
supermacro / wordle-solver.ts
Created November 17, 2023 01:10
wordle solver
// depends on the words_alpha.txt file from https://github.com/dwyl/english-words
import * as readline from 'readline'
const file = Bun.file('./words_alpha.txt')
const text = await file.text()
const wordleWords = text.split('\r\n').filter((w) => w.length === 5)
const prompt = (text: string): void => {
@supermacro
supermacro / pad.ts
Last active April 20, 2021 14:26
Functional `pad` implementation
interface PadConfig {
value: string
padding: string
requiredLength: number
}
export const pad = ({ value, padding, requiredLength }: PadConfig): string => {
const pads = Math.max(requiredLength - value.length, 0)
return Array(pads).fill(padding).concat(value).join('')
@supermacro
supermacro / Main.elm
Last active November 26, 2020 04:40
Nested Comment Tree Decoder
module Main exposing (main)
import Browser
import Html exposing (Html, div, text)
import Json.Decode as D exposing (Decoder)
{-
This module demonstrates how to decode a nested tree of nodes that are NOT infinitely recursive.
-}
type alias CommentTree =
@supermacro
supermacro / tree.elm
Created November 18, 2020 15:04
Thinking about tree structures in Elm
-- A tree contains 2 kinds of nodes
-- at depths 1 through 2 you will have a node with a 'replies' field
-- at depth 3 the node is missing a 'replies' field
type alias TreeNode a =
{ a
| body : String
}
@supermacro
supermacro / ResponsiveNav.elm
Last active November 9, 2019 02:10
Creating a responsive / toggleable responsive navigation bar with elm and tailwindcss
module ResponsiveNav exposing (withVnav, update, Msg)
import Html exposing (Html, div, header, nav)
import Html.Attributes as Attributes exposing (class)
import Html.Events exposing (onClick)
import UI.Icons exposing (logo, hamburger)
type alias Model a =
{ a |
@supermacro
supermacro / lolo.ts
Created April 9, 2019 15:47
TypeSafe `pick` and `omit` from lodash
const pickFunc = <T extends {}, K extends keyof T>(
obj: T,
predicate: (k: string) => boolean
): Pick<T, K> =>
Object
.keys(obj)
.filter(predicate)
.reduce((filteredObj: Pick<T, K>, key) => ({
...filteredObj,
[key]: obj[key as keyof T]
{-
Note that we use the `riskyRequest` function because this
webapp uses Cookies for authentication.
These cookies come from a different domain than the one
that host this app
-}
module Api exposing
( adminSignup
, adminSignin
, getAdminSession
const BUFFER_CAPACITY: usize = 4;
pub struct Buffer {
size: usize,
read_idx: usize,
write_idx: usize,
buffer: [u8; BUFFER_CAPACITY] // unsigned 8bit integer
}