Skip to content

Instantly share code, notes, and snippets.

A ghost

Nathan myobie

A ghost
View GitHub Profile
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 / task.ts
Created Jul 30, 2021
Very simple deno script to test that deno works
View task.ts
const res = await fetch('')
const body = new Uint8Array(await res.arrayBuffer())
await Deno.stdout.write(body)
myobie / server.ts
Created Jul 29, 2021
Very simple deno webserver mostly exactly from the example in the docs at
View server.ts
// Start listening on port 8080 of localhost.
const server = Deno.listen({ port: 8080 })
console.log('HTTP webserver running...')
const headers = Object.freeze({
'Content-type': 'plain/text'
for await (const conn of server) {
// deno-lint-ignore no-extra-semi
myobie / params.ex
Created May 26, 2021
I'm not saying this is a good idea, but I'm not not saying it
View params.ex
defmodule POC.Params do
import Ecto.Changeset
@spec permit(map, map) :: map
def permit(input, types) do
{types, nested} = Enum.reduce(types, {%{}, %{}}, &process_types/2)
{%{}, types}
|> cast(input, Map.keys(types))
|> permit_nested(nested)
myobie / router.ex
Last active Apr 15, 2021
A pipeline for proxying large file uploads
View router.ex
defmodule AppWeb.Router do
use AppWeb, :router
pipeline :browser do
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()
plug Plug.MethodOverride
myobie / poller.ex
Last active Apr 8, 2021
GenServer for longpoll requests with backoff in case of errors
View poller.ex
defmodule Example.Poller do
use GenServer
@backoff [
View identifier.swift
import Foundation
public struct Identifier:
Codable, CustomStringConvertible, ExpressibleByStringLiteral,
Hashable, RawRepresentable
public let rawValue: [UInt8]
public let dataValue: Data
private let stringValue: String

Previewing encrypted content on the web

This would be an extension to The Open Graph protocol.

As more and more people are using privacy preserving tools for sharing content on the web, more content embedded into web pages will be end-to-end encrypted and decrypted in-browser by javascript or wasm code.

A current problem with previews of web URLs is they require the server to know the exact contents of the URL and be able to provide a preview as a resource either inside a header or as a URL to an image. If the primary content at the URL were encrypted, no preview could be provided directly by the server.

What the server could provide is an encrypted preview which was encrypted with a symmetric key by the original creator using one of the standard algorithms provided by webcrypto. Then the browser/client could find the decryption key in the URL fragment (or prompt the user for it) to then facilitate the decryption of the preview content safely on device. This would provide a standard

myobie / application.ex
Last active Apr 1, 2021
Using Finch with ExAws
View application.ex
defmodule Example.Application do
@moduledoc false
use Application
def start(_type, _args) do
children = [
{Phoenix.PubSub, name: Example.PubSub},
View runner.ts
const worker = new Worker('/tests.js')
worker.onmessage = e => {
if ( && {
if ( === 'console') {
const type = || 'log'
const msg = || '<empty>'
switch (type) {
case 'error':