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
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 / filesystem.ts
Last active December 5, 2025 00:12
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 / 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 / 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
@okikio
okikio / mod.ts
Created January 5, 2024 07:53
Un-Escape Typescript Code
import * as ts from "https://esm.sh/typescript"
/**
* Determines whether escape sequences in a token of a specific kind should be preserved.
* Useful for maintaining the integrity of literals where escape characters are meaningful.
*
* @example
* // Simple: In string literals like `"Hello\nWorld"`, the `\n` should be preserved.
* shouldPreserveEscapes(ts.SyntaxKind.StringLiteral);
*
@okikio
okikio / dom-expressions.ts
Created June 10, 2023 01:00
dom-expressions.ts
import { signal, effect } from 'https://esm.sh/usignal';
// Function to check if an expression is iterable
function isIterable(expression) {
return Symbol.iterator in Object(expression);
}
// Function to create a new DOM range for an expression
function createDOMRange(domElement, expression) {
const textNode = document.createTextNode(evaluateExpression(expression.expr));
@okikio
okikio / opfs.ts
Created April 21, 2023 23:43
opfs.ts - API
const isWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
async function getHandleFromPath(path: string) {
const pathParts = path.split('/').filter(part => part.length > 0);
let currentHandle = await navigator.storage.getDirectory();
for (const part of pathParts) {
if (part === '..') {
currentHandle = await currentHandle.getParent();
} else {