Skip to content

Instantly share code, notes, and snippets.

View jmcurran's full-sized avatar

James Curran jmcurran

View GitHub Profile
@jmcurran
jmcurran / cleanCamUploads.py
Last active May 19, 2021 01:16
A Python Script for tidying up Dropbox's Camera Uploads Folder
import shutil
import os
import re
source = '/Users/jcur002/Dropbox/Camera Uploads/'
files = os.listdir(source)
pat = re.compile(r'^(?P<year>20(0[1-2]|1[2-9]|2[0-1]))\-(?P<month>0[1-9]|1[0-2])\-(?P<day>[0][1-9]|[12][0-9]|3[01])[ -](?P<timestamp>.*)\.(?P<extn>gif|png|jpe*g|mts|mp4|mov)$', re.IGNORECASE)
@jmcurran
jmcurran / tidyScreenshots.py
Last active May 19, 2021 01:17
Python Code for Automatically Renaming and Filing Screenshots on the Mac
import os
import re
root = '/Users/jcur002/Dropbox/Screenshots'
Files = os.listdir(root)
pat1 = re.compile('Screenshot (?P<year>[0-9]{4})\-(?P<month>[0-9]{2})\-(?P<day>[0-9]{2}) (?P<hh>[0-9]{2})\.(?P<mm>[0-9]{2})\.(?P<ss>[0-9]{2})(\.png)?')
pat2 = re.compile('Screen Shot (?P<year>[0-9]{4})\-(?P<month>[0-9]{2})\-(?P<day>[0-9]{2}) at (?P<hh>[0-9]{1,2})\.(?P<mm>[0-9]{2})\.(?P<ss>[0-9]{2}) *(?P<am>AM|PM)*(\.png)?')
@jmcurran
jmcurran / matchParams.R
Created January 22, 2021 01:48
An R function for matching a parameter pattern with a list of possible parameters
# A function for matching a parameter pattern with a list of possible parameters
# matchParams("b0", c("b0", "b1", "b2", "sigma")) - should return 1
# matchParams("b.", c("b0", "b1", "b2", "sigma")) - should return 1 2 3
# matchParams("b[1-2]", c("b0", "b1", "b2", "sigma")) - should return 2 3
# matchParams(c("b0", "b1"), c("b0", "b1", "b2", "sigma")) - should return 1 2
# matchParams(c("b0", "b1", "b4"), c("b0", "b1", "b2", "sigma")) - should fail because b4 doesn't match
# matchParams(c("b0", "b."), c("b0", "b1", "b2", "sigma")) - should return 1 2 3 not 1 1 2 3 as it looks for unique matches
matchParams = function(params, paramList){
@jmcurran
jmcurran / progressbar.py
Last active August 5, 2018 03:52
A Python class for creating a text progress bar
# -*- coding: utf-8 -*-
import time #only for the example
"""
This class lets you create a text-based progress bar which updates
in place - i.e. it doesn't print to a newline.
early all of the code in the print method of this class (called
setProgressBar) comes from a stackoverflow post
(https://stackoverflow.com/a/34325723/3746992) from user Greenstick
(https://stackoverflow.com/users/2206251/greenstick).
@jmcurran
jmcurran / whalers.py
Created September 15, 2016 04:10
My first Python programme (of any merit)
import csv, re
def readHeightsFile(path):
heights = []
with open(path, "r", encoding = "utf-8", errors = "ignore") as csvFile:
f1 = csv.DictReader(csvFile)
for row in f1:
heights.append(row["Height"])
@jmcurran
jmcurran / DLMTest.csv
Last active August 26, 2016 03:40
Script for converting imperial height measurements (of humans) into millimetres
raw clean ft in mm
"5 5'0 5 0 1524
5' 5'0 5 0 1524
5'5 5'5 5 5 1651
5'7 1/2 5'7 1/2 5 7.5 1714.5
5'7 5'7 5 7 1701.8
5'8.5 5'8.5 5 8.5 1739.9
5'612 5'6 1/2 5 6.5 1689.1
6'0 1/2 6'0 1/2 6 0.5 1841.5
5'4 1/2 ? 5'4 1/2 ? 5 4.5 1638.3