Skip to content

Instantly share code, notes, and snippets.

@johnmackintosh
johnmackintosh / PBI.txt
Created January 31, 2021 20:22
Power BI resources
----
Power BI Official Software - Cost: $0 Dimes
----
Power BI Desktop. From the Microsoft Store updates automatically. #WINNING
URL: https://aka.ms/pbidesktopstore
Power BI Desktop. From download center requires manual updating. #NOTWINNING
@johnmackintosh
johnmackintosh / HeatmapHrByDay.R
Last active February 21, 2024 10:19
How I made the hourly~daily~monthly~yearly heatmap : https://www.r-graph-gallery.com/283-the-hourly-heatmap.html
# https://www.r-graph-gallery.com/283-the-hourly-heatmap.html
library(ggplot2)
library(dplyr) # easier data wrangling
library(viridis) # colour blind friendly palette, works in B&W also
library(Interpol.T) # will generate a large dataset on initial load
library(lubridate) # for easy date manipulation
library(ggExtra) # because remembering ggplot theme options is beyond me
library(tidyr)
@johnmackintosh
johnmackintosh / basic-row-of-dots-with-floored-time.sql
Last active October 26, 2023 08:40
flooring datetime to 15 minute intervals and using case when
SELECT [MovementDateTime],
[FirstName],
[LastName],
[Ward_Dept],
[Staging_Post],
[Movement_Type],
[IN_OUT],
cast(round(floor(cast([MovementDateTime] AS float(53))*24*4)/(24*4),5) AS smalldatetime) AS Movement15,
(CASE WHEN IN_OUT = 'IN' THEN 1 ELSE -1 END) AS [counter]
FROM [DB].[dbo].[TABLENAME]
@johnmackintosh
johnmackintosh / update-local-git.txt
Created March 14, 2023 11:33
code to update local repo from master to main
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
@johnmackintosh
johnmackintosh / rdsdl.R
Created January 13, 2023 12:07
download RDS file direct from github repository
path <- "https://github.com/owner/repo/raw/main/somedata.rds"
rdsdl <- function(path){
readRDS(url(path, "rb"))
}
@johnmackintosh
johnmackintosh / tidy-gather-pivot_longer-comparison.R
Created December 2, 2022 15:27
remember when tidyr::gather was a piece of cake?
### old way
```r
df %>%
mutate(row = row_number()) %>%
gather('column', 'source', -row, -N) # key = column, value = source, retain row and N
# further transforms
```
@johnmackintosh
johnmackintosh / create_folders.R
Last active October 25, 2022 12:53
quickly create subdiretories for RMarkdown outputs
# I want 18 separate folders for graphic outputs, and 17 separate folders for different outputs
# they will be saved in the "output" folder under my main project directory
library(fs)
library(here)
here <- here::here()
tablenos <- paste0("table",seq(1:17))
fignos <- paste0("fig",seq(1:18))
@johnmackintosh
johnmackintosh / test_frame.csv
Created September 25, 2022 22:32
data for NHSR caseload demo and answer
client_id referral_id team_desc referral_date discharge_date unique_id
1 1 Apple 2018-11-07T00:00:00Z 2019-10-29T00:00:00Z 1_1
2 1 Banana 2018-03-30T00:00:00Z 2_1
2 2 Apple 2020-03-14T00:00:00Z 2021-02-12T00:00:00Z 2_2
3 1 Banana 2017-01-18T00:00:00Z 2017-07-30T00:00:00Z 3_1
4 1 Apple 2020-09-02T00:00:00Z 2021-02-09T00:00:00Z 4_1
4 2 Apple 2017-06-20T00:00:00Z 2017-11-27T00:00:00Z 4_2
4 3 Clementine 2017-08-14T00:00:00Z 4_3
4 4 Clementine 2019-04-13T00:00:00Z 4_4
5 1 Banana 2019-11-21T00:00:00Z 2020-05-09T00:00:00Z 5_1
@johnmackintosh
johnmackintosh / caseload.R
Created September 25, 2022 22:22
as per Chris Beeley caseload question from NHSR demo and how-to
teams <- c("Apple", "Banana", "Clementine")
dates <- seq(as.Date("2017-01-01"), as.Date("2021-01-01"), "days")
# 5 columns- client id, referral id, team_desc, referral_date, discharge_date
test_frame <- purrr::map_dfr(1 : 100, function(x){
rnum <- sample(1 : 5, 1)
team_name <- sample(teams, rnum, replace = TRUE)