Skip to content

Instantly share code, notes, and snippets.

View sbrl's full-sized avatar

Starbeamrainbowlabs sbrl

View GitHub Profile
@sbrl
sbrl / StorageBox.php
Last active September 21, 2019 20:18
[StorageBox.php] A key-value data store, backed by SQLite3.
<?php
/*
███████ ████████ ██████ ██████ █████ ██████ ███████ ██████ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██ ██ ██████ ███████ ██ ███ █████ ██████ ██ ██ ███
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██████ ██ ██ ██ ██ ██████ ███████ ██████ ██████ ██ ██
*/
"use strict";
async function pipe(initial_value, ...funcs) {
let current = initial_value;
for(let func of funcs) {
current = func(current);
// If it's thenable, then it's probably a Promise
if(typeof current.then == "function")
current = await current;
}
@sbrl
sbrl / SvgWriter.mjs
Last active April 14, 2020 16:21
[SVGWriter.mjs] SVGWriter.cs, ported to Javascript. Uses the xml-writer npm package.
"use strict";
import XMLWriter from 'xml-writer';
import Rectangle from './Rectangle.mjs';
import Vector2 from './Vector2.mjs';
/*
* Simplifies the process for creating an SVG dynamically.
* Originally written for MusicBoxConverter, but lifted, reused, and extended for FloatingIslands.
@sbrl
sbrl / CLI.mjs
Last active December 16, 2019 18:47
[CLI.mjs] A CLI template for Node.js #template
#!/usr/bin/env node
// Requires Ansi.mjs, which can be found here: https://gist.github.com/8c0bb5e172438b6e62dd48587cfeba84#file-ansi-mjs
import a from './Ansi.mjs';
// 1: Setup
const settings = {
program_name: "",
version: "v0.1",
@sbrl
sbrl / Ansi.mjs
Last active April 18, 2021 03:20
[Ansi.mjs] VT100 ANSI escape sequence generator in JS. Ported from the C# version.
"use strict";
/**
* Generates various VT100 ANSI escape sequences.
* Ported from C#.
* @licence MPL-2.0 <https://www.mozilla.org/en-US/MPL/2.0/>
* @source https://gist.github.com/a4edd3204a03f4eedb79785751efb0f3#file-ansi-cs
* @author Starbeamrainbowlabs
* GitHub: @sbrl | Twitter: @SBRLabs | Reddit: u/Starbeamrainbowlabs
***** Changelog *****
@sbrl
sbrl / xsend.py
Last active January 7, 2019 19:33
[xsend.py] A cleaned-up version of http://xmpppy.sourceforge.net/examples/xsend.py. Requires the "xmpppy" package - which is installable via pip.
#!/usr/bin/env python3
# $Id: xsend.py,v 1.8 2006/10/06 12:30:42 normanr Exp $
# Edited & cleaned up by Starbeamrainbowlabs <feedback@starbeamrainbowlabs.com>
import sys
import os
import time
import xmpp
@sbrl
sbrl / NightInk.php
Last active May 22, 2023 20:06
[NightInk/PHP] A teeny-tiny templating engine. This implementation is in PHP.
<?php
namespace SBRL;
/**
* A teeny-tiny templating engine.
* @author Starbeamrainbowlabs
* @version v0.4
* @lastModified 19th December 2020
* @license https://www.mozilla.org/en-US/MPL/2.0/ Mozilla Public License 2.0
@sbrl
sbrl / plaintext-convert.sh
Created November 26, 2018 19:38
Converter for pirate/bookmark-archiver that converts a plain-text list of urls into something it can understand.
#!/bin/bash
set -o errexit
set -o nounset
##############
# This program converts a plain-text list of urls to the
# bookmark-archiver HTML format.
#
# Requirements: curl, xidel
# Usage:
@sbrl
sbrl / ParseCSV.mjs
Last active January 28, 2022 05:11
Quick CSV Parser that converts CSV files into an array of JS Objects.
"use strict";
/**
* Parses the source CSV into an array of objects.
* @param {string} source The source CSV to parse.
* @param {Boolean} [parse_numbers=true] Whether number-like values should be parsed with parseFloat()
* @returns {[object]} An array of objects. The keys are taken from the csv header.
*/
export default function ParseCSV(source, parse_numbers = true) {
/// <summary>
/// This is a dictionary guaranteed to have only one of each value and key.
/// It may be searched either by TFirst or by TSecond, giving a unique answer because it is 1 to 1.
/// It implements garbage-collector-friendly IEnumerable.
/// </summary>
/// <remarks>From https://stackoverflow.com/a/35949314/1460422</remarks>
/// <typeparam name="TFirst">The type of the "key"</typeparam>
/// <typeparam name="TSecond">The type of the "value"</typeparam>
public class BiDictionary<TFirst, TSecond> : IEnumerable<BiDictionary<TFirst, TSecond>.Pair>
{