Skip to content

Instantly share code, notes, and snippets.

View jdunic's full-sized avatar

Jillian Dunic jdunic

  • Simon Fraser University
  • Burnaby
View GitHub Profile
#!/usr/bin/env python
# This top line tells the computer that your script is an executable
# Let's save this file as xxxxx_cleanup.py
# Today we have a datafile in csv (comma separated values) format which is not
# clean. There are inconsistencies in text formats,
# Base python comes with a lot of capabilities, but just like in R, we have to
# import different packages or "modules" in python to allow us to do more. We
@jdunic
jdunic / header_date_cleanup.py
Last active January 28, 2016 03:22
Changing date format of csv headers.
# From a list of bad dates:
import csv
from datetime import datetime
input_file = "bad_dates.csv"
output_file = "good_dates.csv"
with open(output_file, 'wb') as open_file:
writer = csv.writer(open_file, dialect='excel')
with open(input_file, 'rU') as csvfile:
reader = csv.DictReader(csvfile)
import os
import glob
import csv
import itertools
from os.path import basename
from collections import OrderedDict
from datetime import datetime
#
#!/usr/bin/python
"""GPX_to_csv_waypoints.py: Exporting waypoints in GPX file to a csv file"""
# Author: Jillian Dunic
# Date created: 2014-08-13
#-------------
# Change log #
@jdunic
jdunic / init.lua
Last active January 13, 2021 01:42
hammerspoon config file
-- Basis of most of this taken from: https://github.com/miromannino/miro-windows-management
local mash = {"cmd", "ctrl"}
local mash2 = {"ctrl", "alt"}
local toggle = false
local VOLUME_INC = 10
local sizes = {1, 3, 2, 3/2}
local fullScreenSizes = {1, 4/3, 2}
@jdunic
jdunic / dms2dec.R
Last active January 12, 2022 23:10
convert character dms to decimal degrees
# Good discussion on str_extract/str_match and positive look behind
# https://stackoverflow.com/questions/35804379/stringr-str-extract-how-to-do-positive-lookbehind
dms2dec <- function(string) {
string <-
str_squish(string) %>%
str_replace_all(., "\\s", "")
values <- str_match(string, "(\\d*)[\\u00B0|˚]\\s?(\\d*\\.?\\d*?)('|′|’)\\s?(\\d*?\\.?\\d*?)[\"|″]?\\s?(N|n|E|e|S|s|W|w)")
original <- values[, 1]
data(major, package = "PBSdata")
data(pmfc, package = "PBSdata")
pmfc_sf <- as_tibble(major) |>
st_as_sf(coords = c("X", "Y"), crs = "WGS84") |>
group_by(PID) |>
summarise(geometry = st_combine(geometry)) |>
st_cast("POLYGON") |>
left_join(pmfc, by = c("PID" = "major")) |>
tidyr::separate(name, into = c("code", "name"), sep = ": ")