2024-09-12 How to translate text from clipboard buffer
using translate-shell
. Install
it, then run a command:
pbpaste | trans -b -no-autocorrect -target en
2024-08-21 How to download subtitles for a Youtube video:
yt-dlp --skip-download --write-auto-subs --convert-subs srt https://youtube-url-here
2024-08-14 ffprobe
is like
identify
command, but for for video files - it shows video
resolution, video and audio codecs, duration and lots of other info:
ffprobe The.Holy.Mountain.1973.REMASTERED.720p.BluRay.999MB.HQ.x265.10bit-GalaxyRG.mkv 2>&1 | grep -Ei '(duration|stream.*video):'
Duration: 01:53:35.58, start: 0.000000, bitrate: 1213 kb/s
Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv), 1280x544 [SAR 408:409 DAR 960:409], 23.98 fps, 23.98 tbr, 1k tbn (default)
2024-08-07 How to mount Tailscale drive on Linux:
sudo apt-get install -y davfs2
mkdir ~/ts-drive
# replace mydomain.com/mylaptop/docs with your-tailnet/your-host/drive-name:
sudo mount.davfs http://100.100.100.100:8080/mydomain.com/mylaptop/docs ~/ts-drive -o uid=$(id -u),gid=$(id -g),noexec,nosui
2024-07-05 aggregate: a command to join adjacent network prefixes into a single one. For example how to shorten the Github Actions IPv4 subnets list:
> curl -sSf https://api.github.com/meta | jq -r .actions[] | grep -v :: | wc -l
3738
> curl -sSf https://api.github.com/meta | jq -r .actions[] | grep -v :: | aggregate -q | wc -l
2499
2024-06-03 In Tailscale, a node can advertise custom routes, so you can route the traffic to the particular subnets via this node without using it as an exit node. In this example I route all Google subnets, because I want to access Youtube Premium from an unsupported country:
tailscale up --advertise-routes "$(curl https://www.gstatic.com/ipranges/goog.json | jq -r .prefixes[].ipv4Prefix | grep -v null | grep -Ev '^8\.8\.' | tr "\n" "," | sed 's/,$//')"
2024-03-05 How to tail logs from multiple pods/containers/apps in a K8s namespace:
kubectl -n MY_NS logs -f --max-log-requests 20 --tail 0 -l 'app in (app1,app2,...)' --all-containers
2024-01-31 Dump Memcached keys with
memcdump
(install libmemcached-tools
package
on Ubuntu and libmemcached
on RedHat-based systems):
memcdump --server=127.0.0.1:11211
2023-12-28 How to find where are executable files are
located after gem install ...
:
gem environment | grep 'EXECUTABLE DIRECTORY'
2023-12-13 How to set remote IP in Nginx log to
X-Real-IP
header if the request is proxied via
Cloudflare:
( echo "real_ip_header CF-Connecting-IP;"; for URL in https://www.cloudflare.com/ips-v{4,6}/; do curl -sSf | sed -E 's/^(.*)$/set_real_ip_from \1;/' ; echo ; done ) | tee /etc/nginx/conf.d/cloudflare.conf
then restart or reload Nginx.
2023-11-28 How to find a process listening a port
without netstat
or ss
(source):
fuser 7000/tcp
2023-11-13 uBlock Origin rule to hide Instagram suggested users:
www.instagram.com##button>span:has-text(/Switch/):nth-ancestor(10)
2023-10-27 How to change the limits for a running process (source):
prlimit --pid 55555 --nofile=1000000:1000000
# make sure the limits have changed:
grep 'Max open files' /proc/55555/limits
2023-10-23 Remove shell color/ANSI codes from text (source):
sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"
2023-10-17 How to check a ZIP file integrity:
zip -T file.zip
# or:
unzip -t file.zip
2023-09-19 How to run a command on Mac wakeup (I use it
to reconnect to my VPN). Source. First, you need
to install Sleepwatcher via Homebrew, and run it as a service, then
create shell script named ~/.wakeup
, which will be execute
on wakeup:
brew install sleepwatcher
brew services start sleepwatcher
brew services | grep sleepwatcher # to make sure the service is running
# now create ~/.wakeup as you usually create shell scripts, starting with #!/bin/bash
chmod +x create ~/.wakeup # make sure it's executable
# to test it, put your Mac to sleep:
pmset sleepnow
# then wake it up and see if your script was executed
2023-09-12 How to trace network calls for a process and all it’s forks/children:
strace -f -e trace=network -s 10000 -p $(pgrep -f PROCESS_NAME -d,)
2023-09-07 How to print SSH options for a particular host after evaluating config files (SSH dry run, of sorts), source:
ssh -G hostname
2023-08-25 List files in Alpine APK package (source):
apk info -L libc6-compat
2023-08-22 To change default time format from AM/PM to
24h on Ubuntu, save the following line in your .bashrc
or
.bash_profile
:
export LC_TIME="C.UTF-8"
2023-08-22 How to make UFW start on system boot (tested on Ubuntu 20.04, source):
sed -i '/^Before=.*/a After=netfilter-persistent.service' /lib/systemd/system/ufw.service
# reboot, then make sure UFW is enabled:
ufw status
Status: active
2023-07-19 Command to show Consul cluster members health:
consul operator autopilot state
2023-06-06 Git command to checkout previous branch - use
dash as a branch name, like in cd
command:
git checkout -
2023-05-29 A command to extract images from EPUB file:
unzip mybook.epub *.jpg *.jpeg *.png *.gif
2023-05-16 How to show details about processes - children of a specific process:
pgrep -P 1 -f myprocess | xargs ps -f -p
2023-05-10 TIL about tmutil status
and made
a tiny command line tool to show Time Machine backup progress: https://gist.github.com/haron/58a156d83527bbe1e450aedc7b5c0642
2023-04-28 Percent sign should be escaped in a crontab file (source), for example:
* * * * * date +%Y-%m-%d # won't work as expected
* * * * * date +\%Y-\%m-\%d # will work as expected
* * * * * date -I # will work even better
2023-04-20 How to remove image background using open-source rembg tool:
# python 3.8, 3.9 or 3.10 is required
pip install rembg
rembg i input.jpg output.png
2023-04-20 Command sort -V
will sort
version numbers:
> printf '1.0.11\n1.0.9' | sort -V
1.0.9
1.0.11
2023-03-31 How to remove K8s PersistentVolume, when the
removing process got stuck in a Terminating
state (source):
kubectl edit pv PV_NAME
### remove the following block:
# finalizers:
# - kubernetes.io/pv-protection
# then remove the volume:
kubectl delete pv PV_NAME --grace-period=0 --force
2023-03-28 How to fix sudo
on my Mac after
messing up /etc/pam.d/sudo
config file: copy the file to
your home directory, edit it, then copy it back with Finder (source).
2023-03-23 Command envsubst
replaces
references to environment variables with their values. Example:
printf 'some\n/Users/haron\ntext\n' | envsubst
2023-03-23 How to remove a node from Consul when even
force-leave
doesn’t help (source):
curl -XPUT -d '{"Node":"NODE_NAME"}' http://NODE_IP:8500/v1/catalog/deregister
2023-03-10 Orphaned uWSGI worker processes may consume
100% CPU per worker, unless you remove --master
option. Github
issue.
2023-03-09 HTML <input>
element
validation pattern: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern
2023-02-12 Supervisord has its own setting to set process’ max open files limit (thanks to this post, now I know it too):
[supervisord]
...
minfds=100000;
To see limits for a running process, show should get its PID and see
/proc/PID/limits
:
# supervisorctl status
my_process RUNNING pid 23754, uptime 0:08:18
# grep 'open files' /proc/23754/limits
Max open files 100000 100000 files
2023-02-09 High quality thumbnails in Python using Pillow library:
from PIL import Image, ImageEnhance
im = Image.open("img.jpg")
im.thumbnail((600, 600)) # max thumbnail size in pixels
enhancer = ImageEnhance.Sharpness(im)
im = enhancer.enhance(2.0)
im.save("tn.jpg", "JPEG", quality="web_medium")
2023-02-09 How to install dig
on Alpine
Linux:
apk add bind-tools
2023-02-08 How to install telnet
on Alpine
linux:
apk add busybox-extras
2023-02-08 How to get Consul cluster leader:
curl localhost:8500/v1/status/leader