Skip to content

Instantly share code, notes, and snippets.

@craigphicks
craigphicks / make-cert.sh
Last active October 26, 2019 01:34
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
#!/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 / iptree.py
Last active April 7, 2020 10:52
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
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 / openssh-descrption-of-X11-forwarding.md
Created July 7, 2020 22:11
openssh descrption of X11 forwarding

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

#!/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 / cli.js
Last active November 21, 2020 04:36
js server-client pair - echo text enter into client terminal
var net = require('net');
var jsesc = require('jsesc');
var ctrlC=false;
//var qwrite=[];
async function Socketing(sock){
return await new Promise((res,rej)=>{
// Event: 'data'
sock.on('data', (d) => {
console.log(`sock data: ${jsesc(Buffer.from(d).toString(),{es6:true})}`);
@craigphicks
craigphicks / dtdotool.sh
Last active December 27, 2020 08:04
Used in Ubuntu 18.04 to manipulate desktops as atomic elements of an array, e.g., swapping element order, inserting and deleting empty elements.
#!/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 / custom-tsc.ts
Last active January 6, 2021 13:21
Typescript - How to compile only one (or more) files from a project using all the project settings from the tsconfig file(s)
import * as ts from 'typescript';
import * as fs from 'fs';
import * as path from 'path';
import * as cp from 'child_process';
import * as dm from '../src-ts/deep-merge-objects';
function compile(fileNames: string[], options: ts.CompilerOptions): void {
const program = ts.createProgram(fileNames, options);
const emitResult = program.emit();
const allDiagnostics = ts
@craigphicks
craigphicks / commonjs-index.js
Created July 26, 2021 06:52
comparison of index.js produced with module:CommonJs vs. module:es2020 under yamato_daiwa-es_extensions
(() => {
"use strict";
var e, t = {
5272: (e, t) => {
Object.defineProperty(t, "__esModule", {
value: !0
}), t.default = function(e, t) {
for (const [a, n] of e.entries())
if (t(n)) return a;
return null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
"type": {
"info": "this is a ts.Type with id=86",
"flags": [
"Union"
],
"objectFlags": [
"PrimitiveUnion"
]