Skip to content

Instantly share code, notes, and snippets.

Avatar
🎩
deducing

Dr. Kibitz drkibitz

🎩
deducing
View GitHub Profile
@drkibitz
drkibitz / childProcessManager.ts
Last active Apr 11, 2020
Type safe ChildProcess Manager (With command flow, i.e. micro redux)
View childProcessManager.ts
import type { ChildProcess, ChildProcessByStdio } from 'child_process';
import type { Readable, Writable } from 'stream';
import stripAnsi from 'strip-ansi';
export enum Status {
Stopped = 'stopped',
Stopping = 'stopping',
Starting = 'starting',
Started = 'started',
}
View Carthage-Dependencies.sh
##
## Source in Xcode Run Script Phase
##
set -e
CARTHAGE=$(command -v carthage)
##
## Validate
@drkibitz
drkibitz / montyhall.js
Last active Sep 28, 2018
Monty Hall Problem
View montyhall.js
/**
* 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
Created Mar 18, 2017
Signal implementation with listener priorities
View priority-signals.js
/**
* 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
View nodejs
#!/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 Feb 9, 2014
Recursively list paths of shared libraries required by given binary. Usage: `otool-ls-r /bin/bash`
View otool-ls-r
#!/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 Jan 23, 2014
Bash script to build all openfl-samples
View build-openfl-samples.sh
## 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 Dec 24, 2015
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
View grunt-shell.js
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();
View LinkedList.js
//I wanted a more elegant linkedlist example than the others, so purely for academic purposes I created one.
var LinkedList = function(e){
var that = {}, first, last;
that.push = function(value){
var node = new Node(value);
if(first == null){
first = last = node;
@drkibitz
drkibitz / gist:6143035
Last active Apr 23, 2020
pixi.js IntactionManager Example Usage 2
View gist:6143035
// create an new instance of a pixi stage
var stage = new PIXI.Stage(0x66FF99);
// create a renderer instance
var renderer = PIXI.autoDetectRenderer(400, 300);
// create a manager instance, passing stage and renderer.view
var manager = new PIXI.InteractionManager(stage, renderer.view);
stage
.on('click', function (event) {
console.log(event.type, event.target); // 'click', PIXI.DisplayObject {}