Skip to content

Instantly share code, notes, and snippets.

View supermacro's full-sized avatar
🎯
Focusing

Gio supermacro

🎯
Focusing
View GitHub Profile
@supermacro
supermacro / images.md
Last active November 29, 2023 18:07
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
}
export const fetchComments = async ({
postId,
host
}: RequestInfo): Promise<Result<Array<Comments.Schema>, string>> => {
try {
const comments = await db(Comments.Table.name)
.select(everything(Comments.Table))
.join(
Posts.Table.name,
`${Comments.Table.name}.${Comments.Table.cols.post_id}`,