Skip to content

Instantly share code, notes, and snippets.

@ozjimbob
ozjimbob / rain.r
Last active June 13, 2022 23:54
Raindrops
library(tickle)
x11(type = 'dbcairo', antialias = 'none')
dev.control(displaylist = 'inhibit')
df = data.frame(x=runif(10,-1,1),y=runif(10,-1,1),size=rep(1,10))
size <- reactive_dbl(value=6)
rate <- reactive_dbl(value=10)
@ozjimbob
ozjimbob / blah.r
Created October 11, 2022 22:33
blah.r
library(tidyverse)
library(plumber)
library(sf)
library(geojson)
register_serializer("geojson", serializer_geojson, verbose = TRUE)
#* @serializer geojson
#* @get /points
points <- function() {
<html><head><title>Test Page</title>
<script type="text/javascript">
// Example POST method implementation:
async function postData(url = '', data = {}) {
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'no-cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
# Data file is as provided
data <- read.delim("data_02.txt",header=FALSE,sep=" ")
# Simple lsit to look up scores for Rock/Paper/Scissors
scores <- list(X=1, Y=2, Z=3)
# Look-up matrix for win/lose/draw conditions, R/P/S in rows/columns
WLD <- matrix(c(3,0,6,
6,3,0,
0,6,3),nrow=3)
data <- readLines("data_03.txt")
letters_all <- c(letters,LETTERS)
process_line <- function(x){
this_line <- data[x]
sl = nchar(this_line)
str1 <- substr(this_line,1,sl/2)
str2 <- substr(this_line,(sl/2)+1,sl)
chars1 <- strsplit(str1,"")[[1]]
data <- readLines("data_05.txt")
# find separator line
blank <- which(data == "")
stacks <- data[1:(blank-1)]
instructions <- data[(blank+1):length(data)]
stacks <- strsplit(stacks,"")
rowlen <- length(stacks[[1]])
Prompt:
Can you tell me a story? There are a group of foxes living underground near a mystical pond in a wood. The foxes have adventures and battle a mysterious malevolent presence.
Response:
Once upon a time, in a dense forest far from civilization, there was a mystical pond hidden among the trees. It was said that the pond had magical properties and was guarded by a group of wise and cunning foxes. These foxes had lived underground near the pond for many generations, and they had developed a rich culture and society of their own.
The foxes were led by a wise and just king named Aspen. He was a strong and honorable fox, and he was loved and respected by all the members of the fox community. Under his guidance, the foxes thrived and lived in harmony with each other and the forest around them.
But one day, a dark and malevolent presence began to stir in the depths of the forest. It was a powerful and evil being that had been sealed away for centuries, but now it had regained its strength and was determine
@ozjimbob
ozjimbob / day_07.r
Last active December 7, 2022 10:12
data <- readLines("data_07.txt")
files <- data.frame(id=1,parent=0,name="/",type="dir",size=0)
find_next <- function(x){
while(x < length(data)){
x=x+1
if(strsplit(data[x]," ")[[1]][1]=="$" || x > length(data)){
return(x)
}
library(tidyverse)
library(terra)
tas <- vect("E:/geodata/Aus_Coastline/tasmania/csttascd_r.shp")
bclm <- rast(list.files("E:/geodata/bioclim/2_5m/",full.names=TRUE))
bclm <- crop(bclm,tas)
ext <- extract(bclm,tas)
ext <- ext[complete.cases(ext),]
# Day 15
library(sf)
#Sensor at x=1943362, y=12808: closest beacon is at x=1861152, y=-42022
data <- readLines("data_15.txt")
ll = list()
# for each data line, get coordinates, draw a diamond based on manhattan distance
for (i in seq_along(data)) {
d2 = strsplit(data[[i]], "[=,:]")[[1]]