Skip to content

Instantly share code, notes, and snippets.

@biiont
biiont / batch_image_resample.sh
Created October 1, 2015 10:07
Batch image resample
#!/bin/sh
# This script allows to resample images from whatever DPI to 75 DPI (screen resolution)
# in batch. I use it to prepare smallsize images of scans of my IDs, etc...
cd path/to/collections/base/dir
for fi in $(/bin/ls -1 image_collection_600dpi/*)
do
fo="$(echo $fi | sed 's/_[[:digit:]]\+dpi//g')"
echo convert-im6 $fi -units PixelsPerInch -resample 75 $fo
@biiont
biiont / someservice
Created October 1, 2015 08:28
init.d service for ordinary console app
#!/bin/sh
# This is /etc/sysconfig/someservice:
# CHARTSRVBASE="/opt/someservice"
# CHARTSRVRUN="/opt/someservice"
# CHARTSRVBIN="/opt/someservice/someservice"
# CHARTSRVPID="/var/run/someservice.pid"
# CHARTSRVLOG="/var/log/someservice/someservice-$(date +%Y%m%d%H%M%S).log"
########################################################################
# Begin $rc_base/init.d/
# Description :
@biiont
biiont / absolute_paths_in_shell.sh
Created October 1, 2015 08:22
Canonical, Absolute and Relative Paths in POSIX Shell
# Prepare
mkdir -p "${HOME}/path without/symlinks"; ln -s "${HOME}/path without" "${HOME}/path with"
TESTPATH="${HOME}/..///${USER}/path with/symlinks///"; echo "${TESTPATH}"
echo "Absolute path: '$(realpath -m ${TESTPATH})'"
echo "Canonical path: '$(realpath -s -m ${TESTPATH})'"
echo "Relative to '/usr/bin': '$(realpath -s -m --relative-to="/usr/bin" ${TESTPATH})'"
echo "Canonical relative to '/usr/bin': '$(realpath -m --relative-to="/usr/bin" ${TESTPATH})'"
echo "Relative with base '/usr/bin': '$(realpath -s -m --relative-base="/usr/bin" ${TESTPATH})'"
@biiont
biiont / ping_with_mtu.sh
Created October 1, 2015 08:20
Determining MTU With Ping
# This script allows to determine MaxTranssmitUnit size for current network.
#
# Argument "-M" selects Path MTU Discovery strategy: - "do" means prohibit
# fragmentation, even local one; - "want" do PMTU discovery, fragment locally
# when packet size is large; - "dont" do not set DF flag.
#
# Argument "-s" specifies payload size. Value 1472 produces frames of 1500 bytes.
# And value 1473 is for frames 1501 byte which is more than usual MTU.
#
# Arguments "-c 3 -A" are used to send 3 packets as fast as possible (adaptive ping).
@biiont
biiont / manipulate_rc.d_scripts.sh
Last active October 1, 2015 08:27
List, enable and disable rc.d scripts
# Here prefx "S" means start, and "K" means stop/kill.
# Two digits after mean order of start and kill operations.
# I have not found any standard defining this order,
# but orders above 90 usually are user scripts.
# List installed runlevels
ls /etc/rc.d/rc?.d/*someservice
# Remove from any runlevels
rm /etc/rc.d/rc?.d/*someservice
@biiont
biiont / tomatousb-button_toggle_vpnclient.sh
Created September 28, 2015 22:04
Script to toggle vpnclient by pressing WPS button on Tomato/Shibby based router (put this to "Custom script" field at "Administration>Buttons/LED" page).
[ $(pidof vpnclient1; echo $?) -ne 0 ] && service vpnclient1 start || service vpnclient1 stop
#[ $1 -le 2 ] && telnetd #...
@biiont
biiont / vim.tiny-rc
Created September 12, 2015 04:27
Fix cursor movement and backspace in insert mode for vim.tiny.
" Fix cursor movement and backspace in insert mode for vim.tiny.
set nocompatible
set backspace=indent,eol,start
@biiont
biiont / gist:8e069824a4d71ddf8ca0
Created August 29, 2015 13:23
Check latency of Hurricane Electric IPv6 Tunnel Servers
#!/bin/sh
IPS="216.218.221.6:216.218.221.42:74.82.46.6:216.66.84.46:216.66.86.114:216.66.87.14:216.66.80.30:216.66.88.98:216.66.84.42:216.66.86.122:216.66.80.90:216.66.80.162:216.66.80.98:216.66.22.2:184.105.253.14:184.105.253.10:184.105.250.46:72.52.104.74:64.62.134.130:216.66.77.230:209.51.161.58:209.51.161.14:66.220.7.82:216.218.226.238:216.66.38.58:184.105.255.26"
#IPS="216.218.221.6"
IT="${IPS}:"
while [ -n "$IT" ]
do
VAL="${IT%%:*}"
RES=$(ping -q -n -c 9 "${VAL}" | grep -e 'rtt' | cut -d ' ' -f 4)
@biiont
biiont / iterate_shell_array.sh
Last active February 7, 2023 18:00 — forked from anonymous/iterate_shell_array.sh
Iterate over an array using POSIX Shell
#!/bin/sh
# Iterate over an array using POSIX Shell
# Initial data
ARR="a:b:c:d"
# Iteration. Do whatever is needed instead of 'echo "$VAL"'.
CDR="${ARR}:"; while [ -n "$CDR" ]; do CAR=${CDR%%:*}; echo "$CAR"; CDR=${CDR#*:}; done; unset CAR CDR
# IMPORTANT!!! Add semicolon to the end of an array (IT="${ARR}:") to make stop condition working.