Skip to content

Instantly share code, notes, and snippets.

View wheelq's full-sized avatar
🎯
Focusing

Michal Wiczynski wheelq

🎯
Focusing
View GitHub Profile
@wheelq
wheelq / bash_templating.sh
Created May 1, 2019 07:31
Templating in bash
#!/usr/bin/env bash
#Templating
#More examples: https://unix.stackexchange.com/questions/73969/how-can-i-use-sed-or-awk-to-replace-placeholders-in-a-template-file-with-variabl
sed -e "s/\${i}/1/" -e "s/\${word}/dog/" template.txt > result.txt
@wheelq
wheelq / docker-logs.sh
Created July 31, 2019 14:08
docker-tail compose style
#!/bin/bash
# Stolen from: https://github.com/joemiller/docker-tail/blob/master/Makefile ;)
# `tail -f` the logs of one or more docker containers, with each log line prefixed
# with the container name and a color.
#
VERSION="0.1.0"
# set of colors for output. We rotate through them and re-use.
COLORS=("\x1b[31m" "\x1b[32m" "\x1b[33m" "\x1b[34m" "\x1b[35m")
@wheelq
wheelq / heredoc_hacks.md
Created February 8, 2021 20:43
Heredoc hacks

variable substitution, leading tab retained, overwrite file, echo to stdout

tee /path/to/file <<EOF
${variable}
EOF

no variable substitution, leading tab retained, overwrite file, echo to stdout

@wheelq
wheelq / k8s-key-export.sh
Created January 31, 2021 16:42
Kubernetes- Export certificate info
#!/usr/bin/env bash
# Export CA
kubectl config view --minify --raw --output 'jsonpath={..cluster.certificate-authority-data}' | base64 -D > ca.crt
# Export Client Cert
kubectl config view --minify --raw --output 'jsonpath={..user.client-certificate-data}' | base64 -D > client.crt
# Export Client Key
kubectl config view --minify --raw --output 'jsonpath={..user.client-key-data}' | base64 -D >client.key
# Usage:
curl -k --cert client.crt --key client.key --cacert ca.crt https://[K8S_HOST]:6443/api/v1/pod
@wheelq
wheelq / docker-compose.yml
Created June 22, 2020 13:08
Logio in docker
version: '3'
services:
logs:
image: gerchardon/docker-logio
links:
- logio:logio
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: -h logio -n docker
privileged: true
@wheelq
wheelq / entropy.sh
Created June 22, 2020 08:04
entropy - docker-compose
cat /proc/sys/kernel/random/entropy_avail
# around 5
apt install -y haveged
systemctl status haveged.service
cat /proc/sys/kernel/random/entropy_avail
# 2400 or more
@wheelq
wheelq / sinatra.README.rdoc
Created May 13, 2020 14:23 — forked from sivagao/sinatra.README.rdoc
sinatra.readme.en

Sinatra

Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort:

# myapp.rb
require 'sinatra'

get '/' do
  'Hello world!'
@wheelq
wheelq / zsh.aliases
Created May 11, 2020 16:37
Aliases for DNS, find files and ssh-keygen
alias dns="scutil --dns | grep 'nameserver\[[0-9]*\]'"
alias ffile='function __ffile(){if [ -z $2 ]; then _loc=".";else _loc="${2}";fi; if [ -z $1 ]; then echo "use: ffile [filename] [path]";else find "${_loc}" -type f -iname "*$1*" 2>/dev/null;unset -f __ffile;fi }; __ffile'
alias create-ssh-key='function _create(){SUFFIX=$(date +%Y%m%d_%H%M%S);ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519_${SUFFIX}_wheelq -C "id_ed25519_${SUFFIX}_wheelq"; unset -f _create;echo -e "Key: ${HOME}/.ssh/id_ed25519_${SUFFIX}_wheelq\n\n$(cat ${HOME}/.ssh/id_ed25519_${SUFFIX}_wheelq.pub)"};_create'
@wheelq
wheelq / go.alias
Last active March 28, 2020 11:57
Dockered go as an alias
#echo "alias go=' function __go(){ docker run --rm -v \"\${PWD}:/usr/src/myapp\" -w /usr/src/myapp -it golang:latest go \$@;unset -f __go;}; __go'"|tee -a ~/.bash_profile >> ~/.bashrc
echo -e "#\!/usr/bin/env bash\nfunction __go(){ docker run --rm -v \"\${PWD}:/usr/src/myapp\" -w /usr/src/myapp -it golang:latest go \$@;unset -f __go;}; __go \$@" > /usr/local/bin/go && chmod 755 /usr/local/bin/go
@wheelq
wheelq / terraform.alias
Last active March 28, 2020 11:56
Alias for terraform from docker
#echo "alias terraform=' function __terraform(){ docker run --rm -v \"\${PWD}:/src\" -w /src -v ~/.terraform.d:/root/.terraform.d -it hashicorp/terraform:light \$@;unset -f __terraform;}; __terraform'"|tee -a ~/.bash_profile >> ~/.bashrc
echo -e "#\!/usr/bin/env bash\nfunction __terraform(){ docker run --rm -v \"\${PWD}:/src\" -w /src -v ~/.terraform.d:/root/.terraform.d -it hashicorp/terraform:light \$@;unset -f __terraform;}; __terraform \$@" >/usr/local/bin/terraform && chmod 755 /usr/local/bin/terraform