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: https://stackoverflow.com/a/59900177/452467
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