Skip to content

Instantly share code, notes, and snippets.

View shadowmoose's full-sized avatar

Mike J shadowmoose

View GitHub Profile
@shadowmoose
shadowmoose / README.md
Last active February 14, 2024 04:10
Simple, bad, pure-js HTML tree wrapper

This is my rapid prototyping JS "library" for building basic UI.

It is absolutely not viable for a production product. This is - at best - a minimalist tool for exposing UI in contexts where libraries or line count matter.

Personally, I use this in situations where content must be injected from outside into the DOM, as the single entrypoint function makes this entire library trivial to encode. This situation is most commonly encountered in Browser plugins or Userscripts.

There are zero external dependencies, and the entire library is under 100 LoC.

@shadowmoose
shadowmoose / encrypted-streams.ts
Last active September 9, 2024 15:05
TypeScript: Encrypt and decrypt files as streams, appending to and resuming from arbitrary locations, efficiently.
import crypto from 'crypto';
import fs, {createReadStream, createWriteStream} from 'fs';
import * as stream from "stream";
import {pipeline} from "stream/promises";
/*
File encryption toolkit, for streaming read/write and appending.
Designed primarily for use in writing/reading file ranges, as they may be requested via HTTP -
though this works for any use case where encrypted file writing/reading may be desired.
The output resulting files are always compatible with standard aes-256-cbc decryption,
@shadowmoose
shadowmoose / pre-commit
Last active February 22, 2024 14:25
Git pre-commit hook to make sure you incremented your program's internal version variable.
#!/usr/bin/env bash
# Checks the latest release version of your GitHub project, and makes sure the local version variable has been incremented.
# This script will run before any commits happen, and interrupt if the local version has not been incremented since the last release.
# It's intended for use with projects who primarily increment versions around their release schedule.
#
# Requires that GitHub releases use tags that match the internal version. Supports oAuth info in the event of GitHub rate limiting.
# The parsing done in here is super hacky, but it's fast and it works cross-platform with minimal requirements.
# Works with any version tag format you use, and should be runnable on Windows/Linux.
#
# TO USE:
@shadowmoose
shadowmoose / Gource.ps1
Last active March 13, 2021 05:58
Gource git history into MP4 format - Windows Powershell
# When run (in PowerShell), this script prompts for a directory containing a git project.
# It then jumps into that directory and uses Gource + FFmpeg to generate an mp4 animation of the history of the current branch.
# Additionally, it has support for embedding background music files. Click "Cancel" on the prompt to not add audio.
# If the video is shorter than the selected audio, the audio will fade out. If longer, the video will be sped up to fit the audio.
#
# Note: If the complementary script "handle_avatars.ps1" is present, this script will use it to download user avatars from GitHub.
# This may hit rate limiting, so ClientID and ClientSecret oAuth params are accepted, which will bypass GitHub's limits.
# You can cut down on the required queries by properly using a ".mailmap" file to combine user's emails.
# Pass "SkipGithubAvatars" to ignore this entirely, if your project is not hosted on GitHub.
#
@shadowmoose
shadowmoose / RWLock.py
Last active April 27, 2018 05:44
Read/Write Lock implementation, modified to support context managers
import threading
'''
This is a lock that enables locking for specifically "reading" or "writing".
Multiple readers can obtain a "read" lock at the same time, but only one "write" lock can exist.
Furthermore, no readers can open a lock while the "write" lock is open.
It attempts to give locking priority to writers.
I've slightly modified it to support an __enter__ and __exit__ method, for convenience.
@shadowmoose
shadowmoose / Audio-Merge.md
Last active December 7, 2022 20:30
Merge multiple audio tracks inside a video file

About

This is a simple script to combine two of a video file's audio tracks into one. It doesn't impact the video's quality.

To make things even more simple, it only prompts for an input/output video using file selectors. The rest is handled automatically.

This is a simple utility to rapidly "fix" videos with split audio tracks, such as those recorded by ShadowPlay or OBS.

To use this script, simply copy/paste the "merge.ps1" code below into a new file named "merge.ps1", then launch it.