graph LR
A[N: config<br/>N: state<br/>N: reality] -->|Nothing to do| B(N: config<br/>N: state<br/>N: reality)
C[Y: config<br/>N: state<br/>N: reality] -->|Create| D(Y: config<br/>Y: state<br/>Y: reality)
E[N: config<br/>Y: state<br/>N: reality] -->|Someone manually deleted it,<br/>and also removed it from the config.| F(?)
G[N: config<br/>N: state<br/>Y: reality] -->|Ignore| H(N: config<br/>N: state<br/>Y: reality)
I[Y: config<br/>Y: state<br/>N: reality] -->|Recreate?<br/>Someone manually deleted it.| D
K[Y: config<br/>N: state<br/>Y: reality] -->|Error. You must import the existing resource into the state.| D
M[N: config<br/>Y: state<br/>Y: reality] -->|Delete| N(N: config<br/>N: state<br/>N: reality)
O[Y: configY: stateY: reality] -->|Nothing to do| P(Y: configY: stateY: reality)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspect a nested hash table as a list | |
as.list.hashtab <- function(h) { | |
val <- vector("list", 0) | |
maphash(h, function(k, v) { | |
r <- if (is.hashtab(v)) { | |
as.list.hashtab(v) | |
}else { | |
v | |
} | |
val[[k]] <<- r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(igraph) | |
library(tidygraph) | |
# Create an igraph | |
# c - d | |
# - e | |
# - f - b | |
ig <- graph_from_literal(f-+b, c-+e:f, c-+d) | |
ig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ENTRY=$(/usr/bin/yad --title "Activity log" --text="What are you doing?" --entry --auto-kill) | |
DATETIME=$(date --iso-8601=seconds) | |
[[ ! -z "$ENTRY" ]] && echo -e "${DATETIME}\t${ENTRY}">> /home/nacnudus/gds/log.log | |
# Schedule in crontab Every six minutes between 9am and 6pm on weekdays | |
# */6 9-18 * * 1-5 env DISPLAY=:0 && /usr/bin/bash /path/to/this_file.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The fastest implementation available is in mlpack (C++) | |
using Pkg | |
Pkg.add("mlpack") | |
using mlpack | |
x = rand(5,2) | |
x_emst = mlpack.emst(x) | |
# A far slower implementation is in EMST.jl. As of 2022-03-14 my fork has been updated to run with Julia v0.7+using Pkg | |
using Pkg | |
Pkg.add(url="https://github.com/nacnudus/EMST.jl", rev="julia-v0.7") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to analyse Gmail message sizes by from/to/subject | |
# 1. Download Gmail from Google Takeout, specifically the folders "Inbox", | |
# "Archived", "Sent", and "Bin". | |
# 2. Extract it into the working directory. It should create the folders | |
# Takeout/Mail | |
# 3. Run this script in the working directory | |
library(tidyverse) | |
library(tm.plugin.mail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(tidyxl) | |
library(unpivotr) | |
#' Convert relevant character values to dates | |
#' | |
#' @param cells Data frame derived from `tidyxl::xlsx_cells()` or | |
#' `readr::melt_csv()` or similar. | |
#' @param condition An expression that returns a logical value, | |
#' is defined in terms of the columns in `cells`. Similar to `dplyr::filter()`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compare performance of ls() with as.list.environment() for counting objects | |
# length(as.list.environment()) is fastest | |
env <- environment(plot) # A handy, large environment | |
bench::mark(length(ls(env)), length(as.list(env))) | |
# # A tibble: 2 x 13 | |
# expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result memory time gc | |
# <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> <bch:tm> <list> <list> <list> <list> | |
# 1 length(ls(env)) 4.69ms 4.96ms 198. NA 0 99 0 501ms <int [1]> <NULL> <bch:tm> <tibble [99 × 3]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --------------------------------------- | |
# untidy data | |
# --------------------------------------- | |
# this dataset is a sample of the kind of data that might appear in the wild, | |
# particularly when dealing with government data, | |
# particularly when trying to convert an output table or individual report | |
# back into a raw data format that can be analyzed. | |
# in these test datasets, discrete observations are spread out across multiple rows. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ompr) | |
library(ompr.roi) | |
library(ROI.plugin.glpk) | |
M <- 3 # Volunteers (rows) | |
N <- 4 # Jobs (combination of role at given time and location) (columnss) | |
# Jobs are: | |
# 1. Greet (8am-9am) |
NewerOlder