23 February 2026

How to shrink file size of a pdf file?

sudo apt update
sudo apt install ghostscript

The Compression Command
Use the following command to compress the PDF to a "screen" quality, which is usually sufficient for viewing on monitors or emailing and will easily bring a 3MB file below 2MB:
bash
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
  • input.pdf: Replace with your original file name.
  • output.pdf: The name of the new compressed file.
Alternative: Better Quality (eBook)
If the /screen setting makes the text look too blurry, try /ebook (150 dpi), which balances good quality with a smaller file size:
bash
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Other Options
  • -dPDFSETTINGS=/screen: 72 dpi, lowest quality, smallest size (best for >2MB requirement).
  • -dPDFSETTINGS=/ebook: 150 dpi, medium quality, better for reading.
  • -dPDFSETTINGS=/printer: 300 dpi, high quality, likely to keep the file over 2MB.
Note: If the PDF contains text only, the file size reduction may be limited.


Knowing port number, how to kill a process which is using that port?

  • Find what's sitting on the port:  

    $ sudo lsof -i :8000 (Replace 8000 with your port)

  • Kill that specific listener:  

    $ sudo kill -9 <PID_FROM_LSOF>


If I am running -

$ gunicorn --bind 0.0.0.0:8000 app:app
[2026-02-23 10:38:25 -0500] [250191] [INFO] Starting gunicorn 25.1.0
[2026-02-23 10:38:25 -0500] [250191] [INFO] Listening at: http://0.0.0.0:8000 (250191)
[2026-02-23 10:38:25 -0500] [250191] [INFO] Using worker: sync
[2026-02-23 10:38:25 -0500] [250191] [INFO] Control socket listening at /home/shermanchen/dev/convShop2/gunicorn.ctl
[2026-02-23 10:38:25 -0500] [250193] [INFO] Booting worker with pid: 250193

 

When I run lsof, I get -

$ sudo lsof -i :8000                           
COMMAND     PID        USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME                            
gunicorn 250191 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN)                 
gunicorn 250193 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN) 

 

If I kill the 'booting worker' pid 250193, the gunicorn will not be killed.  I have to kill the 'listening' pid 250191, to kill the gunicorn process.

$ sudo kill -9 250191

  

If I use ps, I got

$ ps aux | grep gunicorn                       
sherman+  250690  0.0  0.0   9824  2172 pts/1    S+   10:45   0:00 grep --color=auto gunicorn 
 

Killing pid 250690 will not kill the gunicorn process.

Flask Tutorial - Build a Flask Python Web App from Scratch

https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3

 

 

18 February 2026

How to sort by time the result of the $ find command?

$ find . -iname "applied*" -type f -printf '%T+ %p\n' | sort -r

 

$ find . -iname "applied*" -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r 

11 February 2026

In vim, how to make the first letter of every word into uppercase?

https://dev.to/gokayburuc/vim-regex-tricks-capitalize-every-first-letter-526j

To capitalize the first letter of each word in a sentence, use the following Vim command:

:s/\<\w/\u&/g

Explanation of the Command

  • :s/ starts the substitution command in Vim, which is used to find a pattern and replace it with a specified value.
  • \< matches the beginning of a word. In Vim, a word is defined as a sequence of letters, digits, or underscores.
  • \w matches any word character (letters, digits, or underscores).
  • \u is a replacement flag in Vim that converts the next character in the replacement string to uppercase.
  • & represents the entire matched text from the search pattern (in this case, the first character of each word).
  • /g applies the substitution globally, ensuring every matching occurrence in the line is processed rather than just the first one.

By running this command, Vim will capitalize the first letter of each word in the specified text.