Skip to content

Instantly share code, notes, and snippets.

View scarf005's full-sized avatar

scarf scarf005

View GitHub Profile
@scarf005
scarf005 / closure_bench.ts
Last active January 8, 2024 02:08
Inline your callbacks
const f = (g: (x: number) => number) => (x: number) => g(x)
Deno.bench("closure directly", { baseline: true }, () => {
const foo = [...Array(1000).keys()].map(f((x) => x + 1))
})
Deno.bench("closure indirectly", () => {
const g = f((x) => x + 1)
const foo = [...Array(1000).keys()].map(g)
})
// ==UserScript==
// @name Discord Toggle Sidebar
// @namespace https://github.com/scarf005
// @homepage https://gist.github.com/scarf005/5849921063d34744fde3494abd5ea107
// @updateURL https://gist.githubusercontent.com/scarf005/5849921063d34744fde3494abd5ea107/raw/toggle_sidebar.user.js
// @downloadURL https://gist.githubusercontent.com/scarf005/5849921063d34744fde3494abd5ea107/raw/toggle_sidebar.user.js
// @version 0.6.0
// @description Toggles Discord sidebar
// @author scarf
// @license MIT
@scarf005
scarf005 / snake_case.ts
Created September 11, 2023 23:12
rename all files to be snake_case
import { walk } from "https://deno.land/std@0.201.0/fs/walk.ts"
import { join } from "https://deno.land/std@0.201.0/path/join.ts"
import { parse } from "https://deno.land/std@0.201.0/path/parse.ts"
import { asynciter } from "https://deno.land/x/asynciter@0.0.18/mod.ts"
import { snakeCase } from "https://deno.land/x/case@2.1.1/mod.ts"
if (import.meta.main) {
// walk all markdown files in doc/src/content, and rename filenames to snake_case
await asynciter(walk("doc/src/content", { exts: ["md"], includeDirs: false }))
.map(({ path }) => ({ path, ...parse(path) }))
@scarf005
scarf005 / dcinside custom filter
Last active October 28, 2023 00:05
dcfilter.txt
! Title: Clean DCInside UI
! Homepage: https://gist.github.com/scarf005/50451bd971f647da7b4f5f79798a53e6/edit
! 로갤 로스트아크갤 구분
||https://gall.dcinside.com/board/lists/?id=lostark$all
google.*##.g:has(a[href*="https://gall.dcinside.com/board/lists/?id=lostark"])
||dcimg5.dcinside.com/dccon.php?no=62b5df2be09d3ca567b1c5bc12d46b394aa3b1058c6e4d0ca41648b65feb246efc7dee44a100573d4877e943faabd47cae7095ad596fb484b6618dc825dbe838dcd667f5$image
{-# LANGUAGE NoImplicitPrelude #-}
import Data.Bool (Bool, (&&), (||))
import Numeric.Natural (Natural)
import Prelude (Int, (+), (-))
{- |
마그마(Magma)는 집합과 '닫힌' 이항 연산자 (이항 연산의 결과가 집합에 속함)
(𝕄, •) ⊢ ∀ a, b ∈ 𝕄 ⟹ a • b ∈ 𝕄.

Visualizing typeclasses with mermaid diagram

id : a -> a

flowchart LR

a((a)) --> b((a))

classDef default stroke:#333,stroke-width:2px
@scarf005
scarf005 / fetch-aoc.ts
Last active July 15, 2023 11:50
fetches advent of code inputs
import * as dotenv from "https://deno.land/std@0.194.0/dotenv/mod.ts"
import { basename } from "https://deno.land/std@0.194.0/path/mod.ts"
import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.2/command/mod.ts"
import { z } from "https://deno.land/x/zod@v3.21.4/mod.ts"
import { asynciter } from "https://deno.land/x/asynciter@0.0.18/mod.ts"
import { difference } from "https://deno.land/x/set_operations@v1.1.1/mod.ts"
import { match, P } from "npm:ts-pattern@^5.0.3"
const cookieKey = "AOC_SESSION"
const cookieSchema = z.string().min(1, "Session cannot be empty!")
@scarf005
scarf005 / resp.ts
Created July 5, 2023 03:10
inferring responses
import { initContract, ServerInferResponseBody, ServerInferResponses } from "npm:@ts-rest/core"
import z, { boolean } from "npm:zod"
import { createExpressEndpoints, initServer } from "npm:@ts-rest/express"
// @deno-types=npm:@types/express
import express from "npm:express"
const dataSchema = z.object({ data: z.boolean().default(false) })
type DataInfer = z.infer<typeof dataSchema>
type DataInput = z.input<typeof dataSchema>
@scarf005
scarf005 / clip
Last active November 2, 2023 07:22
tiny, fast clipboard util
#!/usr/bin/env -S deno run --allow-run --allow-read --no-config --no-check --no-npm
import clipboard from "https://deno.land/x/clipboard@v0.0.2/mod.ts"
import { readAll } from "https://deno.land/std@0.192.0/streams/mod.ts"
const filename = Deno.args[0]
if (filename) {
const text = await Deno.readTextFile(filename)
await clipboard.writeText(text)
} else if (!Deno.isatty(Deno.stdin.rid)) {
@scarf005
scarf005 / bash-in-a-jar.bash
Last active June 14, 2023 02:16
Bash in a jar
#!/usr/bin/env bash
readonly GREEN='\033[32m'
readonly NC='\033[0m'
header() { printf "${GREEN}$@${NC}"; }
readonly LOCATION=$(pwd)/bash-in-a-jar
header "installation location:\n"
echo ${LOCATION}