Skip to content

Instantly share code, notes, and snippets.

View catichenor's full-sized avatar

Christopher Tichenor catichenor

View GitHub Profile
@catichenor
catichenor / fix_step_list.py
Created August 13, 2018 23:09
Takes in a list of strings containing numerically ordered lists and fixes their numbering
import re
step_list = ['1. Pour\n2. Lather\n2. Rinse\n3. Repeat', # Note two step 2's.
'1. Start filling with water\n1. Open Lid\n1. Load\n2. Add detergent\n3. Add fabric softener\n4. Add clothes\n5. Close lid', # Note 3 step 1's
'1. Put toothpaste on brush\n2. Rub toothbrush on all teeth for two minutes, spit as necessary\n3. Rinse mouth\n4. Floss\n5. Swish mouthwash in mouth for 30 seconds\n6. Gargle, spit']
new_step_list = []
for row in step_list:
if re.match(r'^\d+\. ', row):
@catichenor
catichenor / getzipdate.sh
Created August 3, 2018 16:44
Get the modification date of files inside zip archives in the current directory
#!/bin/bash
for f in `find -maxdepth 1 . -type f -name '*.zip'`; do
datetime=`date -j -f "%y-%b-%d %H:%M" "$(zipinfo $f | head -n 3 | tail -n 1 | awk '{print $7 " " $8}')" +"%Y%m%d%H%M"`;
echo "$f $datetime"
# To rename, appending the date instead: mv $i `echo "$i" | sed -e "s/\(.*\)\(\..*\)/\1_${datetime}\2/"`;
done
@catichenor
catichenor / collect_dict_paths.py
Last active August 6, 2018 20:08
Collect dictionary paths and values
test_info = {
'old_macs': {
'processors': [
{'68000': [
{'name': 'Mac 128k', 'color': False},
{'name': 'Mac 512k', 'color': False},
{'name': 'Mac Plus', 'color': False},
{'name': 'Mac SE', 'color': False},
]},
{'68020': [
@catichenor
catichenor / calendar_to_markdown.py
Created July 17, 2018 00:38
Apple Calendar Meetings to Markdown
# To pass in the correct input, you need to use Automator on macOS.
# First, add in the "Find Calendar Events" Action and set it to find events where "Date starting" "is today".
# Then, pass that to the "Event Summary" Action.
# Finally, add a "Run Shell Script" Action and paste the following into it.
import sys
import re
cal_array = []
@catichenor
catichenor / weekly_report.py
Last active July 14, 2018 00:17
Generate a Markdown-formatted Weekly Report Template via Jinja2
from jinja2 import Template
from datetime import datetime, timedelta
today = datetime.now()
date_today = datetime(today.year, today.month, today.day)
day_of_the_week = date_today.weekday()
date_start_delta = timedelta(-(date_today.weekday()))
date_start = date_today + date_start_delta # Result should be Monday of this week.
date_end_delta = timedelta(4)
date_end = date_start + date_end_delta # Result should be Friday of this week.
@catichenor
catichenor / calculate_timesheet.py
Last active July 3, 2018 19:54
Take in a GitHub-Flavored-Markdown time tracking list and output total times
import sys
import re
from collections import defaultdict
# Script takes in a GitHub-Flavored-Markdown table assuming the following format:
#
# Start | Stop | Task
# ----- | ---- | ----
# 9:20 | 9:40 | Email/Admin
# 9:40 | 11:30 | Automation
@catichenor
catichenor / parallel_rm.sh
Last active July 3, 2018 18:57
Remove files in parallel
# Find a sequence of files and remove them in parallel with xargs. Helpful for FUSE-based object stores attached to VMs.
find . -type f -name "file*.png" | xargs rm -n 1 -P 8
@catichenor
catichenor / copy_filelist_to_gcs.sh
Created February 20, 2018 21:50
Copy a large list of sequential files to GCS
for i in `seq -f '%06g' 1 10`; do echo "/path/to/file.${i}.png"; done | xargs > ./filelist.txt
# ^Generate a space-delimited list of filenames and output it to `filelist.txt`.
# Contents of `filelist.txt`:
# /path/to/file.000001.png /path/to/file.000002.png /path/to/file.000003.png /path/to/file.000004.png /path/to/file.000005.png /path/to/file.000006.png /path/to/file.000007.png /path/to/file.000008.png /path/to/file.000009.png /path/to/file.000010.png
gsutil cp -m `cat ./filelist.txt` gs://png-bucket/path/to/receptacle/
# ^Read the list of files as an argument to gsutil and use multithreaded copy to copy to the bucket.
@catichenor
catichenor / frame_range_calc.py
Last active February 21, 2018 06:06
Frame range calculator
# This is my frame range calculator. There are many like it, but this one is mine.
# Python 2 and 3 compatible. The division method becomes less optimal as the number increases, but
# it works for the use case of relatively small numbers of divisions (up to a few dozen).
import math
import argparse
argparser = argparse.ArgumentParser()
@catichenor
catichenor / is_vs_equals.py
Created February 2, 2018 23:33
Demonstration of the difference between "is" and "==" in Python
test = 'hello'
print(test[:-1] == 'hell')
# returns "True"
print(test[:-1] is 'hell')
# returns "False", these do not point to the same object in memory.