Skip to content

Instantly share code, notes, and snippets.

View brfitzpatrick's full-sized avatar
🐜

Ben R. Fitzpatrick brfitzpatrick

🐜
View GitHub Profile
@brfitzpatrick
brfitzpatrick / .emacs
Last active July 22, 2019 09:15
emacs25 ~/.emacs
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes (quote (manoj-dark)))
'(package-selected-packages (quote (polymode)))
'(show-paren-mode t))
(electric-indent-mode -1)
@brfitzpatrick
brfitzpatrick / R2PBS.md
Last active July 26, 2020 07:07
How to submit R code to a Portable Batch System (PBS) managed HPC resource (e.g. QUT's High Performance Computing Facility `Lyra').

How to submit R code to a Portable Batch System (PBS) managed High Performance Computing (HPC) Facility (e.g. QUT's HPC Facility 'Lyra').

You will need:

  1. An account with the relevant HPC facility (QUT staff and HDR students can request access to the QUT facility here),
  2. the R Script (.R file) you want to run,
  3. a Job Script (.sub file) that tells Lyra how to run your R script and,
  4. a file containing any data your R Script needs to run.

Note: These instructions work on a system running Debian (GNU + Linux) with the Gnome Desktop Environment.

@brfitzpatrick
brfitzpatrick / list.files( ) + assign( )
Created April 22, 2016 21:39
Read all files in a directory into R
# general demo
setwd('~/Documents/directory_of_csv_files/')
# create a collection of .csv files names following some system
X <- expand.grid(LETTERS,1:10)
for(i in 1:nrow(X)){
Data.i <- data.frame(matrix(data = rnorm(1000), nrow = 10))
@brfitzpatrick
brfitzpatrick / leaRn.md
Last active January 23, 2019 14:50
A short list of online resources for self directed learning of the R Language and Environment for Statistical Computing and Graphics

Online Courses

Books:

  • R for Data Science by Hadley Wickham & Garrett Grolemund (an actual book that you can also read for free online)

Reference Cards/Cheat Sheets

@brfitzpatrick
brfitzpatrick / ray.md
Last active July 26, 2017 00:52
fire a ray of blocks in Minecraft

Ray(s) of blocks

a function for interacting with a Minecraft world via ROpenSci's miner package

ray produces one or more rays of blocks of length rng from the fid player's position in the direction given by their view orientation (center the cross hairs on your target). Rays of lava are particularly effective for igniting enemies. Persistent rays (pst = TRUE) of some safe block type provide quick but messy staircases and bridges. If you accidentally ignite yourself, a ray of water starting adjacent to your position (disp = 1) can save you if you run into it but you'll need to type fast. Non-persistant rays replace all blocks in their path first with the block type specified by rid then with empty blocks (air type) and thus may be thought of as destroying all in their path. To ignite a pack of enemies in rapid succession set rpt to the nu

@brfitzpatrick
brfitzpatrick / swap values in emacs
Created July 24, 2017 01:38
swap values in emacs
M-x replace-regexp <RET>
\(dog\)\|cat <RET>
\,(if \1 "cat" "dog") <RET>
Beginning Line 3 with `\,` tells Emacs that this line should be evaluated as a Lisp expression.
The `\1` on Line three referres to the first grouped of characters defined with `(` and `)` on line 2.
Read line 3 as if `\1` replace with "cat" else replace with "dog"
You have to escape (i.e. preceed with `\`) the `(`, `)` and `|` characters for them to be treated as special characters

Preparing Elevation Data for Visualisation with rayshader

library(magrittr)
library(viridis)
library(raster)
library(rayshader)

Preparing Elevation Data for Visualisation with rayshader

library(magrittr)
library(viridis)
library(raster)
library(rayshader)
@brfitzpatrick
brfitzpatrick / vis_nb_wghts_sf.R
Created December 20, 2018 23:14
Visualising Neighbourhood Weights
library(sp)
library(spdep)
library(tidyverse)
library(sf)
data(meuse)
nb.boundary.radius <- 750
nb.obj <- dnearneigh(x = select(meuse, x, y) %>% as.matrix(), d1 = 0, d2 = nb.boundary.radius, row.names = NULL, longlat = NULL, bounds=c("GT", "LE"))
input.seq <- 1:10
for(i in 1:length(input.seq)){
file.con <-file(paste0('script', input.seq[i], '.R'))
writeLines(
text = c("source('my.fun.R')",
paste0('result', i, ' <- my.fun(x = ', i, ", y = 'character input')"),
paste0("save(list = 'result", i, "', file = 'result", i, ".RData')")
),
con = file.con