Skip to content

Instantly share code, notes, and snippets.

Avatar

Craig P Hicks craigphicks

View GitHub Profile
View foo-completion.sh
#!/bin/bash
# copyright craigphicks 2020 - free to use with due attribution
confirm_args(){
logger -t "confirm_args" -- "#=${#}"
for index in `seq 0 ${#}` ; do
eval item=\$$index
logger -t "confirm_args" -- "[$index] ${item}"
done
}
@craigphicks
craigphicks / chromium-bug-report-X11-wrong-auth.md
Last active Jul 8, 2020
chromium bug report: "X11 connection rejected because of wrong authentication."
View chromium-bug-report-X11-wrong-auth.md

Chrome Version : Chromium 83.0.4103.116 snap Other browsers tested: Add OK or FAIL, along with the version, after other browsers where you have tested this issue:

Firefox: OK, "Mozilla Firefox 78.0.1" Chromium (non-span): OK, "Chromium 83.0.4103.61 Built on Ubuntu , running on Ubuntu 18.04"

What steps will reproduce the problem?

View openssh-descrption-of-X11-forwarding.md

https://www.openssh.com/features.html

X11 forwarding (which also encrypts X Window System traffic)

X11 forwarding allows the encryption of remote X windows traffic, so that nobody can snoop on your remote xterms or insert malicious commands. The program automatically sets DISPLAY on the server machine, and forwards any X11 connections over the secure channel. Fake Xauthority information is automatically generated and forwarded to the remote machine; the local client automatically examines incoming X11 connections and replaces the fake authorization

View js readStreamToEnd
async function readStreamToEnd(rstream){
rstream.resume();
let prom=new Promise((resolve,reject)=>{
var buf = Buffer('');
rstream.on('data', function(newbuf) { buf=Buffer.concat([buf,newbuf]); });
rstream.on('end', function() { resolve(buf.toString()); });
rstream.on('error', function(e) { reject(e); });
});
return await prom;
}
@craigphicks
craigphicks / iptree.py
Last active Apr 7, 2020
Convert `iptables -S` output to a depth-first tree listing
View iptree.py
#!/usr/bin/env python3
'''
Convert `iptables -S` output to a depth-first tree listing
Reads from standard input
Craig P Hicks 2019
MIT License
'''
import sys
@craigphicks
craigphicks / dtdotool.sh
Last active Mar 25, 2020
Used in Ubuntu 18.04 to manipulate desktops as atomic elements of an array, e.g., swapping element order, inserting and deleting empty elements.
View dtdotool.sh
#!/bin/bash
# Copyright (c) 2019, Craig P Hicks
# content licensed as CC BY-NC-SA
# CC BY-NC-SA details at https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
# This program depends upon 'xdotool' installed as Ubuntu 18.04 managed package
# xdotool project source can be found at:
# https://github.com/jordansissel/xdotool
# https://www.semicomplete.com/projects/xdotool/
@craigphicks
craigphicks / make-cert.sh
Last active Oct 26, 2019
self managed private CA and certs - no config files, two levels only, no intermediate, no revocation list, file names are CN - ideal for personal IoT
View make-cert.sh
#!/bin/bash
# craigphicks 2019
set -u
function CreateCertificateAuthority {
if [[ $# -ne 2 ]] ; then
echo "two args only: CA common name, CA org name"
exit 1
fi
CA_CN=${1}
@craigphicks
craigphicks / makeNonCryptoRandomAlphaNumString.js
Created Sep 14, 2019
A non-crypto js function for creating random alphanum strings - no dependencies
View makeNonCryptoRandomAlphaNumString.js
function makeNonCryptoRandomAlphaNumString(length) {
function tf(n) {
if (n < 26) return 65 + n
else if (n < 52) return 97 + n - 26
else return 48 + n - 52
}
var result = ''
for (var i = 0; i < length; i++) {
let idx = Math.floor(Math.random() * 62)
result += String.fromCharCode(tf(idx))
@craigphicks
craigphicks / README.md
Last active Aug 16, 2019
Create a non-singleton class from a singleton - yargs
View README.md

A singleton makes sense when it prevent multiple access to a resource than must not be accessed in that way. But sometimes a singleton design is used because it is sufficient for expected usage. But that may block expanded usage unecessarily.

ES6 dynamic import can import a singelton module into a closure allowing a singleton to become a non-singleton class. See the file yargs-class.mjs below.

The result of test-yargs0class.mjs -

argv[0]= {
@craigphicks
craigphicks / extending-error.js
Last active Aug 12, 2019
How to extend error when prepending a message to an existing error which may or may not be instance of Error
View extending-error.js
function showDeep(t){
let o=t
do {
console.log(`--- ${o.constructor.name}`)
for (let k of Reflect.ownKeys(o)) {
let d = Reflect.getOwnPropertyDescriptor(o,k)
if (JSON.stringify(d.value)!==undefined) {
console.log(`${k} : ${JSON.stringify(d.value)}`)
if (k==='stack')
console.log("") // funky
You can’t perform that action at this time.