Skip to content

Instantly share code, notes, and snippets.

Starbeamrainbowlabs sbrl

Block or report user

Report or block sbrl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sbrl
sbrl / ErrorWrapper.mjs
Last active Feb 13, 2020
[ErrorWrapper.mjs] Error wrapper class - wrap errors like C♯! #error-handling
View ErrorWrapper.mjs
class ErrorWrapper extends Error {
constructor(message, inner_exception) {
super(message);
this.inner_exception = inner_exception;
}
toString() {
return `${super.toString()}\n***Inner Exception ***\n${this.inner_exception}`;
}
}
@sbrl
sbrl / Retry.mjs
Created Feb 13, 2020
[Retry.mjs] Retry a function automatically a specified number of times #utility
View Retry.mjs
"use strict";
import l from './Log.mjs';
import { ErrorWrapper } from './Errors.mjs';
/**
* Tries to execute a given function, and retried it a specified number of
* times if it throws an error.
* @param {Number} times The number of times to retry before giving up and throwing an error ourselves.
* @param {Function} func The function to execute.
@sbrl
sbrl / CliParser.mjs
Created Jan 12, 2020
[CliParser.mjs] Minimal CLI parser for Node.js - uses Ansi.mjs #library
View CliParser.mjs
"use strict";
import fs from 'fs';
import a from './Ansi.mjs';
/**
* Represents a program and all it's arguments and subcommands.
* @license MPL-2.0
*/
@sbrl
sbrl / Stopwatch.mjs
Created Dec 22, 2019
[Stopwatch.mjs] C#'s System.Diagnostics.Stopwatch (roughly) implemented in C#.
View Stopwatch.mjs
"use strict";
/**
* Stopwatch class for timing things.
* Based on System.Diagnostics.Stopwatch from .NET: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch
*/
class Stopwatch {
/**
* Creates a new (stopped) stopwatch.
*/
@sbrl
sbrl / Log.mjs
Last active Jan 12, 2020
[Log.mjs] Logging utility class
View Log.mjs
"use strict";
import a from './Ansi.mjs';
const LOG_LEVELS = {
DEBUG: 0,
INFO: 1,
LOG: 2,
WARN: 4,
ERROR: 8,
@sbrl
sbrl / errorimage.php
Created Oct 22, 2019
[errorimage.php] Generate error images on the fly in portable PHP
View errorimage.php
/**
* Creates an images containing the specified text.
* Useful for sending errors back to the client.
* @package core
* @param string $text The text to include in the image.
* @param int $target_size The target width to aim for when creating
* the image. Not not specified, a value is
* determined automatically.
* @return resource The handle to the generated GD image.
*/
@sbrl
sbrl / JsonStorageBox.php
Last active Sep 21, 2019
[JsonStorageBox.php]
View JsonStorageBox.php
<?php
/*
███████ ████████ ██████ ██████ █████ ██████ ███████ ██████ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██ ██ ██████ ███████ ██ ███ █████ ██████ ██ ██ ███
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██████ ██ ██ ██ ██ ██████ ███████ ██████ ██████ ██ ██
*/
@sbrl
sbrl / StorageBox.php
Last active Sep 21, 2019
[StorageBox.php] A key-value data store, backed by SQLite3.
View StorageBox.php
<?php
/*
███████ ████████ ██████ ██████ █████ ██████ ███████ ██████ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██ ██ ██████ ███████ ██ ███ █████ ██████ ██ ██ ███
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██████ ██ ██ ██ ██ ██████ ███████ ██████ ██████ ██ ██
*/
View cucumber.js
"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 Jun 10, 2019
[SVGWriter.mjs] SVGWriter.cs, ported to Javascript. Uses the xml-writer npm package.
View SvgWriter.mjs
"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.
You can’t perform that action at this time.