Skip to content

Instantly share code, notes, and snippets.

Avatar
👻
A ghost

Nathan myobie

👻
A ghost
View GitHub Profile
@myobie
myobie / ci.yml
Last active Jan 27, 2023
Don't run GitHub Actions for pull requests that are drafts
View ci.yml
on:
push:
branches:
- master
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
@myobie
myobie / expand-all-files-on-github-diff-page.js
Created Oct 6, 2022
I couldn't find an "expand all" button, so I just made my own
View expand-all-files-on-github-diff-page.js
document.querySelectorAll('button[aria-label="Toggle diff contents"]').forEach(b => b.click())
@myobie
myobie / application.ex
Last active Sep 20, 2022
Using Finch with ExAws
View application.ex
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 / generate-importable-blob.ts
Created Mar 25, 2022
Generate Blob import from file on disk with deno
View generate-importable-blob.ts
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 Mar 15, 2022
A cloudflare worker to remove the www subdomain and redirect
View remove-www.js
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 Feb 10, 2022
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.
View async_iterators_throw_catch_test.ts
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 / service-worker.ts
Last active Nov 17, 2021
A small example of a service worker in typescript along with the tsconfig.json that allows tsserver and IDEs to understand what's going on
View service-worker.ts
// NOTE: We must export or import at least one thing so we are not in
// the "global" scope, but in a module scope which is re-declarable.
//
// The error from tsserver is: 2451: Cannot redeclare block-scoped
// variable 'self'.
//
// Even tho this is not really a module and cannot be: ServiceWorkers
// cannot be modules.
export type Version = number
@myobie
myobie / mountain-lion-brew-setup.markdown
Created Feb 18, 2012
Get Mountain Lion and Homebrew to Be Happy
View mountain-lion-brew-setup.markdown

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.

@myobie
myobie / deferred.ts
Created Aug 2, 2021
My own promise-like object where I can type the rejection and I can resolve from the outside
View deferred.ts
export class Deferred<T = void, E = Error> {
#promise: Promise<T>
// deno-lint-ignore ban-ts-comment
// @ts-ignore
resolve: (arg: T) => void
// deno-lint-ignore ban-ts-comment
// @ts-ignore
reject: (arg: E) => void
constructor() {
@myobie
myobie / task.ts
Created Jul 30, 2021
Very simple deno script to test that deno works
View task.ts
console.log('Fetching...')
const res = await fetch('https://example.com')
const body = new Uint8Array(await res.arrayBuffer())
console.log('---')
await Deno.stdout.write(body)
console.log('---')
console.log('Done.')