Skip to content

Instantly share code, notes, and snippets.

View okikio's full-sized avatar
🏠
Working from home

Okiki Ojo okikio

🏠
Working from home
View GitHub Profile
@okikio
okikio / constrain-transform-stream-queues.md
Created September 1, 2024 03:21
Queue's via TransformStreams

Using TransformStream in place of traditional queue implementations is an interesting approach that leverages the stream API's natural queuing and backpressure features. Below is a breakdown of how you might implement each queue type using TransformStream, adhering to the constraint of using no more than 2 TransformStreams per queue, and addressing any limitations that arise.

1. Simple Queue (FIFO Queue)

  • Implementation:
    • TransformStream 1: This stream simply passes data from the writable side to the readable side in FIFO order.
    • TransformStream 2: Not necessary in this case, as one TransformStream is sufficient to maintain the FIFO order.
const fifoQueue = new TransformStream({
transform(chunk, controller) {
@okikio
okikio / split-iter.ts
Last active August 21, 2024 06:10
Splits a single iterator into 2 separate async iterators by some predicate or by whether an error occurs or not.
/**
* An async generator function that pulls values from the source async iterator.
*
* @template T The type of values being yielded from the source iterator.
*
* This generator yields values it receives from an external source (via `yield`).
* It also receives an initial value when invoked, which is yielded first.
*
* ### How it Works
*
// Target object
const target = {
foo: 1,
bar: 2,
};
// Fallback object
const fallback = {
bar: 20, // This will be overridden by target's bar
baz: 3,
import type { Logger as LogTapeLogger } from "@logtape/logtape";
import { deepMerge } from "@bundle/utils/utils/deep-equal.ts";
import { getLogger } from "@logtape/logtape";
export const initLogger = getLogger(["@bundle/core", "init"]);
export const buildLogger = getLogger(["@bundle/core", "build"]);
export const generalLogger = getLogger(["@bundle/core", "general"]);
// Add more loggers as needed
import type { Filter } from "./filter.ts";
import type { LogLevel } from "./level.ts";
import type { LogRecord } from "./record.ts";
import type { Sink } from "./sink.ts";
/**
* A logger interface. It provides methods to log messages at different
* severity levels.
*
* ```typescript
@okikio
okikio / spec.md
Last active June 29, 2024 08:46
Compressed Typescript Import and Export Notation (CTIE Notation)

Specification for TypeScript Import and Export Notation

Overview

This specification defines a notation format for representing TypeScript imports and exports. It is designed to be concise, flexible, and easily understandable, suitable for use in various contexts including configuration files, command-line interfaces, and documentation.

Format Design

Basic Structure

  • Imports and Exports: Use - to start import declarations and ~ to start export declarations.
  • Namespace Imports: Double bangs !! indicate namespace imports (e.g., * as name).
@okikio
okikio / oauth2.ts
Created May 5, 2024 02:49
Google OAuth2 w/ Deno & Hono
import { CLIENT_ID, CLIENT_SECRET } from "~/env.ts";
import { gmail_v1, auth } from "@googleapis/gmail";
import { Hono } from '@kyiro/hono';
import open from 'open';
const REDIRECT_URI = "http://localhost:8000/token";
const SCOPE = "https://www.googleapis.com/auth/gmail.readonly";
console.log({
SCOPE,
@okikio
okikio / filesystem.ts
Last active June 24, 2024 04:28
How to integrate into the esbuild wasm file system built into the package. Think esbuild-wasm-fs
// Based off of https://github.com/esbuild/esbuild.github.io/blob/main/src/try/fs.ts
// GitHub Permalink: https://github.com/esbuild/esbuild.github.io/blob/d405aa5f06ef359430344ca7fcbbc9bc8acf620e/src/try/fs.ts
// This file contains a hack to get the "esbuild-wasm" package to run in the
// browser with file system support. Although there is no API for this, it
// can be made to work anyway by pretending that node's "fs" API is present.
import { decode, encode } from "./encode-decode";
const enum Kind {
File,
@okikio
okikio / private-field-event-handler-delegation.ts
Last active June 20, 2024 20:56
A way to keep event handler private, but still benefit from a constant event listener object, decreasing memory overhead and ensuring private fields stay private. Inspired by https://webreflection.medium.com/dom-handleevent-a-cross-platform-standard-since-year-2000-5bf17287fd38. Demo https://codepen.io/okikio/pen/QWRmdxm
export class Component {
/**
* For perf. reasons use a class to delagate event handlers,
* this lets us avoid binds and arrow functions which have memory overhead,
* in addition since it's always the same instance of the same class,
* so it's super easy to remove later on
*
* Based on https://webreflection.medium.com/dom-handleevent-a-cross-platform-standard-since-year-2000-5bf17287fd38
*/
static #eventhandlers = new WeakMap();
@okikio
okikio / ideas.md
Created March 27, 2024 06:02
Unified URI Spec. Brainstorm

Unified URI Spec. Brainstorm

Hey 👋, I was working on the proposals for unifying the URL specs. From the research I’ve done on the topic so far, we’d need a total of 2 RFC's to solve to problem and ensure it never occurs again.

Unified URI RFC (RFC 1)

The 1st RFC (The Unified URI RFC) will use the original 2005 URI RFC as it’s basis, then build on top of it the modern WHATWG URL standard. Alwin Blok already created a new URL Spec. proposal to try to accomplish this very goal, we’ll investigate what changes there are between both RFC’s and the new proposal by Alwin, and look to create a Unified RFC from that.

Some ideas that @Randall, Jonathan Neal, and I played with were separating URI’s and URL’s.

  • URI’s represent any form a path locator ca