Skip to content

Instantly share code, notes, and snippets.

@danew
danew / replace-alias-with-relative-imports.ts
Created February 23, 2024 11:11
A quick script to replace all the alias module imports with relative imports.
import ts from 'typescript';
import fs from 'fs';
import path from 'path';
const projectRoot = process.cwd();
const tsConfigPath = path.join(projectRoot, 'tsconfig.json');
const tsConfig = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
const parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, projectRoot);
@danew
danew / snippet.js
Created April 19, 2024 10:27
Print all elements and their z-index to console in descending order
(() => {
const elements = Array.from(document.querySelectorAll('*'));
const zIndexedElements = elements.map(element => ({
element,
zIndex: window.getComputedStyle(element).zIndex
}))
.filter(item => item.zIndex !== 'auto')
.sort((a, b) => b.zIndex - a.zIndex);
zIndexedElements.forEach(({ element, zIndex }) => {
@danew
danew / time-set.ts
Created May 8, 2024 10:43
Set with timestamps of when values were added with a purge by age helper
export class TimeSet {
private items: Map<string, number>;
constructor() {
this.items = new Map();
}
add(item: string) {
const timestamp = Date.now();
this.items.set(item, timestamp);
@danew
danew / debug.ts
Created April 8, 2025 09:10
Proxy-based debug logger when in development
export const isDev = process.env.NODE_ENV === 'development';
type ConsoleMethod = (...args: any[]) => void;
export const debug = new Proxy({} as Record<keyof Console, ConsoleMethod>, {
get(_, prop: keyof Console): ConsoleMethod {
const fn = console[prop] as (...args: any[]) => void;
if (!isDev || typeof fn !== 'function') return () => {};
return (...args: any[]) => fn('[Debug]', ...args);
}
@danew
danew / extend-wrangler.ts
Created May 2, 2025 20:51
Extend WrangleJson
import { WranglerJson, WranglerJsonSpec } from "alchemy/cloudflare";
import { writeFile } from "fs/promises";
import prettier from "prettier";
interface ExtendedWranglerJsonSpec extends WranglerJsonSpec {
migrations: {
tag: string;
new_sqlite_classes: string[];
}[];
}
@danew
danew / config.json
Created February 2, 2026 23:22
Opencode ask agent
# ~/.config/opencode/config.json
{
"$schema": "https://opencode.ai/config.json",
"agent": {
"ask": {
"description": "Answer questions about the codebase without making changes. Use this for exploring code, understanding architecture, finding files, and getting explanations.",
"mode": "primary",
"color": "#2E8B57",
"temperature": 0.2,
"tools": {