Skip to content

Instantly share code, notes, and snippets.

View drkibitz's full-sized avatar
🎩
deducing

Dr. Kibitz drkibitz

🎩
deducing
View GitHub Profile
@drkibitz
drkibitz / parallel.bash
Last active September 11, 2023 03:29
parallel.bash
#!/usr/bin/env bash
## parallel.bash
## -------------
## A bash script that executes provided tasks in parallel, with added handling
## for errors, logs, and signals (within reason).
## ```sh
## ./parallel.bash -m 2 \
## 'echo 'sleeping1'; sleep 5' \
## 'echo 'sleeping3'; sleep 2' \
## 'echo 'sleeping3'; sleep 3' \
@drkibitz
drkibitz / delete-all-remote-git-tags-in-pages.sh
Last active June 6, 2023 03:32
Delete all remote Git tags in pages
#!/usr/bin/env bash
## Count local
totalCount=$(git tag -l | wc -l)
pageCount=150
index=0
while [ $index -le $totalCount ]; do
## Reverse order with `sort -r`
list=$(git tag -l | sort | head -n $pageCount)
@drkibitz
drkibitz / childprocess-lifecycle-manager.ts
Last active June 6, 2023 03:16
Type safe ChildProcess Manager (With command flow, i.e. micro redux)
import type { ChildProcess, ChildProcessByStdio } from 'node:child_process';
import type { Readable, Writable } from 'node:stream';
import stripAnsi from 'npm:strip-ansi';
export enum Phase {
Stopped = 'stopped',
Stopping = 'stopping',
Starting = 'starting',
Started = 'started',
}
##
## Source in Xcode Run Script Phase
##
set -e
CARTHAGE=$(command -v carthage)
##
## Validate
@drkibitz
drkibitz / montyhall.js
Last active June 6, 2023 01:42
Monty Hall Problem
/**
* The Monty Hall Problem
* https://en.wikipedia.org/wiki/Monty_Hall_problem
*/
// convert 0.333 to 33%
const toPercentInteger = (fraction) => {
return Math.floor(fraction * 100);
};
@drkibitz
drkibitz / priority-signals.js
Last active June 6, 2023 03:30
Signal implementation with listener priorities
/**
* This object represents a single listener of a Singal.
* A listener is simply an object with a reference to a function and thisArg,
* with a priority for insertion sorting and a once flag.
* @class
*/
class Listener {
/**
* @param {Function} fn - The listener function
* @param {Function} [thisArg] - The listener thisArg
#!/bin/sh
#
# chkconfig: 35 99 99
# description: Node.js /home/nodejs/sample/app.js
#
. /etc/rc.d/init.d/functions
USER="nodejs"
@drkibitz
drkibitz / otool-ls-r
Created February 9, 2014 08:11
Recursively list paths of shared libraries required by given binary. Usage: `otool-ls-r /bin/bash`
#!/bin/bash
list=""
otool_list() {
local lib="$1"
local libs=""
if [[ "$list" == "${list/:$lib/}" ]]; then
echo "$lib"
list="$list:$lib"
@drkibitz
drkibitz / build-openfl-samples.sh
Created January 23, 2014 05:39
Bash script to build all openfl-samples
## Needed for CI environment
export NEKOPATH=""
export HAXEPATH=""
export HAXE_STD_PATH=""
DIST="/path/to/dist"
rm -fR $DIST
SAMPLES=$(lime create openfl | sed -nr 's/ - (.+)/\1/p')
for sample in $SAMPLES
@drkibitz
drkibitz / grunt-shell.js
Last active December 24, 2015 02:39
Run shell command as grunt task, like `grunt $:/etc:ls:-laG`, or `grunt $::npm:pack`. Use it with `grunt.task.run('$:blah');`. $:opt_chdir_value:cmd_name:arg1:arg2
module.exports = function(grunt) {
'use strict';
var path = require('path');
var spawn = require('child_process').spawn;
grunt.registerTask('$', 'Run command in the form $::cmd:arg1:arg2, or $:/blah:cmd:arg.', function() {
var done = this.async();
var args = Array.prototype.slice.call(arguments);
var cwd = process.cwd();