Skip to content

Instantly share code, notes, and snippets.

View bohdanszymanik's full-sized avatar

Bohdan Szymanik bohdanszymanik

  • Wellington, New Zealand
View GitHub Profile
@bohdanszymanik
bohdanszymanik / ApplicativeValidation.fsx
Last active December 30, 2018 08:16
Getting my head round applicative validation
// Exploring validation approaches
// (To start off a no validation option then...)
// Firstly by using an Option type to return Some error text or None if ok - well, actually we end up wrapping the output with Result just because we can
// Secondly by using a Result type and applicative validation a la https://fsharpforfunandprofit.com/posts/elevated-world-3/#validation
open System
module Result =
let apply fResult xResult =
match fResult, xResult with
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
fun main(args : Array<String>) {
var value1 = 1
var value2 = "2"
var value3 = 3.0
var value4 = 4.0
println(java.lang.String.format("%d, %s, %6f : %3f", value1, value2, value3, value4))
(*
<?xml version="1.0" encoding="UTF-8"?>
<Questionnaire type="referee">
<Section id="referee" label="Your details">
<Section id="identity" label="Identity">
<Input id="name" label="Referee name">
<Input id="firstName" label="First name">Douglas</Input>
<Input id="middleName" label="Middle name">Neil</Input>
<Input id="surname" label="Surname">Adams</Input>
</Input>
@bohdanszymanik
bohdanszymanik / LiquorLicenceRegisterAddressLookup.R
Last active May 7, 2021 04:04
nominatum openstreetmap address lookup for the liquor licencing register
##################################################################################
# Import liquor licencing data, geocode and plot
# Plot on a NZ map
# Show a regional view - some demographics eg population density at SA2
# Import the public NZ Police aggregated crime data
# Look at crime harm regional cf liquor outlet distribution
#
library(readxl)
library(rgdal)
@bohdanszymanik
bohdanszymanik / st_join_example.R
Created May 19, 2021 20:46
Expanded example of joining spatial datasets, counting intersecting points across shapes, and using as an aesthetic
# refer to https://gis.stackexchange.com/questions/110117/counting-number-of-points-in-polygon-using-r/270479#270479
# for original code example
# Load libraries ----------------------------------------------------------
library(raster)
library(sf)
library(dplyr)
# Get sample data ---------------------------------------------------------
@bohdanszymanik
bohdanszymanik / dateChange.R
Created May 24, 2021 02:30
Random date formatting example in R so I don't forget how it's done
library(readr)
library(stringr)
library(stringi)
em <- read_csv("C:/somewhere/some.csv")
em$Time <- paste(
paste(str_sub(em$`Date & Time`, 7, 10), str_sub(em$`Date & Time`, 4, 5), str_sub(em$`Date & Time`, 1, 2), sep="/"),
str_sub(em$`Date & Time`, -8), sep = " "
)
@bohdanszymanik
bohdanszymanik / mappingWithGgplot.R
Created May 24, 2021 02:35
Using ggplot to display a map plot with an underlying tiles
library(tidyverse)
library(readr)
library(ggmap)
library(ggplot2)
library(readxl)
library(plotly)
library(here)
library(httr)
@bohdanszymanik
bohdanszymanik / countInAreas.R
Last active July 19, 2021 22:50
R sample to count locations in areas
##################################################################################
# Import school locations
# Import some areas
# Join counts
# write out
library(readxl)
library(writexl)
library(sf)
tcltkUrl <- "https://cran.r-project.org/bin/windows/contrib/4.0/tcltk2_1.2-11.zip"
install.packages(tcltkUrl, repos=NULL, type="binary")
# tkplotUrl <- "https://cran.r-project.org/bin/windows/contrib/4.0/tcltk2_1.2-11.zip"
# install.packages(tkplotUrl, repos=NULL, type="binary")
# library(tkplot)
knitrUrl <- "https://cran.r-project.org/bin/windows/contrib/4.0/knitr_1.38.zip"
install.packages(knitrUrl, repos=NULL, type="binary")
remove.packages("rlang")
remove.packages("tibble")
rlangUrl <- "https://cran.r-project.org/bin/windows/contrib/4.0/rlang_1.0.2.zip"
install.packages(rlangUrl, repos=NULL, type="binary")
tcltkUrl <- "https://cran.r-project.org/bin/windows/contrib/4.0/tcltk2_1.2-11.zip"
install.packages(tcltkUrl, repos=NULL, type="binary")
knitrUrl <- "https://cran.r-project.org/bin/windows/contrib/4.0/knitr_1.38.zip"