Skip to content

Instantly share code, notes, and snippets.

View the-moog's full-sized avatar
💭
Not looking for a new job

Jay the-moog

💭
Not looking for a new job
  • Qualcomm/QTI, UK, Cambridge
  • Cambridge, UK
  • 21:24 (UTC)
View GitHub Profile
@the-moog
the-moog / remote-sftp.shsrc
Created November 7, 2024 04:49
Running remote sftp commands from a script
# use the source, Luke
# > source remote-sftp.shsrc
action="df -h\nexit\n"
for d in / /vol /vol/homes /vol/Public; do
echo "${d}:"
echo -e "${action}" | sftp "user@fs1:${d}"
echo "${d}/:"
@the-moog
the-moog / .bash_aliases
Last active February 9, 2024 18:43
Got fed up trying to work out which .ssh key maps to which host hence: alias (or function) lskeys
alias lskeys='for kf in ~/.ssh/*.priv; do read -rst 2 size fingerprint userid txt <<<$(ssh-keygen -l -f ${kf});\
printf "KEYFILE: %-50s - BITS: %-6d FP: %s, USER: '%s', INFO: '%s'\n" "$(basename ${kf})" "${size}" "${fingerprint}" "${userid}" "${txt}"; done'
@the-moog
the-moog / README.md
Created September 13, 2023 13:02
shebang: '/usr/bin/env /path/interpreter' or '/usr/bin/env interpreter'??

Running

Notice that #2 in the 2nd example is the only one that works

1: Without user PATH

./envtest1;./envtest2;./envtest3

diff &lt;(cat env_envtest1) &lt;(cat env_envtest2)
@the-moog
the-moog / rainbow.sh
Last active June 9, 2023 13:21
Bash shell scipt that prints lots of colous on an ANSI terminal
#!/bin/bash
# rainbow
# A bash script that prints a nice set of colours on an ANSI terminal
# Written as a platform to test capability and conformance, but it's also pretty!!
# Written in celebration of Pride Month 2023 and support of LGBTQ+
# J. Morgan (@the-moog on github)
#
# License: MIT: Free to the community not commercial gain and no warranties applied.
@the-moog
the-moog / WSL2-DNAT-HowTo.md
Created June 6, 2023 19:48
Make WSL2 networking play nicely with DNAT/dest-NAT/portproxy and/or give WSL a static IP address

Port forwarding from host (aka WSL2 Static IP)

I have read many articles about WSL networking that try and sort DNAT and static IP and none that I've found seem to work or only work for some. So here is my attempt....

It seems getting port forwarding to work in WSL is not easy. I think WSL has unusual hidden network mechanisms and that confuses the matter. Also when WSL boots the WSL init mechanism gives the guest a random address, which is no use for static NAT

This worked for me. Try it yourself and let me know if I've finally cracked it !!

@the-moog
the-moog / get_real_login.sh
Created June 1, 2023 18:58
Bash script to find the true UID and HOME of a user once they have used sudo or are not in an interractive login.
#!/bin/bash
# Bash script, related to https://stackoverflow.com/a/76384868/1364242
# get_real_login.sh
# Get the name at the time of login of the user who is running this script
# MIT License
LICENSE="
Copyright (c) <2023> <https://github.com/the-moog>
Permission is hereby granted, free of charge, to any person obtaining a copy
@the-moog
the-moog / build.bash
Last active March 19, 2023 00:15
Improved fix for dynamic build and load of shared library support when using pyenv virtualenv (Python)
### pyenv hook script to prepare a build env
#
# 0: Intro
# $MYLOC points to your local sideload root (usually ~/.local)
MYLOC=$HOME/.local
#
export PYTHON_CONFIGURE_OPTS="--with-openssl=$MYLOC --enable-shared --enable-optimizations --with-lto"
export PYTHON_CFLAGS="-march=native -mtune=native"
echo ""
echo "This is $(basename $0) hook 'build.bash':"
@the-moog
the-moog / Makefile
Created January 4, 2023 15:13
makefile to see if it's possible to detect source of shell invocation with the make run
# use a bash as sh is sh*#
.SHELL = /bin/bash -e
# Turn off make's legacy cruft
.SUFFIXES:
# Unless otherwise stated
.DEFAULT_GOAL := diff
# TOOLS
@the-moog
the-moog / cards.c
Created June 20, 2022 13:24
Sidestepping limitation of variable length member of fixed array sizes
#include <stdio.h> // for printf
#include <string.h> // for strcmp
// Define a card
typedef struct card
{
int value; // This is an int, so it's storage size does not change
char * name; // This is a pointer, so it's storange size does not change
int rule_change;
} card_t;
@the-moog
the-moog / round_vs_floor.py
Last active June 18, 2022 19:11
Comparing Python round() vs math.floor()
import timeit
import sys
import platform
# Expected result values vs output values (we always expect rounded down)
du = {
1.231234: 1.23,
1.239876: 1.23,
1.999999: 1.99,
1.00000001: 1.00,