Skip to content

Instantly share code, notes, and snippets.

@geelen
geelen / curl + jq.md
Created January 26, 2023 21:23
ZSH aliases
@geelen
geelen / maybe-error.md
Last active January 4, 2024 22:51
"Maybe Error" pattern in Typescript

"Maybe Error" pattern in Typescript

TL;DR? 👉 Implementation.

Inspiration

So one of the things I've liked about working with Go is that you use multiple return values a lot, with early exits that work as a kind of guard:

func GetUserFromAuth(name string, auth Auth) (error, User) {
@geelen
geelen / idea.md
Last active June 11, 2020 19:51
Cracking the Cryptic webapp helper

Cracking the Cryptic sudoku webapp helper

This just detects if you've made a clear error as you're solving something (only looks at the basic sudoku rules, nothing fancy):

image

To install, just open your developer console (⌘⇧I or Cmd Shift I, then select console) and paste in the source code below:

@geelen
geelen / a.md
Last active May 29, 2020 17:34
(all night) Long HTTP Request demo

Example of FAB streaming.

  1. Open https://www.youtube.com/watch?v=nqAvFx3NxUM
  2. Paste the following in the terminal:
curl "https://despacito.glen.workers.dev/?https://gist.githubusercontent.com/geelen/779758741e57f717a93e7bff7f2a6c5f/raw/ac8eb260f7fd2130ff5b648b91924ce1262262b0/lyrics.vtt"
  1. About 11 seconds into the video, hit enter.
@geelen
geelen / traits.ts
Created April 7, 2020 10:03
ARGH TYPESCRIPT WHY WONT YOU OBEY ME
import { css } from 'styled-components'
type RulesDefn = {
[k: string]: string
}
type TrainBuilder<T extends RulesDefn> = {
[k in keyof T]: TrainBuilder<T>
} & {
toString: () => string[]
@geelen
geelen / input.js
Created December 9, 2019 15:07
Proxy memo async
const someExpensiveOperation = async x => {
await new Promise(resolve => setTimeout(resolve, 1000))
return x.toUpperCase()
}
const PROXY_MEMO = Object.create(
new Proxy(
{},
{
get(_, handler) {
type Query = {
book(id: ID!): Book!
author(id: ID!): Author!
}
type Book = {
id: ID!
name: String
author: Author
}
root@vps190992:~/go/bin# ./hey https://serverless-ssr.now.sh/ssr/preact
Summary:
Total: 14.7408 secs
Slowest: 6.9887 secs
Fastest: 0.2357 secs
Average: 1.9901 secs
Requests/sec: 13.5678
(async () => {
const rows = 44
const cols = 36
const fps = 12
const gif = "http://i.imgur.com/ifR7csn.gif"
const rotate = false
const mirror = false
const vertmirror = false
document.body.innerHTML = ''
(async () => {
const cols = 44
const rows = 36
const size = 90
const speedX = 0.02
const speedY = 0.0
const loadImage = url => {
const img = document.createElement('img')