Skip to content

Instantly share code, notes, and snippets.

View erikvullings's full-sized avatar

Erik Vullings erikvullings

View GitHub Profile
@erikvullings
erikvullings / debounce.ts
Last active June 6, 2025 18:57
Debounce a function, i.e. wait for a certain amount of time before executing the function. Often used when frequent edits would trigger a function multiple times, you can use this to wait for a certain amount of time before executing the function.
/**
* Debounce a function, i.e. wait for a certain amount of time before executing the function.
* Often used when frequent edits would trigger a function multiple times, you can use this to
* wait for a certain amount of time before executing the function.
*
* @param func The function to be debounced.
* @param delay The delay in milliseconds for the debounce.
* @returns A function that debounces the original function.
* @example const debouncedFunc = debounce(myFunction, 100); debouncedFunc(args);
@erikvullings
erikvullings / README.md
Last active May 28, 2025 14:55
Mithril tab pill component

TabPills

Create a tab-like experience using 'pills', based on this CodePen.

Example of tab pills in action

m(TabPills, {
  tabs: [
 {
@erikvullings
erikvullings / README.md
Last active May 5, 2025 09:47
Docker swarm setup on Windows using WSL2

WSL2 Docker Swarm Setup Scripts

This repository contains PowerShell scripts to help configure and run a multi-node Docker Swarm cluster using WSL2 on Windows 11, without relying on Docker Desktop. If you need GPU access in your swarm, please read Tom Lankhort's gist.

These scripts automate:

  • Port forwarding using netsh (TCP and UDP)
  • Generation of config.toml for wsl2proxy
  • Service installation and startup of wsl2proxy
  • Docker Swarm initialization (manager)
@erikvullings
erikvullings / docker-compose.yml
Created May 4, 2025 19:03
Traefik running in docker swarm
services:
traefik: # Your Traefik service name as defined in your compose file
image: traefik:v3.3.6 # Use the specific version
command:
# Enable the API and Dashboard without TLS
- --api.insecure=true
# Listen on the 'web' entrypoint (HTTP) on the new internal port 8091
- --entrypoints.web.address=:8091
# Listen on the 'dashboard' entrypoint on the new internal port 8092
- --entrypoints.dashboard.address=:8092
@erikvullings
erikvullings / README.md
Created December 14, 2024 10:18
Highlight text in a data object

Highlighter

TypeScript highlighter that takes a data object, and applies a highlighting function to selected property values.

I needed to render a data object representing an article. Before rendering it to HTML, I wanted to mark certain parts of the text with a background color.

  1. Create string or regex-based highlighters descriptions
  2. Create a factory function that takes these highlighters and converts them to functions that will wrap matching text with an HTML mark element and background color. It returns a highlighter.
  3. Use the highlighter to convert the original data object to a data object with the same shape, but where matching text is highlighted.
@erikvullings
erikvullings / app.ts
Created November 3, 2024 11:56
Plugin for mithril-ui-form of the SearchSelect component
import { registerPlugin } from 'mithril-ui-form';
import { searchSelectPlugin } from './search-select-plugin';
// Register plugin under the name `search_select` or any other name of your choosing.
registerPlugin('search_select', searchSelectPlugin);