Skip to content

Instantly share code, notes, and snippets.

@Dibasic
Dibasic / colortest.sh
Created February 24, 2022 17:58
colortest - print terminal foreground/background color combinations in a 16x16 (80 chars x 16 lines) grid
colortest() {
echo "$(tput setaf 1)1 $(tput setaf 2)2 $(tput setaf 3)3 $(tput setaf 4)4 $(tput setaf 5)5 $(tput setaf 6)6 $(tput setaf 7)7 $(tput setaf 8)8 $(tput setaf 9)9 $(tput setaf 10)10 $(tput setaf 11)11 $(tput setaf 12)12 $(tput setaf 13)13 $(tput setaf 14)14 $(tput setaf 15)15 $(tput setaf 16)16 $(tput sgr0)"
local FCR=$(tput setaf 1)
local FCG=$(tput setaf 2)
local FCY=$(tput setaf 3)
local FCB=$(tput setaf 4)
local FCM=$(tput setaf 5)
local FCC=$(tput setaf 6)
local FCW=$(tput setaf 7)
local FCK=$(tput setaf 8)
@Dibasic
Dibasic / prototype_array.js
Created October 12, 2021 16:43
array prototype functions that i use
Array.prototype.unique = function() { return this.filter(function(val, idx) { return this.indexOf(val) === idx; }, this); };
Array.prototype.union = function(that) { return this.concat(that).unique(); };
Array.prototype.intersection = function(that) { return this.filter(function(val) { return that.indexOf(val) !== -1; }).unique(); };
Array.prototype.difference = function(that) { return this.filter(function(val) { return that.indexOf(val) === -1; }).unique(); };
@Dibasic
Dibasic / waitUntil.js
Created August 28, 2019 15:05
Wait until a condition becomes true to execute something
function waitUntil(condition, delay, maxAttempts, onSuccess, onFail) {
console.debug(`- - - waitUntil to run ${onSuccess.name} - trying ${condition.name} up to ${maxAttempts} times over up to ${delay * maxAttempts}ms`);
let attempts = 0;
function attempt() {
setTimeout(function() {
attempts++;
console.debug(`- - - - Attempting ${condition.name} to run ${onSuccess.name} (attempt ${attempts} of ${maxAttempts})...`);
if (condition()) {
let result = onSuccess();
console.debug(`- - - - - Success: ${onSuccess.name} returned ${result} after ${attempts * delay}ms`);
Stalking my profile is a valid solution.
bA7q50lYryz3IE0i