Skip to content

Instantly share code, notes, and snippets.

View NuroDev's full-sized avatar
🌈

Ben NuroDev

🌈
View GitHub Profile
@NuroDev
NuroDev / bunfig.toml
Last active March 27, 2025 09:57
🔌 Bun HTTP import plugin
preload = ['./path/to/plugin.ts']
@NuroDev
NuroDev / mod.ts
Created April 16, 2025 00:50
💎 Zod - `X` or `X_FILE` transformer
import { z } from 'zod';
function transformFileProperty<T extends string>(key: T) {
return (data: Record<string, string>) => {
if (data[key]) {
return {
[key]: data[key],
} as {
[P in T]: string;
};
@NuroDev
NuroDev / example.ts
Last active July 9, 2025 14:06
🦺 A minimal `Result` type system for TypeScript
import { Err, Ok, PromiseResult } from 'path/to/module';
interface User {
// ...
}
enum UserError {
USER_NOT_FOUND = 'USER_NOT_FOUND',
}
@NuroDev
NuroDev / queue-controller.ts
Created October 13, 2025 11:15
⏭️ Queue Controller - A minimal `Hono` style controller for Cloudflare Workers `queue`
import { env } from 'cloudflare:workers';
import type { z } from 'zod';
export type QueueBody = {
payload?: unknown;
type: string;
};
type KeysOfType<T, V> = {
@NuroDev
NuroDev / worker.ts
Last active October 16, 2025 00:39
🚦 UniFi Relay | Remap UniFi Network alert events & forward them to Discord
export default {
fetch: async (request, env) => {
if (request.method !== 'POST')
return new Response('Method Not Allowed', { status: 405 });
const json = await request
.json<{
alarm_id: string;
events: Array<{
alert_id: string;
@NuroDev
NuroDev / schedule-controller.ts
Created November 21, 2025 16:36
⏲️ Schedule Controller - A minimal `Hono` style controller for Cloudflare Workers scheduled handler
export interface ScheduleHandlerContext<E = Env> {
/**
* The scheduled event controller providing details about the cron trigger.
*/
controller: ScheduledController;
/**
* The environment bindings available to the worker.
*/
env: E;
/**
@NuroDev
NuroDev / osc-progress-demo.ts
Last active June 9, 2026 10:10
📊 OSC 9;4 terminal progress example
// Or use the `osc-progress` package
enum ProgressState {
Hidden = 0,
Normal = 1,
Error = 2,
Indeterminate = 3,
Warning = 4,
}