Skip to content

Instantly share code, notes, and snippets.

View rhom6us's full-sized avatar

Thomas Butler rhom6us

  • Butler Software
  • Atlanta, GA
View GitHub Profile
@rhom6us
rhom6us / tuple.ts
Last active July 15, 2023 19:54
pointless tuple
type Dec<Length extends number, Acc extends never[] = []> =
[never, ...Acc]['length'] extends Length ? Acc['length'] :
Dec<Length, [never, ...Acc]>;
type MakeRange<TMin extends number, TMax extends number, Acc extends number = never> =
TMax extends TMin ? TMax | Acc
: MakeRange<TMin, Dec<TMax>, TMax | Acc>;
type TupleBaseType = readonly any[] & { length: MakeRange<1,10> }
/**
* generate this code with:
* =======================
@rhom6us
rhom6us / fluent-object-builder.ts
Created June 20, 2023 06:32
Fluent Object Builder
import { Func } from "@rhombus-toolkit/func";
type AnyRecord = Record<string|symbol, any>;
type AnyFunction = (...args: any[]) => any;
type MakeBuilder<T extends AnyRecord> = T extends infer a extends AnyRecord | infer b extends AnyRecord ? ObjectBuilder<a> | ObjectBuilder<b> : ObjectBuilder<T>;
type ExtractObject<T> =
@rhom6us
rhom6us / RefreshEnv.cmd
Created June 17, 2023 21:58
refreshenv
// https://github.com/chocolatey/choco/blob/0.10.15/src/chocolatey.resources/redirects/RefreshEnv.cmd
@echo off
::
:: RefreshEnv.cmd
::
:: Batch file to read environment variables from registry and
:: set session variables to these values.
::
:: With this batch file, there should be no need to reload command
@rhom6us
rhom6us / enable-rdp.sh
Last active July 15, 2022 21:34
Configure Ubuntu to be accessible via RDP
#!/bin/bash
# chmod +x ./enable-rdp.sh
sudo apt install xrdp
sudo systemctl enable --now xrdp
sudo ufw allow from any to any port 3389 proto tcp
sudo ufw allow from any to any port 3399 proto tcp
@rhom6us
rhom6us / Complex.js
Created June 3, 2022 07:44
Complex number data structure & operators
// https://github.com/RobTillaart/Arduino/blob/master/libraries/Complex/complex.cpp
function format(real, imag){
if(this.imag == 0){
return real
}
if(real == 0){
return 'i' + imag;
}
return `${real} ${imag < 0 ? `-` : `+`} ${Math.abs(imag)}i`;
@rhom6us
rhom6us / Winlogon_Startup.hta
Created December 5, 2021 20:39
change window default shell to this
<html>
<head>
<title>IT Tasks for Users</title>
<HTA:APPLICATION
APPLICATIONNAME="IT Tasks for Users"
ID="IT Tasks for Users"
VERSION="1.0"/>
<STYLE></STYLE>
@rhom6us
rhom6us / Spectrogram-1v00.js
Last active July 2, 2022 11:21
JavaScript graphics functions to draw Spectrograms.
// http://arc.id.au/Spectrogram.html
const [Waterfall, Rasterscan] = (function () {
Waterfall = function (ipBufAry, w, h, dir, options) {
var direction = typeof dir === "string" ? dir.toLowerCase() : "down";
switch (direction) {
case "up":
return new Spectrogram(ipBufAry, w, h, "WF", false, true, options);
case "down":
@rhom6us
rhom6us / tsconfig.json
Created March 4, 2021 07:11
Typescript config for generating @types
{
"compilerOptions": {
"noImplicitAny": false,
"strictFunctionTypes": false,
"strictPropertyInitialization": false,
"strictBindCallApply": false,
"noImplicitThis": false,
"noImplicitReturns": false,
"alwaysStrict": false,
"esModuleInterop": true,
@rhom6us
rhom6us / draw-audio-buffer.js
Created February 25, 2021 22:58
Draw an audio buffer to a canvas
function drawBuffer( width, height, context, buffer ) {
var data = buffer.getChannelData( 0 );
var step = Math.ceil( data.length / width );
var amp = height / 2;
for(var i=0; i < width; i++){
var min = 1.0;
var max = -1.0;
for (var j=0; j<step; j++) {
var datum = data[(i*step)+j];
if (datum < min)
@rhom6us
rhom6us / Tuple.ino
Created January 21, 2019 03:07
Arduino-compatable Tuple implementation (not std compatable). Need to make a proper adruino lib for this.
#include <ArduinoSTL.h>
#include <iostream>
// helpers
template <typename T>
struct id { using type = T; };
template <typename T>
using type_of = typename T::type;