This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BUFFER_CAPACITY: usize = 4; | |
pub struct Buffer { | |
size: usize, | |
read_idx: usize, | |
write_idx: usize, | |
buffer: [u8; BUFFER_CAPACITY] // unsigned 8bit integer | |
} | |
NewerOlder