Skip to content

Instantly share code, notes, and snippets.

@a1ip
Last active December 24, 2022 16:02
Show Gist options
  • Save a1ip/acc83b7d4e5faa55b432 to your computer and use it in GitHub Desktop.
Save a1ip/acc83b7d4e5faa55b432 to your computer and use it in GitHub Desktop.
Useful Mac OS X terminal one-liners in fish shell.
  1. Get your external IP:
    curl -s ipecho.net/plain
  2. Get your internal IP:
    ipconfig getifaddr en0
  3. Test http with netcat:
    echo -e "HTTP/1.1 200 OK\nContent-Type: text/html\n\n Jesus Christ is my Lord!" | nc -vv -l 8080
  4. Extract SVG from the 30's page of PDF file using Poppler:
    pdftocairo -f 30 -l 30 -svg  book.pdf  30.svg
  5. Extract files from archive.zip with filenames in Russian:
    unzip -O cp866 archive.zip
  6. Make JSON array from list of all *.txt filenames in current directory:
    ls *.txt|jq -R -s -c 'split("\n")' > list.json
  7. Print out all Russian Bible book names with their numbers:
    http jbbl.github.io/rst/index.json|fx ".books.reduce((a,b) =>a+`\n`+b.nr+`: `+b.name,``)"|column
  8. Print out John 1:1 from Greek Textus Receptus:
    http jbbl.github.io/tr.json|fx .books[4-1].chapters[1-1].verses[1-1] "`«`+this.text+`» (`+this.name+`)`"
  9. Print out Ps.83:3 in RST translation:
    http jbbl.github.io/rst/ps/83.json|fx .verses[3-1] "`«`+this.text+`» (`+this.name+`)`"
  10. Copy Ps.83:3 in RST translation into the clipboard buffer:
    http jbbl.github.io/rst/ps/83.json|fx .verses[3-1] "`«`+this.text+`» (`+this.name+`)`"|pbcopy
  11. Print out whole chapter 1 of book of Psalms in KJV translation:
    http jbbl.github.io/kjv/ps/1.json|fx ".verses.reduce((a,b) =>a+`\n`+b.verse+`. `+b.text,this.name)"
  12. List of *.txt filenames from current directory saved in JSON array:
    ls *.txt|jq -R -s -c 'split("\n")' > ./list.json
  13. List only subdirectories of current directory (files not included):
    ls -d */
  14. Executes ls -l with all *.md files from ~/dev directory:
    find ~/dev -iname \*.md -exec ls -l \{\} +
  15. Finding *.md files excluding node_modules directories from search path:
    find ~/dev -iname \*.md -not -path \*node_modules\* 2>/dev/null
  16. To keep my mac software updated with homebrew, homebrew-cask-upgrade and mas:
    brew update;brew upgrade;brew cu --all --yes --cleanup;mas upgrade;brew cleanup;brew bundle dump --force --describe --file=~/Brewfile
  17. To set hostname to myMac.myDomain.ru:
    sudo scutil --set HostName myMac.myDomain.ru
  18. Full year calendar for 2020 and 2021 side by side (fish analog of bash's paste <(cal 2020) <(cal 2021)):
    paste (cal 2020|psub) (cal 2021|psub)
  19. Chars frequency in Psalm 90:
    http jbbl.github.io/rst/ps/90.json|fx ".verses.reduce((a,b) =>a+b.text+`\n`,``)"|grep -o '.'|tr А-Я а-я|sort|uniq -c|sort -rn
  20. Glueing 6 tile images together vertically using ImageMagick:
    montage  *.jpg  -tile 1x6  -geometry +0+0  imagelist.jpg
  21. Adding transparent padding to an image using ImageMagick:
    convert withoutpadding.jpg -resize 1200x630 -gravity center -background none -extent 1200x630 withpadding.jpg
  22. Mirroring an image using ImageMagick:
    convert -flop input.png output.png
  23. Viewing picture.png image with 60 columns width using imgcat:
    imgcat --width=60 picture.png
  24. Saving current weather report to the weather.png file with transparency using wttr.in API:
    http -do weather.png wttr.in/Новороссийск,Видова,58_lang=ru_format=v2_t_F.png
  25. Making screenshot with current weather using webkit2png:
    webkit2png -F -z 2.0 -W 608 --delay=2 -o wttrNovorossEn 'https://wttr.in/Novorossiysk,Vidova,58?lang=en&format=v2&F'
  26. Get forms of Russian word Иисус:
    http https://ws3.morpher.ru/russian/declension\?format=json\&s=Иисус
  27. Merge some pdf files into one merged.pdf file:
    gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf file1.pdf file2.pdf
  28. Delete second page from in.pdf file and put result in out.pdf with pdftk server:
    pdftk in.pdf cat 1 3-end output out.pdf
    Note that last version of pdftk server for Mac are not listed on the official web site!!!
  29. Cropping short.mp3 file with 3 min 16 sec duration from 44 min 44 sec of long.mp3 file:
    ffmpeg -i long.mp3 -ss 00:44:44 -t 00:03:16 short.mp3
  30. Convert high bitrate MP3 to 92k bitrate using FFmpeg:
    ffmpeg -i input.mp3 -codec:a libmp3lame -b:a 92k output.mp3
  31. Extracting screenshot for video.mkv with ffmpeg at a given time (3m16s):
    ffmpeg -ss 00:03:16 -i video.mkv -vframes 1 -q:v 2 screenshot.jpg
  32. Detect and extract slides in video.mkv with slide-detector.py script by Daniel Perelman:
    ./slide-detector.py video.mkv
  33. Print out banner Христос воскресе! with figlet:
    figlet -C utf8 -f banner Христос воскресе!
  34. Run local static web server on port 8000 with Python version 3.X:
    python -m http.server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment