Skip to content

Instantly share code, notes, and snippets.

View T99's full-sized avatar
:shipit:
programmin'

Trevor Sears T99

:shipit:
programmin'
View GitHub Profile
@T99
T99 / collapse-whitespace.ts
Last active February 2, 2023 17:02
A TypeScript function that returns a modified version of the input string, having collapsed all horizontal whitespace down to single space characters.
/**
* Returns a modified version of the input string, having collapsed all
* horizontal whitespace down to single space characters.
*
* @param input {string} The string that should be modified to have it's
* whitespaces collapsed.
* @returns {string} A modified version of the input string, having collapsed
* all horizontal whitespace down to single space characters.
*/
export function collapseWhitespace(input: string): string {
@T99
T99 / group-array.php
Created December 12, 2022 20:18
Group a given input array using a configurable set of fields.
<?php
/**
* Given a 2-dimensional array, this function returns a mapped 2-dimensional
* array wherein the rows of the input array have been 'grouped'.
*
* 'Grouping' involves merging similar rows of the input array. Rows are
* considered 'similar' if some subset of their fields are found to be
* equivalent to each other. This subset of fields is identified using the
* '$group_by' argument. 'Merging' involves the creation of an array of the
@T99
T99 / to-ascii-table.php
Last active December 12, 2022 17:01
Generate an ASCII/text-based table string in PHP from a given input set of data.
<?php
/**
* Returns true if the input array appears to be an associative array, otherwise
* returning false.
*
* @param array $input The array being tested.
* @return bool true if the input array appears to be an associative array,
* otherwise returning false.
*/
@T99
T99 / casing-conversion.php
Last active November 21, 2022 17:21
A PHP helper script for converting between different casing conventions.
<?php
/**
* Returns an array of words extracted from the input string.
*
* @param string $text The input string from which to extract words.
* @return string[] An array of words extracted from the input string.
*/
function convertToWords(string $text): array {
@T99
T99 / preserve_history.ps1
Last active August 25, 2022 16:18
Preserve/save PowerShell command history globally, across sessions.
# The full path at which to save the history file.
$history_file = "~\PowerShell\history.csv"
# The amount of history to save.
$history_size = 32KB
# Create the ~\PowerShell directory if is does not already exist.
if (!(Test-Path ~\PowerShell -PathType Container)) {
New-Item ~\PowerShell -ItemType Directory
}
@T99
T99 / powershell_prompt.ps1
Created August 23, 2022 13:35
A simple custom PowerShell prompt.
function prompt {
$date = Get-Date -Format "M/d @ h:mm tt"
$cwp = Get-Location
$drive_letter = Split-Path -Path $cwp -Qualifier
$cwd = Split-Path -Path $cwp -Leaf
$location = $drive_letter + "\..\" + $cwd
if ($cwd -eq $cwp) {
@T99
T99 / check-file.ts
Last active July 18, 2022 19:43
A more accessible API wrapper over Node's builtin `fs.stat`.
/*
* Created by Trevor Sears <trevor@trevorsears.com> (https://trevorsears.com/).
* 2:49 PM -- July 18th, 2022
*/
import fs from "fs";
import process from "node:process";
export type CheckFileOptions = {
isFile?: boolean,
@T99
T99 / generic-table.sql
Last active September 21, 2022 20:16
DDL for a very basic SQL table.
CREATE TABLE ExampleTable (
`id` INT UNSIGNED NOT NULL
AUTO_INCREMENT
PRIMARY KEY
COMMENT 'An unsigned integer value that uniquely identifies this row among those in this table.',
`uuid` CHAR(36) NOT NULL
DEFAULT UUID()
COMMENT 'A UUID (''universally unique identifier'') that can uniquely identify this row in any context.',
`modifiedAt` DATETIME NOT NULL
DEFAULT CURRENT_TIMESTAMP
@T99
T99 / create-ssh-key
Last active March 21, 2022 13:35
Create an SSH key
#!/bin/bash
ssh-keygen -f "$HOME/.ssh/ids/$1-to-$2" -t "rsa-sha2-512" -C "Keyfile for: $3"
@T99
T99 / xlsb2csv.py
Last active January 21, 2022 21:36
Convert XLSB files to CSVs, optionally specifying a sheet
#!/usr/bin/env python
import os
import sys
from pyxlsb import open_workbook
def to_string(s):
if s is None:
return ''
if isinstance(s, (str)):