Skip to content

Instantly share code, notes, and snippets.

View leodr's full-sized avatar

Leo Driesch leodr

View GitHub Profile
@leodr
leodr / useMoneyInput.ts
Created March 9, 2021 15:57
A React hook for creating mobile-friendly, auto-formatted money inputs.
import { KeyboardEvent, useState } from 'react';
interface MoneyInputReturn {
cents: number;
setCents: (newCents: number) => void;
stringValue: string;
handleKeyUp: (event: KeyboardEvent<HTMLInputElement>) => void;
}
/**
@leodr
leodr / index.js
Created June 21, 2021 08:32
Print an ASCII-Art-cube for a given height
function printCube(height) {
const width = height * 2;
const depth = Math.ceil(height / 2);
const canvas = [];
const canvasWidth = width + 2 + depth + 1;
const canvasHeight = height + 2 + depth + 1;
for (let i = 0; i < canvasHeight; i++) {
canvas[i] = Array(canvasWidth).fill(" ");
@leodr
leodr / change-mac-address.js
Created November 4, 2021 23:57
Changes the networking MAC address on macOS.
const { exec } = require("child_process");
let macAddress;
do {
macAddress = "XX:XX:XX:XX:XX:XX".replace(/X/g, () =>
"0123456789abcdef".charAt(Math.floor(Math.random() * 16))
);
} while (parseInt(macAddress[1], 16) % 2 !== 0);