Skip to content

Instantly share code, notes, and snippets.

View redsfyre's full-sized avatar
:shipit:
There is nothing here -> /dev/null

Yasin İsa YILDIRIM redsfyre

:shipit:
There is nothing here -> /dev/null
View GitHub Profile
@redsfyre
redsfyre / nvfixbl.sh
Created June 9, 2021 19:07
Simple script I wrote for Arch Linux to use Nvidia brightness setting properly
#!/bin/bash
for x in \
nvidia-460.67-5-x86_64.pkg.tar.zst \
nvidia-dkms-460.67-1-x86_64.pkg.tar.zst \
nvidia-settings-460.67-1-x86_64.pkg.tar.zst \
nvidia-utils-460.67-1-x86_64.pkg.tar.zst \
; do
test -f $x || \
@redsfyre
redsfyre / basic-parser.sh
Last active August 23, 2021 07:15
An extended yaml parser for bash scripts. Copied from https://stackoverflow.com/a/21189044/13756006 and https://stackoverflow.com/a/51789677/13756006 and https://github.com/mrbaseman/parse_yaml Note: This gist was created so that I can easily access these scripts when needed.
#!/bin/sh
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
@redsfyre
redsfyre / k8s-all-cron-suspend.sh
Created November 5, 2021 14:05
Script that stops (suspends) all running kubernetes cronjobs
#!/bin/bash
for ns in $(kubectl get ns -o jsonpath="{.items[*].metadata.name}"); do
for cj in $(kubectl get cronjobs -n "$ns" -o name); do
kubectl patch "$cj" -n "$ns" -p '{"spec" : {"suspend" : true }}';
done
done
@redsfyre
redsfyre / mem.sh
Last active November 5, 2021 14:13
The command that gives the memory usage of the named application in mb (WIP)
appname= XX;
for line in $(ps -e -orss=,args= | sort -b -k1 -nr | grep $appname | cut -d' ' -f1);
do
declare -i mem; mem="$line/1024"; echo "$mem M";
done
@redsfyre
redsfyre / psmem20.sh
Created November 5, 2021 14:15
Top 20 processes that consume the most memory
#/bin/bash
ps -e -orss=,args= | sort -b -k1 -nr | head -20
@redsfyre
redsfyre / aliases.sh
Created November 5, 2021 14:20
This gist has been updated to include my favorite aliases and funcs.
dls () {
print -l *(/)
}
@redsfyre
redsfyre / copy_id_sequence.sql
Last active November 9, 2021 07:27
While I was creating postgresql table partitions, I realized that I needed to move/copy the old id sequence to the new table. We can do this with the following query
postgres_test_db=# select last_value from old_table_id_seq;
last_value
------------
2084740
(1 row)
postgres_test_db=# select last_value from new_table_id_seq;
last_value
------------
1
@redsfyre
redsfyre / index_dropper.sql
Created November 9, 2021 10:58
Query that drops all indexes in the given table. Note: unique keys are not affected by this operation.
DO
$do$
DECLARE
_sql text;
BEGIN
SELECT 'DROP INDEX ' || string_agg(indexrelid::regclass::text, ', ')
FROM pg_index i
LEFT JOIN pg_depend d ON d.objid = i.indexrelid
AND d.deptype = 'i'
WHERE i.indrelid = 'TABLE_NAME'::regclass -- Replace the TABLE_NAME with your table's name
@redsfyre
redsfyre / k8s-ocp-cli-tricks.md
Last active December 24, 2021 13:10
Kubernetes & Openshift CLI Tricks -- WIP

Kubernetes list all deployments and their specs (requests/limits)

kubectl get deployments -o jsonpath='{range .items[*]}{"NAME:  "}{.metadata.name}{"\nSPEC:  \n  LIMITS  : "}{.spec.template.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.template.spec.containers[*].resources.requests}{"\n\n"}{end}'

Kubernetes list all cronjobs and their specs (requests/limits)

kubectl get cronjobs -o jsonpath='{range .items[*]}{"NAME:  "}{.metadata.name}{"\nSPEC:  \n  LIMITS  : "}{.spec.jobTemplate.spec.template.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.jobTemplate.spec.template.spec.containers[*].resources.requests}{"\n\n"}{end}'
@redsfyre
redsfyre / sequence_list.sql
Created March 23, 2022 08:05
List postgresql sequences. Actually i dont remember what is this query :D
select sequence_name, (xpath('/row/last_value/text()', xml_count))[1]::text::int as last_value
from (
select sequence_schema,
sequence_name,
query_to_xml(format('select last_value from %I.%I', sequence_schema, sequence_name), false, true, '') as xml_count
from information_schema.sequences
where sequence_schema = 'public'
) new_table order by sequence_name asc;