I'm using this repo to keep track of random scripts I write.
Go script used to crop photos. Useful for cropping multiple photos in the same place. Used like:
crop -i /path/to/image.jpg -w 200 -h 200 -x 0 -h 0
w: width of cropped image
h: height of cropped image
x: x-coordinate in the original image to start with
y: y-coordinate in the original image to start with
i: input image to use
Not optimized for piping, but
find work fine. Saves the cropped photo in the same directory of the photo:
Go script used to invert png images. Once compiled with
go build invert.go, use like
invert -i input_image:
invert_image --help Usage of invert_image: -i string path to the image (default "test.png") -invert_color string do you only want invert non-grey pixels? default: yes (default "yes") -invert_grey string do you only want to invert grey pixels? default: yes (default "yes")
Creates a png in the current working directory named
Opens the leading three stories from the nytimes page in your browser.
python3 nyt.py or
Short notes on how to run opencv within a docker container. I've verified this works for some short scripts that use opencv. If the opencv build on your machine breaks, this is a good option to use instead.
Shell script I use to create compressed archive files for backing up. Used like
bkp /path/to/folder_to_backup destination/. Uses bzip2.
Shell script that uses pandoc, ucto, and readability to calculate readability statistics from a docx or md file. Used like
Shell script that converts markdown files to a pdf using pandoc. Used like
md2pdf some_text.md. Creates
A ggplot2 theme I like + some color scales.
I've been disappointed with the ability to download free, old books from project gutenberg and use them on my Kindle. When I download the books as .mobi files, I can't change the font style. When I download them as plain text documents, there's weird line spacing.
This script uses amazon's KindleGen command line tool to convert .htm books from the project gutenberg site to .mobi files that the Kindle can read. There are no funky spacing issues and you can choose whatever font you'd like.
The script is run like
bash -x convert_htm_to_mobi.sh /path/to/dir/with/htm/files/. It'll save the results .mobi files the directory containing the /htm files. The filenames of the htm files can't have spaces.
Opens the first frame of a video. The user draws a rectangle. The video is cropped to fit the rectangle with a subprocess call to ffmpeg. Run like
python crop_video.py /path/to/video
Script I use for encoding videos. I put it in
/usr/local/bin/ so that it can be executed no matter where you are in the machine. Makes an
encoded folder wherever the raw video is and saves the encoded video with the same name to that folder. It does not delete the old video.
Use to convert a video to a gif, which is more portable and is a fail-safe when embedding in powerpoint / keynote presentations. Requires that ffmpeg be installed on your machine. Use it like
Apply k-means clustering based on color to the frames of a video. Used like
python k_means_video.py -n input_video.mp4 -n 6 where
-n is the number of groups to use for clustering.
A work in progress.
Get the difference between when a file was created and when it was last modified. Useful when making sure videos are the length you think they are. Used like
python mod_time.py -i /path/to/dir.
Written for Kelly to overlap various boxes on a video.
This script take two inputs: a video and a csv file. The csv file contains the boundaries of different boxes to draw on the frames of each video. The csv file should have one column and four rows for each box. The first row contains the upper-left x coordinate of the box, the second the upper-left y coordinate, the third the lower-right x coordinate, and the fourth the lower-right y coordinate.
The script outputs one thing: a video identical to the input video but with the boxes overlaid. Saves as whatever the input name was appended with _overlaid_boxes. For example, video_a.mp4 will be saved as video_a_overlaid_boxes.mp4.
python overlay_boxes.py -i /path/to/video.mp4 -b boxes.csv