Skip to content

Instantly share code, notes, and snippets.

View scolton99's full-sized avatar
🐢

Spencer Colton scolton99

🐢
  • Northwestern University
  • Chicago, IL
View GitHub Profile
@scolton99
scolton99 / gen.fish
Created April 8, 2025 01:39
Certificate Generators
#!/usr/bin/env fish
if test -f ".req.conf"
rm .req.conf
end
set STRBASE "[req]
distinguished_name = dn
x509_extensions = v3_req
prompt = no
@scolton99
scolton99 / test.ps1
Created April 26, 2024 12:35
Test Transient Error Handling in PowerShell
function Get-RandomSuccess {
$val = Get-Random -Maximum 2
$val -eq 0
}
function Get-RandomThrow {
if (!(Get-RandomSuccess)) {
throw "ERR"
}
@scolton99
scolton99 / SWCommon.psm1
Created August 30, 2023 18:36
SolarWinds Rainmeter Widget
class SwisConnection {
[String] $HostName
[Bool] $UseSSL
[Bool] $ValidateSSL
[Int] $Port
[PSCredential] $Credential
SwisConnection(
[String] $HostName,
[Bool] $UseSSL,
@scolton99
scolton99 / cube.js
Created December 4, 2022 14:44
Thing to test random permutations of numbers representing Rubik's Cube arrangements to probabilistically verify possible orientations.
const { Worker, isMainThread, parentPort, workerData } = require('node:worker_threads');
const randIdx = vals => Math.floor(Math.random() * vals.length);
const permute4 = vals => {
const vCopy = [...vals];
if (vCopy.length !== 4)
throw new Error('Array must be of size 4');
@scolton99
scolton99 / archive.js
Created November 18, 2022 19:45
Twitter archive thing NodeJS
const fetch = require("node-fetch");
const { readFileSync, writeFileSync } = require('fs');
const getAccess = async () => {
const refresh_token = readFileSync('last_refresh', { encoding: 'utf-8' });
const data = new URLSearchParams();
data.append('refresh_token', refresh_token);
data.append('grant_type', 'refresh_token');
$TTL 60
$ORIGIN local.example.com.
@ IN SOA examplecom.ddns.net. admin.example.com. {{SERIAL}} 300 900 604800 60
@ IN NS examplecom.ddns.net.
@ IN A {{EXT_IP}}
* IN CNAME examplecom.ddns.net.
@scolton99
scolton99 / generateHeadings.js
Created October 11, 2022 17:27
Create headings for the "What did you work on today?" Confluence documents.
const generateHeadings = () => {
let date = new Date('2023-08-31T00:00:00');
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
for (; date.getTime() >= Date.parse('2023-06-01T00:00:00'); date.setDate(date.getDate() - 1)) {
if (date.getDay() === 0 || date.getDay() === 6)
continue;
@scolton99
scolton99 / DynamicModel.php
Created July 1, 2022 02:46
My shitty attempt at making an ActiveRecord equivalent for PHP.
<?php
abstract class DynamicModel {
/** @var DBEngine */
protected static $db;
protected $id;
protected $values;
private static $consonants = "bcdfghjklmnpqrstvwxz";
private static $vowels = "aeiou";
@scolton99
scolton99 / certificateGenerator.sh
Created June 16, 2022 14:08
Use OpenSSL to generate a self-signed certificate with SANs.
if [ -f ".req.conf" ]; then
rm .req.conf
fi
STRBASE="[req]\ndistinguished_name = dn\nx509_extensions = v3_req\nprompt = no\n\n[dn]\nC = US\nST = Illinois\nL = Chicago\nO = Northwestern University\nOU = Information Technology\nCN = $1\n\n[v3_req]\nkeyUsage = keyEncipherment, nonRepudiation, digitalSignature, dataEncipherment, keyAgreement, keyCertSign\nextendedKeyUsage = serverAuth\nbasicConstraints = CA:true\nsubjectKeyIdentifier = hash\nauthorityKeyIdentifier = keyid:always,issuer:always\nsubjectAltName = @alt_names\n\n[alt_names]"
C=1
for var in "$@"
do
STRBASE="${STRBASE}\nDNS.${C} = ${var}"
@scolton99
scolton99 / countBits.js
Created May 10, 2022 01:52
Counting bits in a 32-bit number.
const countBits = num => {
let bits = 0;
for (let i = 0; i < 32; ++i)
bits += !!(num & (1 << i)) ? 1 : 0;
return bits;
};