Skip to content

Instantly share code, notes, and snippets.

@NanoDano
NanoDano / minecraft_backup.py
Created July 14, 2020 01:24
Backup, zip, FTP upload, rotate script for Minecraft server
#!/usr/bin/python3
from ftplib import FTP
import glob
from os import system, path, remove
from os.path import join
from datetime import datetime
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
@NanoDano
NanoDano / maps_caps_to_esc.ahk
Created June 3, 2020 21:26
Map Caps Lock key to Escape in Windows with AutoHotKey
; maps_caps_to_esc.ahk
; AutoHoyKey script to remap Caps lock to Escape key
; Double-click the file or run it directly from the
; command line to start the script in the background.
; To run the script on startup, place in the Startup directory
; by pressing `Windows Key + r` and running `shell:startup`.
Capslock::Esc
@NanoDano
NanoDano / bash_get_user_input.sh
Created June 3, 2020 21:11
Bash get user input
# Simple user prompt
echo -n "Enter name: "
read name
echo $name
# Read with a prompt
read -p "Enter name: " name
echo $name
# If reading from current shell and not running a separate process, use -e
@NanoDano
NanoDano / bash_for_loop_examples.sh
Created June 3, 2020 21:09
Bash For loop examples
# Specific number of iterations
for i in $(seq 1 10)
do
echo $i
done
# Specify list
for x in test.txt misc.txt other.txt
do
rm $x
@NanoDano
NanoDano / bash_history_tips.md
Created June 3, 2020 21:08
Bash history tips

Bash history tips

Run the last command again

!!

Check history

@NanoDano
NanoDano / bash_check_return_value.sh
Created June 3, 2020 21:02
Bash check return values
# See if last statement executed was successful
./runSomething
if [ $? -eq 0 ]; then
echo OK
else
echo FAIL
fi
# The return value can also be stored as a variable
@NanoDano
NanoDano / bash_function_arg_examples.sh
Created June 3, 2020 21:01
Bash functions with arguments examples
# Define a function
hello() {
echo "Hello, world!"
}
# Run the function
hello
# Using function arguments
hello() {
@NanoDano
NanoDano / bash_if_examples.sh
Created June 3, 2020 21:01
Bash IF statement examples
# Specific number of iterations
for i in $(seq 1 10)
do
echo $i
done
# Specify list
for x in test.txt misc.txt other.txt
do
rm $x
@NanoDano
NanoDano / bash_shell_terminal_colors.md
Created June 3, 2020 21:00
Bash shell terminal colors

Colors

Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown 0;33 Yellow 1;33
@NanoDano
NanoDano / check_if_root.sh
Created June 3, 2020 20:59
Bash check if user is root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Exiting"
exit 1
fi