App-Cheats
view release on metacpan or search on metacpan
#
# 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
Control + r
#############################################################
## Linux Commands - apt-cache
#############################################################
# Search for available apt-get modules/libraries/package
apt-cache search perl
# View more info of packages to be installed
sudo apt-cache show perl
# Show module/library dependancies
apt-cache depends perl
#############################################################
## Linux Commands - apt-get
#############################################################
# Install a package
apt-get install perl
# Upgrade all packages
apt-get update
apt-get upgrade
# Remove a system package
sudo apt-get remove <package>
# Remove a system package along with its dependencies
sudo apt-get remove --auto-remove <package>
# Remove a system package along with its configuration
sudo apt-get purge <package>
# Remove a system package along with its dependencies and configuration
sudo apt-get purge --auto-remove <package>
# Add packages to apt-get install list
apt edit-sources # similar to: vi /etc/apt/sources.list
deb [trusted=yes] http://ftp2.de.debian.org/debian/ stable main contrib
apt-get update
# Apt update has many 404 errors.
# Fix with:
sudo apt dist-upgrade.
#############################################################
## Linux Commands - apt-key
#############################################################
# Add the key of a package site to allow installing from other sources
wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
#############################################################
## Linux Commands - apt-list
#############################################################
# List trusted source lists for packages
sudo apt-key list
#############################################################
## Linux Commands - arp
#############################################################
# View all IP addresses (Debug,pi)
# Scan network
arp -a
netstat -a | findstr 172.17
# Remove arp -a cache (pi,debug)
netsh interface ip delete arpcache
#############################################################
## Linux Commands - awk
#############################################################
# Get the first line, second field (read file)
sui -u | grep "abc" | awk 'NR==1 {print $2}'
#############################################################
## Linux Commands - basename
#############################################################
# Get the basename or last file/directory of a string
basename <string>
#############################################################
## Linux Commands - cat
#############################################################
# Add line numbers to a file
cat -n <file>
# Skip the first line on the file
cat file | tail -n +2
crontab <cron_file>
# View all crontabs on a bench
ls /var/spool/cron/crontabs
# Schedulers
crontab
cron
at
# Crontab job in interactive mode
* * * * * DISPLAY=localhost:11.0 xterm -e 'read -p "aaa - 3"'
# crontab job sent to any particular IP address
* * * * * DISPLAY=1.1.1.1:0 xterm -e 'read -p "aaa - 3"'
# Run a task according to a step amount (say every 5 minutes, crontab)
# min hr dom mon dow command
/5 * * * * my_command
# Run crontab at 3am and 3pm (task)
# min hr dom mon dow command
* 3,15 * * * my_command
#############################################################
## Linux Commands - curl
#############################################################
# View the heading of a server response
curl --head www.google.com
# Check if website/URL is up (Jira,ping)
curl -s --head http://localhost:8081/secure/Dashboard.jspa | head -1
# Download files using curl and validate the checksum:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert.sha256"
echo "$(cat kubectl-convert.sha256) kubectl-convert" | sha256sum --check
#
# Install the new command.
sudo install -o root -g root -m 0755 kubectl-convert /usr/local/bin/kubectl-convert
#############################################################
## Linux Commands - cut
#############################################################
# Show so many character and everything after on a line
echo "1 2 3 5-d 4" | cut -c5-
#############################################################
## Linux Commands - date
#############################################################
# Format for date timestamps in scripts (primitive)
date "+%Y-%m-%d_%H:%M:%S"
# Convert epoch seconds to absolute time (@ means UNIX timestamp)
perl -le 'print ~~ localtime 1484048121'
date -d @1484048121
date -r 1484048121 # Mac
# Date is taken from a variable/string
tool_log_file=`date --date="@$START_DATE" "+%YY_%mm_%dd_%HH_%MM_%SS"`
#############################################################
## Linux Commands - declare, typeset
#############################################################
# List function declarations/names in bash
declare -F
typeset -F
# List function definitions in bash
declare -f
typeset -f
# Show all bash array declarations
declare -a
# Show select bash array declaration
declare -p a
# Create an associative array/hash in bash
# (Make sure NOT to use empty or undef keys!)
declare -A h
# View an associative array/hash in bash
declare -p h
#############################################################
## Linux Commands - df
#############################################################
# See how much disk space is left on the device
df -h /tmp
#############################################################
## Linux Commands - diff, sdiff, patch
#############################################################
# Do a file comparison while showing the context (copy)
diff -c file1 file2
# Do a file comparison while showing the context (unified)
diff -u file1 file2
# Do a difference on variables (not just files)
diff -u <(echo "a") <(echo "b")
# Create a patch file
diff -rupN src2 src > test.patch
# Compare folders
diff -ruN src_sean_latest/ src > diff
# Side by side difference
sdiff file1 file2
# Python bottle module routing options
self.app.get("/<f:path>")(lambda f: bottle.static_file(f, root=path))
self.app.get("/<file:path>")(lambda file: self.get_static_file(file,path))
#
def get_static_file(self,file,path):
self.logger.debug("get_static_file(file:{},path={})".format(file,path))
# Remove option timestamp/UID: version--UID--123.js
file = re.sub(self.is_uid,'',file)
return bottle.static_file(file, root=path)
#
#
The following filters are implemented by default and more may be added:
:int matches (signed) digits only and converts the value to integer.
:float similar to :int but for decimal numbers.
:path matches all characters including the slash character in a non-greedy way and can be used to match more than one path segment.
:re allows you to specify a custom regular expression in the config field. The matched value is not modified.
#############################################################
## Python Modules - datetime
#############################################################
# Get yyyymmmdd format in Python from a integer Epoch string
python -c "import datetime; import os; s=os.stat('version.js'); t=datetime.datetime.fromtimestamp(int(s.st_mtime)).strftime('%Y%m%d%H%M%S'); print(t)"
20210203102701
# Print current time in about YYYYMMDD
python -c "import datetime; print(datetime.date.today().strftime('%Y%m%d'))"
# Current timestamp as a string
python -c "from datetime import datetime; print(datetime.now(tz=None))"
#############################################################
## Python Modules - gevent
#############################################################
# Using gevent in a python webserver
#
import gevent.pywsgi
import geventwebsocket
import geventwebsocket.handler
class Server:
def __init__(self,...):
self.server = gevent.pywsgi.WSGIServer((address, port), self.app,
handler_class=geventwebsocket.handler.WebSocketHandler)
#############################################################
## Python Modules - json
#############################################################
# Using json in a python webserver
#
import json
class Server:
def info(self):
try:
return json.dumps(possible_endpoints)
except KeyError:
return bottle.HTTPError(404, "Error occurred")
#############################################################
## Python Modules - logging
#############################################################
# Log format to use for the logger
log_format = '%(asctime)s %(levelname)s %(module)s.%(funcName)s:%(lineno)d %(message)s'
# Using rotating logs in python (at midnight the log file changes)
import logging.handlers
file_handler = logging.handlers.TimedRotatingFileHandler(filename=log_file, when="midnight")
#############################################################
## Python Modules - os
#############################################################
# Python get the current working directory (dirname)
this_dir = os.path.dirname(os.path.realpath(__file__))
# Example of using system command in python.
python3 -c 'import os; os.system(" ".join(["which", "mid2agb"]))'
#############################################################
## Python Modules - SimpleHTTPServer
#############################################################
# View linux files from windows (debug,pi)
python -m SimpleHTTPServer 8080
http://172.17.17.10:8080/
#############################################################
## Python Modules - socket
#############################################################
# Create a port that can be connected to with netcat
/usr/bin/python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("localhost",4445));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
nc -nlvp 4445
#############################################################
## Python Modules - sys
#############################################################
# Flushing output in Python
import sys
sys.stdout.flush()
#############################################################
## Python Modules - time
#############################################################
# Seconds since epoch
python -c "import time; print(time.time())"
python -c "import time; print(int(time.time()))"
( run in 2.140 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )