Skip to content

Instantly share code, notes, and snippets.

Craig P Hicks craigphicks

Block or report user

Report or block craigphicks

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
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 /
Last active Aug 16, 2019
Create a non-singleton class from a singleton - yargs

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 / 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(`--- ${}`)
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
craigphicks /
Created Jul 10, 2019
testing javascript setTimeout args, bind, scope.
function test(){
  var x=20;
  var obj = {x:30};
  function logargs(t,arg1,arg2,arg3,arg4) { 
    console.log(`(${t}) this.x=${this.x},x=${x},obj.x=${obj.x},${arg1},${arg2},${arg3},${arg4.x}`); 
craigphicks /
Created Jul 6, 2019
Forwarding `X11` over `ssh` without using `xauth`

Forwarding X11 over ssh without using xauth

  • local -- the local machine serving an Xserver.
  • remote -- the remote machine serving the application which drives the data going to the Xserver

Remote /etc/ssh/sshd_config:

X11Forwarding no
X11DisplayOffset 10
X11UseLocalhost yes
#<UDF name="ssuser" Label="Sudo user username?" example="username" />
#<UDF name="sspassword" Label="Sudo user password?" example="strongPassword" />
#<UDF name="sspubkey" Label="SSH pubkey (installed for root and sudo user)?" example="ssh-rsa ..." />
# initial needfuls
apt-get -o Acquire::ForceIPv4=true update
craigphicks /
Last active Jun 26, 2019
Used in Ubuntu 18.04 to manipulate desktops as atomic elements of an array, e.g., swapping element order, inserting and deleting empty elements.
# Copyright (c) 2019, Craig P Hicks
# content licensed as CC BY-NC-SA
# CC BY-NC-SA details at
# This program depends upon 'xdotool' installed as Ubuntu 18.04 managed package
# xdotool project source can be found at:
craigphicks /
Last active Apr 25, 2019 — forked from lanceliao/
Cache all packages from OpenWrt trunk repository
#!/usr/bin/env python2
# Openwrt Package Grabber
# Copyright (C) 2014
# modified 2019 craigphicks
import urllib2
craigphicks /
Last active Apr 24, 2019
Setting up openwrt to run on Paspberry Pi 3 B+ - and replacing `iptables` with `nftables`
craigphicks /
Last active Nov 7, 2019
Convert `iptables -S` output to a depth-first tree listing
#!/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
You can’t perform that action at this time.