Skip to content

Instantly share code, notes, and snippets.

@AMathMonkey
AMathMonkey / Profile.ps1
Created June 16, 2024 21:33
Get-AdventOfCodeInput: A PowerShell function to get the text string of your input for a given year, day, and session cookie value
function Get-AdventOfCodeInput {
param(
[Parameter(Mandatory)][string]$Year,
[Parameter(Mandatory)][string]$Day,
[Parameter(Mandatory)][string]$Session
)
$S = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$S.Cookies.Add([System.Net.Cookie]::new('session', $Session, '', 'adventofcode.com'))
$Result = (Invoke-WebRequest https://adventofcode.com/$Year/day/$Day/input -WebSession $S)
$Result.Content
# By AMathMonkey, 2022
# Depends on Tcl, Tk, Img, and ImageMagick!
# Something really rough that I'm working on to practice GUI development.
# A utility to look through a directory of images using the left and right arrow keys
# then save any desired images to an output directory by pressing the space bar.
# Takes 3 arguments - input directory, output directory, and optional index of image in input directory to open to (default is 0)
# The title bar says the name of the current file and if it's saved to the output directory or not.
@AMathMonkey
AMathMonkey / artist_hyphen_title.pl
Last active June 4, 2022 19:48
This is some boilerplate Perl code that I have been modifying and using to fix tags on my mp3s. Read the full description at the top of the file.
=pod
This is some boilerplate Perl code that I have been modifying and using to fix tags on my mp3s.
In its current state, this code will take tracks that are titled like "[actual artist] - [title]"
with the Artist field being Various Artists, and fix their Title and Artist fields, and set the
Album Artist field to Various Artists. MP3::Tag doesn't support the Album Artist field by default,
which is strange, so this file also adds this functionality to the library.
=cut
use strict;
use warnings;
@AMathMonkey
AMathMonkey / bar_time_calc_rust.rs
Last active September 18, 2021 17:43
I wrote the dumb BAR time calculator again (after so long), in an attempt to see if Rust is less ugly than I thought, and you know, it's not that bad. Just a little bit bad.
use text_io::read;
use regex::Regex;
use std::{io::{self, Write}, {fs::OpenOptions}, fmt};
const TRACKS: [&str; 6] = ["Coventry Cove", "Mount Mayhem", "Inferno Isle", "Sunset Sands", "Metro Madness", "Wicked Woods"];
const GREETING: &str = "BAR! Bonus Circuit IGT Calculator by AMathMonkey\n\
Input times in the format MSShh where M is minutes, SS is seconds and hh is hundredths\n\
Enter 'u' or 'undo' to undo\n";
struct Time {
@AMathMonkey
AMathMonkey / message_splitter.pl
Last active June 4, 2022 19:34
Perl utility (should work on Windows and Linux) to split a long Discord message into pieces under the 2000-char limit. Like my old Python version except it only uses stdin and stdout. Provide the input via stdin (or as a filename argument because "while(<>)" accepts that too), and redirect the output to a new file yourself.
#!/usr/bin/perl
use v5.28.1;
use strict;
use warnings;
use open qw/:std :utf8/;
eval {require Win32::Console; Win32::Console::OutputCP(65001)};
my $CHAR_LIMIT = 2000;
my $MESSAGE_DELIMITER = "-----------------\n\n";
@AMathMonkey
AMathMonkey / puzzlecalc.awk
Created January 1, 2021 22:20
AWK script to estimate the dimensions of a jigsaw puzzle in pieces, given the number of pieces and the measured dimensions of the puzzle, assuming square pieces
{
pieces = $1
height_in_units = $2
width_in_units = $3
area = height_in_units * width_in_units
piece_area = area / pieces
piece_side_length = sqrt(piece_area)
@AMathMonkey
AMathMonkey / bartimecalc.awk
Last active December 31, 2020 07:42
Experimental no-frills attempt to port the BAR time calculator to AWK, requires an input file with 6 IGT times in MMSShh format separated by newlines. Update: added display of formatted individual track times before the result
BEGIN {
tracks[1] = "Coventry Cove"
tracks[2] = "Mount Mayhem"
tracks[3] = "Inferno Isle"
tracks[4] = "Sunset Sands"
tracks[5] = "Metro Madness"
tracks[6] = "Wicked Woods"
print "BAR! Bonus Circuit IGT Calculator by AMathMonkey\n"
}
@AMathMonkey
AMathMonkey / message_splitter.py
Last active February 7, 2021 01:09
Will split a long message into multiple mini messages under Discord's per-message character limit, for you to paste and send one-by-one
#!/usr/bin/python3
from os import path, getcwd
import sys
CWD = getcwd()
CHAR_LIMIT = 2000 # Discord char limit per message
OUTPUT_FILE_NAME = "split-output.txt"
MESSAGE_DELIMITER = "-----------------\n\n"
filepath = "message.txt" # Default argument
@AMathMonkey
AMathMonkey / AnagramSolver.nim
Created December 21, 2020 05:35
Nim translation of AnagramSolver.d
import os
import sets
import algorithm
import unicode
var args = commandLineParams()
assert(args.len == 1, "Provide exactly one jumbled word to unscramble.")
var
jumble: string = args[0].toUpper()
@AMathMonkey
AMathMonkey / AnagramSolver.d
Last active February 11, 2021 06:31
Single-word jumble solver, requires a file named DICTIONARY.TXT with all possible solution words on separate lines to be in the same directory
import std.stdio : writefln, File;
import std.exception : enforce;
import std.algorithm : map;
import std.algorithm.iteration : permutations;
import std.utf : byChar;
import std.conv : to;
import std.uni : toUpper;
void main(string[] args)
{