Skip to content

Instantly share code, notes, and snippets.

View scarf005's full-sized avatar

scarf scarf005

View GitHub Profile
@scarf005
scarf005 / fetch-aoc.ts
Last active July 15, 2023 11:50
fetches advent of code inputs
import * as dotenv from "https://deno.land/[email protected]/dotenv/mod.ts"
import { basename } from "https://deno.land/[email protected]/path/mod.ts"
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts"
import { z } from "https://deno.land/x/[email protected]/mod.ts"
import { asynciter } from "https://deno.land/x/[email protected]/mod.ts"
import { difference } from "https://deno.land/x/[email protected]/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/[email protected]/mod.ts"
import { readAll } from "https://deno.land/[email protected]/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}
@scarf005
scarf005 / mapEntries.ts
Created June 10, 2023 22:26
unnecesarily complex useform with only string input
export const mapEntries = <T, U>(
obj: Record<string, T>,
fn: (entry: [string, T]) => [string, U],
) => Object.fromEntries(Object.entries(obj).map(fn))
@scarf005
scarf005 / removeIsOpen.ts
Created June 7, 2023 02:13
removes is:open from issues and discussions (only for Q&A).
const getUrl = (elem: Element) => elem.getAttribute("href")!.split("?")[0]
const setQuery = (selector: string, query: string) => () => {
const elem = document.querySelector(selector)
if (!elem) {
console.log(`elem with ${selector} not found`)
return
}
const newSearchParams = new URLSearchParams({ q: query })
elem.setAttribute("href", `${getUrl(elem)}?${newSearchParams}`)
@scarf005
scarf005 / README.md
Last active December 11, 2023 07:30
statistics
@scarf005
scarf005 / initdeno.ts
Last active June 6, 2023 13:43
initialize deno with vscode settings, no semicolon, and line width 100
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run --allow-env --unstable
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts"
import { dirname, join } from "https://deno.land/[email protected]/path/mod.ts"
import { c, p } from "https://deno.land/x/[email protected]/mod.ts"
const mapKeys =
<A>(f: (k: string) => string) => (record: Readonly<Record<string, A>>): Record<string, A> =>
Object.fromEntries(Object.entries(record).map(([k, v]) => [f(k), v]))
import {
bgBrightRed,
bold,
brightGreen,
brightRed,
brightWhite,
brightYellow,
} from "https://deno.land/[email protected]/fmt/colors.ts"
import { c, p } from "https://deno.land/x/[email protected]/mod.ts"
import { match } from "npm:ts-pattern"
declare global {
interface PromiseConstructor {
resolve<const T>(value: T): Promise<Awaited<T>>
}
}