Skip to content

Instantly share code, notes, and snippets.

View NuroDev's full-sized avatar
🌈

Ben NuroDev

🌈
View GitHub Profile
@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 / 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 / example-wrangler.jsonc
Last active October 19, 2025 23:15
⏲️ Schedule Controller - A minimal `Hono` style controller for Cloudflare Workers `scheduled`
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "example-scheduled-worker",
"main": "src/index.ts",
"compatibility_date": "2025-10-01",
"triggers": {
"crons": [
"0 8 * * *",
"*/30 * * * *"
]
@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 / 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 / bunfig.toml
Last active March 27, 2025 09:57
🔌 Bun HTTP import plugin
preload = ['./path/to/plugin.ts']
@NuroDev
NuroDev / latench.sh
Last active June 6, 2025 09:52
⏱️ Measure latency to a provided URL & show the min, max & average results
latency() {
# Check if URL is provided
if [[ -z "$1" ]]; then
echo "Error: URL is required"
echo "Usage: latency <url> [number_of_requests]"
return 1
fi
local url="$1"
local times=${2:-10}
@NuroDev
NuroDev / cloud-config.yml
Created December 15, 2024 00:43
☁️ A `cloud-config` script for configuring a fresh Ubuntu server to be secure
#cloud-config
# Variables:
# - `ssh_authorized_keys`: A YAML encoded list of SSH public keys to add to the user's `authorized_keys` file
# - `timezone`: The timezone to set the system to
# - `username`: The username of the user to create
disable_root: true
manage_resolv_conf: true
package_reboot_if_required: true
@NuroDev
NuroDev / deno.ts
Last active November 21, 2024 23:22
🔒 Remap environment variables ending in `_FILE` with the contents of the file
import { existsSync } from "@std/fs/exists";
interface LoadOptions {
/**
* Whether to overwrite existing env vars.
*
* @default false
*/
overwrite?: boolean;
/**
const ChuckNorrisFact = z.object({
icon_url: z.string().url(),
id: z.string().min(1),
url: z.string(),
value: z.string(),
});
const UserOptions = z
.object({
category: z.enum([