App-Cheats
view release on metacpan or search on metacpan
#
# except it is a generic solution which works also outside of minikube.
# IAM - Ingress enable.
minikube addons list | grep ingress
minikube addons enable ingress
# IAM - Ingress simple guide:
https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/
# Need to also update /etc/hosts
# IAM - Ingress example resource file:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: keycloak-ingress-service
namespace: iam-ns
labels:
app: keycloak
spec:
rules:
- host: hello-world.info # Ask krikkit for correct name!
http:
paths:
- path: / # Redirects requests back to self
pathType: Prefix
backend:
service:
name: keycloak-service # To this existing service
port:
number: 8080 # and port
#############################################################
## Journalctl
#############################################################
# Examples of journalctl commands.
journalctl _PID=1 # From a precific PID.
journalctl -S -4h # Since last 4 hours.
journalctl -S 22:00:00 # Since a sprecific time.
journalctl -S 2022-02-10 # Since a specific date.
journalctl -S '2022-02-10 22:00:00' # Since a specific date and time.
journalctl -U 22:00:00 # Until a specific time.
journalctl -u cron[.service] # Search by unit type.
journalctl -F _SYSTEMD_UNIT # List all units found in the logs.
journalctl -N # List all fields.
journalctl -g 'gas.*' # Grep through the logs.
journalctl -b # Start to end of current boot.
journalctl -b -1 # Start to end of last boot.
journalctl -b -r # Start to end of current boot in reverse.
journalctl --list-boots # List boots by IDs.
journalctl -k # Display kernel messages.
journalctl -f # Like tail -f.
#############################################################
## JP2A
#############################################################
# png to ascii converter (linux,ascii,art)
sudo apt install jp2a
jp2a --colors programmer_icon.png
#############################################################
## Kate Editor
#############################################################
# Kate editor shortcuts
F6 - Left margin
F9 - Right margin (code folding)
F11 - Line numbers
#############################################################
## Kubeseal
#############################################################
# Kubeseal handles passwords - Simple use case.
# Creates a yaml manifest file that can be used publicly.
# without sharing the real password.
echo -n bar | kubectl create secret generic mysecret --dry-run=client --from-file=foo=/dev/stdin -o yaml > mysecret.yaml
# Seal a kubernetes manifest file.
# This service needs to be running:
kubectl get service sealed-secrets-controller -n kube-system
#
# Run this to seal:
cat mysecret.yaml | kubeseal --format=yaml --namespace iam --controller-namespace kube-system --controller-name sealed-secrets-controller > my-sealed-secret.yaml
#############################################################
## Keycloak
#############################################################
# Keycloak links
admin: http://localhost:8080/admin
realm: http://localhost:8080/realms/myrealm/account
# Keycloak simple example.
https://www.keycloak.org/getting-started/getting-started-docker
#
# Get the latest image:
docker pull quay.io/keycloak/keycloak:latest
#
# Can see that its using kc.sh as the entrypoint:
docker inspect quay.io/keycloak/keycloak:latest
#
# View the help page:
docker run quay.io/keycloak/keycloak:latest -h
#
# Start a simple development server:
docker run --rm -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev
#
# Go to http://localhost:8080/
#############################################################
# Linux Terminal
#############################################################
# Search through linux terminal history
// UA_Server_run
# Add a namespace (ns=2) open62541
# Get namespace index given a name.
UA_String s = UA_String_fromChars("myNamespace");
UA_Server_addNamespace(server, "myNamespace");
size_t ns;
UA_Server_getNamespaceByName(server, s, &ns);
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "ns=%d", ns);
#############################################################
## openssl
#############################################################
# convert pem file to certificate file.
openssl x509 -in MY.pem -outform DER -out MY.cert
# Fetch certificate authorization file (openssl).
wget LINK -O MY.cert
# View certificate file.
openssl x509 -in MY.cert -text -noout
#############################################################
## Parallel
#############################################################
# Run multiple commands in parallel.
# Specify how many to run at once.
cat commands.sh | parallel -j 10
#############################################################
## PDF
#############################################################
# View pdf files on linux
xpdf perl6intro.pdf
# Parse PDF files (convert to text)
pdftotext file.pdf
pdftotext file.pdf -
# Make pdf of differences on Linux
kdiff3 file1 file2
File->Print
Properties->PageSize = A1 -> Save
Print to pdf
# Simple perl library for generating pdf files
sudo apt-get install libpdf-api2-simple-perl
# Simple perl library for generating pdf files with tables
# Need also PDF::API2
sudo apt-get install libpdf-table-perl
# Get the dimensions of a PNG image file (picture)
sudo apt-get install libimage-size-perl
perl -MImage::Size -le 'print for imgsize("logo.png");'
# HTML to PDF tool
sudo apt-get install wkhtmltopdf
# Send output to pdf
# setup
sudo apt-get install aha
echo -e "Im $RED RED $RESTORE now" | aha
#############################################################
## Perl General
#############################################################
# Zen of Perl
# wget http://www.perlmonks.org/?abspart=1;node_id=752029;displaytype=displaycode;part=1
Beauty is subjective.
Explicit is recommended, but not required.
Simple is good, but complex can be good too.
And although complicated is bad,
Verbose and complicated is worse.
Brief is better than long-winded.
But readability counts.
So use whitespace to enhance readability.
Not because you're required to.
Practicality always beats purity.
In the face of ambiguity, do what I mean.
There's more than one way to do it.
Although that might not be obvious unless you're a Monk.
At your discretion is better than not at all.
Although your discretion should be used judiciously.
Just because the code looks clean doesn't mean it is good.
Just because the code looks messy doesn't mean it is bad.
Reuse via CPAN is one honking great idea -- let's do more of that
# Zen of Perl
According to Larry Wall, there are three great virtues of a programmer; Laziness, Impatience and Hubris
- Laziness:
- The quality that makes you go to great effort to reduce overall energy expenditure.
- It makes you write labor-saving programs that other people will find useful and
- document what you wrote so you don't have to answer so many questions about it.
- Impatience:
- The anger you feel when the computer is being lazy.
- This makes you write programs that don't just react to your needs,
- but actually anticipate them.
- Or at least pretend to.
- Hubris:
- The quality that makes you write (and maintain) programs that other
- people won't want to say bad things about.
# Create a modulino (Module/program that can be also run standalone/by itself)
run unless caller;
# Use yadda yadda to denote not yet implemented code.
perl -E 'sub F{} F'
perl -E 'sub F{...} F'
Unimplemented at -e line 1.
#############################################################
Running child 1
parent is reading now pid: 593943
parent is reading now pid: 593944
parent is reading now pid: 593945
parent is reading now pid: 593946
parent is reading now pid: 593947
{
"593943" => [
"From-1"
],
"593944" => [
"From-2"
],
"593945" => [
"From-3"
],
"593946" => [
"From-4"
],
"593947" => [
"From-5"
]
}
# Run multiple processes and collect their data (no debug output).
perl -MMojo::Util=dumper -E 'use strict; use warnings; local $| = 1; my @Wait; for my $Count (1..200){ my($In,$Out); pipe($In,$Out); my $PID = fork; if (!$PID){ close $In; sleep int(rand(5)); say $Out "From-$Count"; close $Out; exit 0 } close $Out; p...
# Run multiple processes and collect their data.
# Sends a structure back from the children.
perl -Mojo -E 'local $| = 1; my @Wait; for my $Count (1..5){ my($In,$Out); pipe($In,$Out); my $PID = fork; if (!$PID){ close $In; sleep int(rand(5)); say $Out j { Title => "From-$Count", Count => $Count }; close $Out; exit 0 } close $Out; push @Wait,...
{
"1" => {
"ChildPid" => 28843,
"Count" => 1,
"Title" => "From-1"
},
"2" => {
"ChildPid" => 28844,
"Count" => 2,
"Title" => "From-2"
},
"3" => {
"ChildPid" => 28845,
"Count" => 3,
"Title" => "From-3"
},
"4" => {
"ChildPid" => 28846,
"Count" => 4,
"Title" => "From-4"
},
"5" => {
"ChildPid" => 28847,
"Count" => 5,
"Title" => "From-5"
}
}
# Process killing example:
perl -E '$pid = fork; if (!$pid){ say "[$$] child", sleep 1 while 1 } else { say "[$$] parent"; waitpid $pid, 0; say "[$$] parent end" }'
perl -E '$pid = fork; if (!$pid){ say "[$$] child", sleep 1 while 0; say "start"; system qq(google-chrome --headless --virtual-time-budget=15000 --window-size=200,200 --screenshot=$ENV{HOME}/Downloads/my.png log); say "wait"; sleep 10 } else { say "...
#
perl -E 'for ( shift ) { say kill 0, $_; sleep 1; say kill -9, $_; sleep 1; say kill 0, $_ }' 3022126
#############################################################
## Perl Functions - getpwnam, getgrent, getgrnam, getgrgid
#############################################################
# UID in scalar context, all fields in list
perl -lE '$a=getpwnam("<USER>"); say $a'
perl -lE 'say for getpwnam("<USER>")'
# Group name entry
perl -lE 'say getgrent'
# Get name
perl -lE 'say for getgrnam("systems")'
# Group ID
perl -lE 'say for getgrgid("systems")'
# Get password file entry for a username (check if they exist)
perl -le 'print for getpwnam "<USER>"'
#############################################################
## Perl Functions - local
#############################################################
# Can use local actually with a lexical/my variable.
perl -Mojo -E 'my %h; { local $h{abc}=1; say r \%h } say r \%h'
perl -Mojo -E 'my %h; sub show { say "show: " . r \%h } { local $h{abc}=1; show() } show()'
show: {
"abc" => 1
}
show: {}
# Comparing lexical and global (quite similar).
perl -E 'sub show { my ($ref) = @_; say "$ref $$ref" } my $my = 111; our $our = 222; show \$my; show \$our; { my $my = 112; local $our = 223; show \$my; show \$our } show \$my; show \$our' SCALAR(0xb4000075870a0168) 111...
SCALAR(0xb4000075870a0198) 222
SCALAR(0xb4000075870a1498) 112
SCALAR(0xb40000758701f678) 223
SCALAR(0xb4000075870a0168) 111
SCALAR(0xb4000075870a0198) 222
#############################################################
## Perl Functions - msgsnd, msgrcv
#############################################################
# Send and receive message from the queue (IPC)
perl -le 'msgsnd 99483684, "123456789", 0'
perl -le 'msgrcv 99483684, $var, 24, 0, 0; print "[$var]"'
#############################################################
## Perl Functions - ord
#############################################################
# Show ascii ordinal values
#
# Do nothing (plus uncomment)
HandleLidSwitch=ignore
#
# Suspend
HandleLidSwitch=suspend
#
# Restart system daemon
sudo systemctl daemon-reload
# Check the battery charging threshold on Linux (Ubuntu)
cat /sys/class/power_supply/BAT0/charge_st*
# Ubuntu prevent auto suspend when closing the lid.
# Check default:
gsettings get org.gnome.settings-daemon.plugins.power lid-close-battery-action # 'suspend'
gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action # 'suspend'
#
# Change default:
gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action nothing
gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing
#
# Didnt WORK!
# Ubuntu prevent auto suspend when closing the lid.
sudo apt install gnome-tweaks
# Start Tweaks -> General
#############################################################
## Ubuntu - X-Server
#############################################################
# On Ubuntu there are 2 X-Servers available during login:
- Wayland
- Xorg
# Wayland is newer and to use screen sharing (share,jitsi) in
chrome enable this:
chrome://flags/#enable-webrtc-pipewire-capturer
# Xorg should be avoided since it can cause a black screen on lock screen
(at least if an extra monitor is connected).
#############################################################
## Ubuntu - Desktop/Tasklist App
#############################################################
# Sample .desktop file to add xair as a favorite program.
cat xair.desktop
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=XAIR
# If file name is to be renamed, also probably need to update this class,
# (as is done now).
# Run:
# xprop WM_CLASS # WM_CLASS(STRING) = "X-AIR-Edit", "X-AIR-Edit"
StartupWMClass=X-AIR-Edit
Exec=/home/tim/git/xair/software/latest/RUN.sh
Icon=/home/tim/git/xair/software/latest/xair.png
#############################################################
## VBA Regex
#############################################################
# Regex for validating input on database
cat data | add_color -r '(?x) ^ (?! ^( (ALLENGINES|ASAPPLICABLE|PW\d+\w+-?\w+)(,|$))+ ((Except:)? (\d{6}-\d{6}|\d{6}) (,|$) )* $ ) .*'
#############################################################
## Vim Strings
#############################################################
# Example of using a multiline string in Vim
#
+ " Perl Data Dumper and other useful features all in one mapping.
+ function PerlDev()
+ let l:PERL_DEV = "
+ \\nuse v5.32;
+ \\nuse Mojo::Util qw(dumper);
+ \\nuse Carp qw( croak confess carp cluck );
+ \\nsub WhoAmI { say '--> ' . (caller(1))[3] }
+ \\nsay 'var: ', dumper $var;
+ \\n$Self->HandleException('message'); # New - Test/*
+ \\n$Selenium->HandleError('message'); # Legacy - script/*
+ \\n
+ \\n"
+
+ put =l:PERL_DEV
+ endfunction
+
+ nnoremap <leader>r :call PerlDev()<CR>
#############################################################
## Vim Quitting
#############################################################
# Exit, saving changes (Vim)
:x
# Exit as long as there have been no changes (Vim)
:q
# Exit and save changes if any have been made (Vim)
ZZ
# Exit and ignore any changes (Vim)
:q!
#############################################################
## Vim Variables
#############################################################
# Do substitution on a string or variable (vim)
let new_variable s = ubstitute("My::Long::Package", "::", "/", "g")
let old_variable = "My::Long::Package"
let new_variable = substitute(old_variable, "::", "/", "g")
( run in 2.254 seconds using v1.01-cache-2.11-cpan-364913b4093 )