Skip to content

Instantly share code, notes, and snippets.

View caruccio's full-sized avatar
😐
state = not in mood

Mateus Caruccio caruccio

😐
state = not in mood
View GitHub Profile
@caruccio
caruccio / suspend-process.md
Created December 18, 2022 16:29
Suspend cpu greed process and economize your batery

Create the file stop-proc below:

#!/bin/bash

SIG=${0##*/}    ## basename only (name of the file itself, no dirs)
SIG=${SIG%-*}   ## remove filename suffix. "-*" is a glob pattern ("stop" in this case)
SIG=${SIG^^}    ## UPPERCASE all letters

## read process from command line or use this as default.

Keybase proof

I hereby claim:

  • I am caruccio on github.
  • I am caruccio (https://keybase.io/caruccio) on keybase.
  • I have a public key whose fingerprint is 1B8D F261 E133 2C08 7981 40CC 6C8F D64B E1EF E05E

To claim this, I am signing this object:

@caruccio
caruccio / undistro-demo-eks.sh
Last active October 27, 2021 23:21
Undistro Demo EKS
#!/bin/bash
case "$1" in
-h|--help)
echo "Usage: $0 [phase]"
echo ""
echo "Default phases, in this order: "
echo " download Download all required tools into current directory"
echo " credentials Ask for missing credentials"
echo " create-manager-cluster Create Manager Cluster, used to create \"real\" Clusters"
@caruccio
caruccio / Kubernetes-Stuck-Resources.md
Last active October 14, 2020 20:25
How to identify and remove resources stuck in Terminating state

Namespaces

List all resources within a namespace

NS=some-namespace

kubectl api-resources --verbs=list --namespaced -o name \
  | xargs -n 1 kubectl get --show-kind --ignore-not-found -n $NS
@caruccio
caruccio / kubectlgen
Created January 3, 2020 15:45
Kubectl Generator - on-the-fly kubectl shortcuts
#!/usr/bin/python
from __future__ import print_function
import sys
def usage(argv):
print('Usage: %s [commands][resources][options][parameters]' % argv[0], file=sys.stderr)
print('\nCommands:', file=sys.stderr)
for s, l in commands:
print(' %s (%s)' % (s, l), file=sys.stderr)
@caruccio
caruccio / pvc-copy.sh
Created October 4, 2019 21:04
Generates an rsync pod to copy between two PVCs
#!/bin/bash
if [ $# -lt 3 ]; then
echo "Usage: $0 pod-name-suffix source-pvc-name destination-pvc-name [rsync options...]"
exit 1
fi
POD_SUFFIX=${1}
PVC_FROM=${2}
PVC_TO=${3}
@caruccio
caruccio / kubectl.md
Created May 7, 2019 17:21 — forked from so0k/kubectl.md
Playing with kubectl output

Kubectl output options

Let's look at some basic kubectl output options.

Our intention is to list nodes (with their AWS InstanceId) and Pods (sorted by node).

We can start with:

kubectl get no
@caruccio
caruccio / getopts.md
Last active November 3, 2023 22:07
Read shell options with positional arguments

This example shows how to read options and positional arguments from a bash script (same principle can be applied for other shells).

# some global var we want to overwrite with options
force=false
help=false
log=info
ARGS=() ### this array holds any positional arguments, i.e., arguments not started with dash

while [ $# -gt 0 ]; do
@caruccio
caruccio / bash-reload.sh
Last active June 25, 2019 13:05
Reload shell config in-place
## Ever had to add something to your shell's config files (i.e. .bashrc)
## and open a new shell? Well, that may be fine, but you can achieve the
## same result, plus without having to open a new window/tab
## or execute a child process.
##
## Idea taken from https://learn.hashicorp.com/vault/getting-started/install
## lets check if any command `hello` exists
$ hello
bash: hello: command not found
@caruccio
caruccio / spread.sh
Last active September 26, 2018 12:02
Spread parameters
$ function spread_parameter {
local p="$1"
shift
local IFS=","
eval "echo $(echo "$p\ {$*}")"
}
$ spread_parameter --include '*.jpg' '*.gif' '*.svg'
--include *.jpg --include *.gif --include *.svg