Skip to content

Instantly share code, notes, and snippets.

@ohjho
ohjho / imagemagick_cheatsheet.md
Last active February 23, 2024 16:28
imagemagick cheatsheet

Replace a color with transparency

for example, to convert white to transparent

convert target.png -transparent white result.png

if not perfectly white:

convert target.png -fuzz {}% -transparent white result.png

where the smaller the fuzz %, the closer to true white or conversely, the larger the %, the more variation from white is allowed to become transparent.

@ohjho
ohjho / build_pytorch_from_source.md
Last active May 21, 2023 10:20
Build PyTorch from Master/ Source using VirtualEnv

Building PyTorch from Master/ Source using VirtualEnv

with reference to this

make sure that you have cloned the PyTorch repo. Let's assume that we'll install into ~/git/

$ cd ~/git
$ git clone --recursive https://github.com/pytorch/pytorch.git

activate your Python3 virtualenv and install PyTorch requirements

@ohjho
ohjho / Python+VirtualEnvs.md
Last active March 27, 2024 17:48
Python Versions + Virtual Environments Tips and Tricks

PIP

installing from Git Repo

in general the command is as follows but see this blog post for the most detailed explanation:

pip install git+https://github.com/user/repositor.git@branch#subdirectory=src
  • note that the @branch is completely optional
  • also #subdirectory=src is also optional (sometimes the project to install is not in the root of the repo, e.g. Streamlit)
  • either options like --ignore-requires-python might be useful if you think the python version requirement is not neccessary
@ohjho
ohjho / bash_cheatsheet.md
Last active January 19, 2024 22:31
text file handling edition

Find Differences in two Text Files

grep -Fxvf file1 file2

Flags mean:

-F, --fixed-strings
              Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.    
-x, --line-regexp

Installation

MacOS

Get FFMPEG with all the options which is a little more complicated in brew because the Homebrew team removed all options from the core formula:

brew update
brew uninstall --force --ignore-dependencies ffmpeg
brew install chromaprint amiaopensource/amiaos/decklinksdk
brew tap homebrew-ffmpeg/ffmpeg
brew upgrade homebrew-ffmpeg/ffmpeg/ffmpeg $(brew options homebrew-ffmpeg/ffmpeg/ffmpeg | grep -vE '\s' | grep -- '--with-' | grep -vi chromaprint | tr '\n' ' ')
@ohjho
ohjho / grep_string_in_dir.sh
Last active October 15, 2019 03:32
use grep to search for files containing a given string
grep -R --exclude-dir=node_modules 'some pattern' /path/to/search
grep -R --exclude-dir={node_modules,.git} 'some pattern' /path/to/search
@ohjho
ohjho / imgmagick_batch_resize
Created April 23, 2019 02:50
imgmagick resize batch sub directory (replace . with your dir path)
find . -type f -iname "*.jpg" -exec identify -format '%w %h %i\n' {} \; |
awk '$1 > 1200 || $2 > 1200 {sub(/^[^ ]* [^ ]* /, ""); print}' |
tr '\n' '\0' |
xargs -0 mogrify -resize '1200x1200'
@ohjho
ohjho / imaginemagick_crop.sh
Created March 29, 2019 00:52
how to crop an image with imaginemagick: -crop {w}x{h}+{x}+{y}
convert foo.png -crop 640x480+50+100 out.png
@ohjho
ohjho / imaginemagick_color_convert.sh
Last active March 6, 2019 04:29
-fill is the new color and -opaque is the old color; you can use https://imagecolorpicker.com/ to identify the color in the image
convert original.jpg -fuzz 15% -fill "#84BE6A" -opaque "#d89060" new.jpg
@ohjho
ohjho / git_blob_obj.sh
Last active December 11, 2018 07:10
shell script to show all blob objects in your git repo sorted from smallest to largest. For mac users, please comment out the last line. To run, place this in your git directory and run `sh git_blob_obj.sh`
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest