Skip to content

Instantly share code, notes, and snippets.

View cmndrsp0ck's full-sized avatar
🖖
Fascinating

Fabian B. cmndrsp0ck

🖖
Fascinating
View GitHub Profile
@cmndrsp0ck
cmndrsp0ck / postgres-cheatsheet.md
Created April 11, 2019 16:25 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@cmndrsp0ck
cmndrsp0ck / kubernetes_add_service_account_kubeconfig.sh
Last active March 20, 2019 06:00 — forked from innovia/kubernetes_add_service_account_kubeconfig.sh
Create a service account and generate a kubeconfig file for it - this will also set the default namespace for the user
#!/bin/bash
set -e
set -o pipefail
# Add user to k8s using service account, no RBAC (must create RBAC after this script)
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
echo "usage: $0 <service_account_name> <namespace>"
exit 1
fi
@cmndrsp0ck
cmndrsp0ck / mkcd
Last active January 7, 2023 05:33
mkdir and cd into it
# set in ${HOME}/.bashrc
function mkcd() {
mkdir -p "$@" && cd -- "$_"
}
@cmndrsp0ck
cmndrsp0ck / GitDeleteCommands.ps1
Created January 6, 2019 06:54 — forked from cmatskas/GitDeleteCommands.ps1
Git Delete Branch commands
## Delete a remote branch
$ git push origin --delete <branch> # Git version 1.7.0 or newer
$ git push origin :<branch> # Git versions older than 1.7.0
## Delete a local branch
$ git branch --delete <branch>
$ git branch -d <branch> # Shorter version
$ git branch -D <branch> # Force delete un-merged branches
## Delete a local remote-tracking branch
@cmndrsp0ck
cmndrsp0ck / consul.service
Created September 10, 2018 06:17 — forked from yunano/consul.service
/etc/systemd/system/consul.service
[Unit]
Description=consul agent
Requires=network-online.target
After=network-online.target
[Service]
EnvironmentFile=-/etc/sysconfig/consul
Environment=GOMAXPROCS=2
Restart=on-failure
ExecStart=/usr/local/sbin/consul agent $OPTIONS -config-dir=/etc/consul.d
@cmndrsp0ck
cmndrsp0ck / consul-template.service
Created September 10, 2018 06:17 — forked from yunano/consul-template.service
/etc/systemd/system/consul-template.service
[Unit]
Description=consul-template
Requires=network-online.target
After=network-online.target consul.service vault.service
[Service]
EnvironmentFile=-/etc/sysconfig/consul-template
Restart=on-failure
ExecStart=/usr/local/sbin/consul-template $OPTIONS -config=/etc/consul-template.d
@cmndrsp0ck
cmndrsp0ck / get-latest-tag-on-git.sh
Created July 9, 2018 18:34 — forked from rponte/get-latest-tag-on-git.sh
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@cmndrsp0ck
cmndrsp0ck / README.md
Last active February 9, 2019 22:31 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@cmndrsp0ck
cmndrsp0ck / randnum.sh
Created May 23, 2018 17:28
Generate random number of variable digit length
function randNum() {
# Generate random number of variable length with a default of 5 digits
local val
local len=${1:-5}
for (( x=0; x<${len}; x++ )); do
val+=($(echo $((RANDOM%9))));
done
printf -- "%s" "${val[@]}"
}
@cmndrsp0ck
cmndrsp0ck / saltmine.sh
Created May 23, 2018 17:24
Function to generate WordPress auth salt that's safe to pass through Jinja template
function makeSalt() {
# Create variable length passwords
LC_CTYPE=C;
local saltine=$(tr -dc 'A-Za-z0-9_@#$%^&*~!?;`./|:{} <>[]()-+=' < /dev/urandom | head -c 64)
if [[ $(echo ${saltine} | grep -P '({%|%}|{#|#}|{{|}}|##)') ]]; then
makeSalt;
else
echo "${saltine}";
fi
}