Skip to content

Instantly share code, notes, and snippets.

View NewGraphEnvironment's full-sized avatar

Allan Irvine NewGraphEnvironment

View GitHub Profile
@NewGraphEnvironment
NewGraphEnvironment / railway_pars.sql
Last active May 18, 2020 15:17
get details of railway crossing in PARS. Plagiarized from Simon Norris - https://gist.github.com/65c3db70eccfed9cf0d7f2bc10b3d058
-- modelled crossings
SELECT
pmc.pscis_model_combined_id,
x.crossing_id as model_crossing_id,
pmc.pscis_stream_crossing_id,
x.track_name,
x.track_classification,
x.use_type,
x.gauge,
x.status,
@NewGraphEnvironment
NewGraphEnvironment / list package depedencies
Last active January 30, 2023 21:33
list package depedencies in a project and spit out as a glued string to insert into packages.R file for loading with `pacman`
pack <- renv::dependencies() %>%
dplyr::distinct(Package) %>%
dplyr::pull(Package)
paste(shQuote(pack), collapse=", ")
@NewGraphEnvironment
NewGraphEnvironment / metadata_bcdata.R
Last active January 18, 2023 20:27
get metadata from bc data catolougue using bcdata. Column names, types and descriptions. Assumes `bcfishpass` virtenv is set up already
reticulate::use_condaenv('bcfishpass') %>%
base::system2(paste0("sh ",getwd(), "/scripts/test.sh"))
schema <- jsonlite::fromJSON('data/whse_fish.pscis_assessment_svw_metadata.json', flatten = T) %>%
purrr::pluck('schema') %>%
dplyr::mutate(column_name = stringr::str_to_lower(column_name))
#within test.sh (unhash second line) is
#!/bin/bash
#this is for make
for x in {1..20}; do make; done
@NewGraphEnvironment
NewGraphEnvironment / run_kill_pg_server.sh
Last active February 9, 2023 17:10
find and kill pg_featureserv and pg_tileserv running from `hohup`
#from https://stackoverflow.com/questions/17385794/how-to-get-the-process-id-to-kill-a-nohup-process#:~:text=When%20using%20nohup%20and%20you,you%20need%20to%20force%20kill).
# pg_tileserv
nohup ~/config/pg_tileserv >> pg_tileserv.log 2>&1 &
echo $! > pid_pg_tileserv.txt
#check output with
tail pg_tileserv.log
@NewGraphEnvironment
NewGraphEnvironment / sp_extract_coords.R
Last active November 6, 2023 15:57
Extract coordinates from `sf` spatial object and add to object as columns
# asssumes UTMs. Column nmaes would be `lat` `long` if in Albers or WSG84
#option 1 - retains the sf object
sf_object %>%
mutate(
easting = sf::st_coordinates(.)[,1],
northing = sf::st_coordinates(.)[,2])
# option 2 - this changes from sf object to a dbl_df - not usually helpful
sf_object %>%
@NewGraphEnvironment
NewGraphEnvironment / cmd_shft_period
Last active February 16, 2023 14:00
see dotfiles on mac
Command+Shift+Dot
@NewGraphEnvironment
NewGraphEnvironment / pg_common_queries.sh
Last active January 23, 2024 23:04
postgres common queries
#list column names of a table
select column_name
from information_schema.columns
where table_name = 'questionnaire'
and table_schema = 'fi';
## list the sizes of all schemas in a database
SELECT schema_name,
pg_size_pretty(sum(table_size)::bigint),
(sum(table_size) / pg_database_size(current_database())) * 100
@NewGraphEnvironment
NewGraphEnvironment / assume-unchanged-git.txt
Last active March 20, 2023 18:11
assume-unchanged git
#For now lets stop tracking the bcfishpass.sqlite changes in repo unless changes to underlying tables actually happen by running the script below
git update-index --assume-unchanged data/bcfishpass.sqlite. When changes actually occur we use git update-index --no-assume-unchanged data/bcfishpass.sqlite to log a commit
@NewGraphEnvironment
NewGraphEnvironment / regex_file.sh
Created April 7, 2023 15:15
regex to search for `.gpkg`
([^/\\]+)\.\gpkg