Skip to content

Instantly share code, notes, and snippets.

View myobie's full-sized avatar

Nathan myobie

View GitHub Profile
@myobie
myobie / full-stacktrace.txt
Created June 19, 2023 19:03
Internal application error: TypeError: cannot read headers: request closed
Internal application error: TypeError: cannot read headers: request closed
at Object.get headerList (ext:deno_fetch/23_request.js:115:17)
at Request.request.<computed> (ext:deno_fetch/23_request.js:565:60)
at Request.get [headers] (ext:deno_fetch/23_request.js:252:46)
at Request.get headers (ext:deno_fetch/23_request.js:452:16)
at NativeRequest.get headers (https://deno.land/x/oak@v12.5.0/http_server_native_request.ts:72:26)
at new Request (https://deno.land/x/oak@v12.5.0/request.ts:150:21)
at new Context (https://deno.land/x/oak@v12.5.0/context.ts:172:20)
at Application.#handleRequest (https://deno.land/x/oak@v12.5.0/application.ts:450:17)
at Application.listen (https://deno.land/x/oak@v12.5.0/application.ts:656:28)
@myobie
myobie / application.ex
Last active May 8, 2023 23:21
Using Finch with ExAws
defmodule Example.Application do
@moduledoc false
use Application
def start(_type, _args) do
children = [
Example.Repo,
ExampleWeb.Telemetry,
{Phoenix.PubSub, name: Example.PubSub},
@myobie
myobie / effect-with-previous-value.ts
Created April 4, 2023 09:09
Sometimes I want to know the previous value for an effect
import { effect } from '@preact/signals-core'
export function effectWithPreviousValue<T>(
initialValue: T,
compute: (prev: T) => T
): () => void {
let prev = initialValue
return effect(() => {
prev = compute(prev)
@myobie
myobie / complex-signal.ts
Last active March 29, 2023 11:09
A simple, non-performance-optimized way to keep a Set, Map, etc in a Signal
import { signal } from '@preact/signals'
export type ComplexSignal<T> = {
value: T
peek: T
subscribe: (cb: (t: T) => void) => () => void
update: (cb: (t: T) => void) => void
}
export function complexSignal<T>(initialValue: T): ComplexSignal<T> {
@myobie
myobie / create_slides.exs
Created April 20, 2017 21:20
Elixir code to generate a json file of all the svg slides in a directory
# curry the write function
write_data = &(File.write!("./assets/slides.json", &1))
Path.wildcard("./assets/slides/*.svg")
|> Enum.sort()
|> Enum.map(&Path.basename/1)
|> Enum.with_index(1)
|> Enum.map(fn {file, index} -> {file, Path.basename(file, ".svg"), index} end)
|> Enum.map(fn {file, name, index} ->
%{
@myobie
myobie / expand-all-files-on-github-diff-page.js
Created October 6, 2022 08:19
I couldn't find an "expand all" button, so I just made my own
document.querySelectorAll('button[aria-label="Toggle diff contents"]').forEach(b => b.click())
@myobie
myobie / generate-importable-blob.ts
Created March 25, 2022 11:04
Generate Blob import from file on disk with deno
const bytes = await Deno.readFile(new URL('./thumbnail.png', import.meta.url))
const encoder = new TextEncoder()
const contents = encoder.encode(
`export const thumbnail = new Blob(new Uint8Array(${
JSON.stringify(Array.from(bytes))
}), { type: 'image/png' })`
)
await Deno.writeFile(new URL('./hardcoded-thumbnail.ts', import.meta.url), contents)
@myobie
myobie / remove-www.js
Created March 15, 2022 13:32
A cloudflare worker to remove the www subdomain and redirect
const status = 301
addEventListener('fetch', event => {
const url = new URL(event.request.url)
url.hostname = url.hostname.replace(/^www\./, '')
event.respondWith(Response.redirect(url.toString(), status))
})
@myobie
myobie / async_iterators_throw_catch_test.ts
Last active February 10, 2022 11:40
I was testing to see if the next() in an async iterator worked how I suspected, where throws are really Promise.reject() which throws at the for await point.
import { assertEquals } from 'https://deno.land/std@0.125.0/testing/asserts.ts'
Deno.test('async iterator throw in next should throw in for scope', async () => {
const results: number[] = []
const numbers = (() => {
let counter = 0
const iterator: AsyncIterator<number> = {
// deno-lint-ignore require-await
@myobie
myobie / mountain-lion-brew-setup.markdown
Created February 18, 2012 20:14
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.