repo to keep track of random scripts
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.MD
bkp
caitlin_pep_talk.sh
color and fill scale for ggplot2.txt
combine_videos.sh
configure_email.md
convert_htm_to_mobi.sh
convert_md_to_html.md
creativity_exercise.py
crop.go
crop_video.py
eda.R
encode
exploratory_data_analysis.Rmd
find_largest_transcripts_oasis.py
git_reminders.md
guide_to_permutations_and_bootstrapping_in_r.Rmd
guide_to_permutations_and_bootstrapping_in_r.html
intro_to_docker.md
invert.go
k_means_color.py
k_means_video.py
learning_pandas.md
lsmeans_tutorial.Rmd
mary_shuttlebox.sh
md2pdf
mod_time.py
nyt.py
opencv_inside_docker.md
overlay_boxes.py
pairwise_correlations.Rmd
permutations_functions.R
plotting_functions.R
practice.R
r_tutorials.R
reading_level
remark_boilerplate.html
rhymer.py
san_fran.R
scheduling_chron_jobs.md
send_python_tip.py
send_text.py
send_text_bandwidth.py
sm
split_channels.py
time_track_analysis.R
txt
unix_tips_and_tricks.md
video_recorder.go
video_to_gif.sh
web_visit.py

README.MD

random_scripts

I'm using this repo to keep track of random scripts I write.

crop.go

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

where:

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 parallel or find work fine. Saves the cropped photo in the same directory of the photo: photo.1.jpg becomes photo.1_cropped.jpg.

invert.go

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 out.png.

nyt.py

Opens the leading three stories from the nytimes page in your browser.

Run like: python3 nyt.py or ./nyt.py

opencv_inside_docker.md

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.

bkp

Shell script I use to create compressed archive files for backing up. Used like bkp /path/to/folder_to_backup destination/. Uses bzip2.

reading_level

Shell script that uses pandoc, ucto, and readability to calculate readability statistics from a docx or md file. Used like reading_level some_file.docx

md2pdf

Shell script that converts markdown files to a pdf using pandoc. Used like md2pdf some_text.md. Creates some_text.pdf @ ~/Desktop/.

plotting_functions.R

A ggplot2 theme I like + some color scales.

convert_htm_to_mobi.sh

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.

crop_video.py

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

encode

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.

useage: encode /path/to/video

video_to_gif.sh

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

video_to_gif /path/to/video.

k_means_video.py

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.

unix_tips_and_tricks.md

A work in progress.

mod_time.py

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.

overlay_boxes.py

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.

Run like: python overlay_boxes.py -i /path/to/video.mp4 -b boxes.csv