Skip to content

Instantly share code, notes, and snippets.

@deevis
deevis / gist:fa50df908bef0aee2ac898961ca0ebf7
Created August 12, 2023 23:17
Portainer - backup/new docker
# To backup portainer volume
_backup_time=$(date +"%F_%H_%M%P"); sudo tar cvfz /mnt2/docker/backups/portainer/portainer_backup_${_backup_time}.tar.gz /var/lib/docker/volumes/portainer_data
# To run new portainer container with ports and volumes and local docker.sock
docker run -p 8000:8000 -p 9000:9000 --name portainer -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
@deevis
deevis / create_mysql_db_and_user.sql
Last active June 4, 2023 01:40
New MySQL (MariaDB) Schema/User
create database prisoners;
CREATE USER 'prisoners'@'%' IDENTIFIED BY '???????????';
GRANT ALL PRIVILEGES ON prisoners.* TO 'prisoners'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
@deevis
deevis / Linux-Samba-sharing.txt
Last active May 21, 2023 19:29
Mount shared volume on linux (Raspberry Pi)
# on host (eg: 192.168.0.111)
sudo apt-get install samba samba-common-bin
sudo vi /etc/samba/smb.conf
# create directory with correct permissions that can be exposed via Samba
sudo mkdir -p /mnt/drive01
sudo chown -R pi:pi /mnt/drive01
# add sections within /etc/samba/smb.conf
[Pi Media Share]
@deevis
deevis / mysql_backup.sh
Last active October 30, 2022 18:36
Backup all MySQL (MariaDB) databases
#!/bin/bash
_now=$(date +"%F_%H_%M%P")
pushd /mnt2/backups/mysql/
for db_name in `mysql -h 127.0.0.1 -u root -e "show databases;" | grep "\|" | grep -v "_schema" | grep -v "mysql" | tail -n +2`; do
echo "Backing up ${db_name}"
filename="${db_name}_${_now}.sql"
mysqldump -h 127.0.0.1 -u root $db_name > ${filename}
done
tar cvfz mysql_pi_${_now}.tar.gz $(ls *${_now}*.sql) && rm *${_now}*.sql
@deevis
deevis / path_finder.rb
Created January 24, 2022 02:11
PathFinder along with solution visualization
# originally a solution for Codewars.com: Path Finder #3: the Alpinist
class PathFinder
# Options for display_strategy: [nil, :highlight, :animate]
def initialize(display_strategy =nil)
@display_strategy = display_strategy
end
# Options for display_strategy: [nil, :highlight, :animate]
def path_finder(maze, display_strategy = nil)
@deevis
deevis / react_hook_usage.sh
Created September 20, 2021 19:08
Build a histogram of React hook usage in a project
for effect in useState useEffect useContext useReducer useCallback useMemo useRef useImperativeHandle useLayoutEffect useDebugValue; do RESULT=`find client/src -iname "*.js" | xargs grep -s -E "import React.*use.*from" | grep $effect | wc -l`; echo "$RESULT $effect"; done | sort -n -r
# 166 useState
# 128 useEffect
# 23 useCallback
# 8 useRef
# 1 useReducer
# 1 useContext
# 0 useMemo
@deevis
deevis / bit_flags.rb
Last active July 22, 2021 16:29
Working with bitflags in Ruby
# our flags ordered by the bit that they'll toggle
# new flags MUST be added to the BEGINNING of the array!
FLAGS = [:a, :b, :c, :d, :e, :f]
build_flags = -> (*performed) { n = FLAGS.length; val = 0; FLAGS.each{|v| n -= 1; val += 2 ** n if performed.index(v)}; val}
required = build_flags.(:a, :b, :c, :f)
=> 57
required.to_s(2)
=> "111001"
@deevis
deevis / gist:05cf1e381f141e2f0d0d3dd902c2d1e8
Last active March 12, 2021 00:50
List processes with time running and total memory used
IFS=$'\n'
for line in `ps -o pid,etime,%mem,command ax | grep launch | grep -v "grep"`; do echo "---------------------------------"; echo $line; echo $line | awk '{print $1}' | xargs pmap | grep "total"; done; echo ""
@deevis
deevis / gist:a8617e68903ca063ce94dec9c7557d41
Created February 22, 2021 18:10
Delete Kubectl namespaces in my project older than 40d ( but not > 99)
for ns in `kubectl get pods -A | grep my_project_name | grep "^.*[4-9]\dd$" | awk {'print $1'} | uniq`;do kubectl delete namespace $ns --namespace $ns; done
@deevis
deevis / ipod_recovery.rb
Created February 18, 2021 05:39
If you have a bunch of F00-F95 mp3 folders with encrypted file names, put this in the same folder to build an unencrypted filename directory structure of files
# To build music_log.txt
# ------------------------------------
# sudo apt-get install ffmpeg
# SAVEIFS=$IFS
# IFS=$(echo -en "\n\b")
# for file in `find . -iname "*.mp3"`;do echo "=========================="; echo $file; ffprobe $file 2>&1 | grep -A 12 'Metadata:'; done > music_log.txt
require 'awesome_print'
# require 'byebug'