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 / clip_akld.R
Created May 13, 2025 02:11
Clip meshblock 2013 to Auckland area - copied from a Microsoft Fabric Spark(R) notebook so I st_read file will be an odd location
library(sf)
library(dplyr)
nz_coastline <- st_read("/lakehouse/default/Files/lds-nz-coastline-mean-high-water-SHP/nz-coastline-mean-high-water.shp")
mb2013_akld <- st_read("/lakehouse/default/Files/statsnz-meshblock-2013-SHP-akld/meshblock-2013.shp")
# different CRS for the two regions
# nz_coastline is NZGD2000 while mb2013_akld is WGS 84
# Let's reconcile both to WGS84
nz_coastline_wgs84 <- st_transform(nz_coastline, st_crs(mb2013_akld))
@bohdanszymanik
bohdanszymanik / MapVictimisations.ipynb
Created April 27, 2025 00:15
Mapping crime victimisations from the nz police data site
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bohdanszymanik
bohdanszymanik / example.R
Created November 6, 2023 00:28
From a tibble map a (slow) function over a column to calculate a new column with a progress bar
library(tidyverse)
1:1000 |>
as_tibble_col(column_name="some_column") |>
select(some_column) |>
mutate(some_other_column = map(some_column, function(x){Sys.sleep(1/100);(1/x)}, .progress = list(
type = "iterator",
format = "Calculating {cli::pb_bar} {cli::pb_percent}",
clear = TRUE)))
@bohdanszymanik
bohdanszymanik / db2se_create_srs.txt
Last active September 22, 2023 00:42
Syntax to create NZTM
db2se create_srs testdb -srsName NZTM -srsID 2193 -xScale 500 -yScale 500 -xMin 900000 -xMax 1.8014399E13 -yMin 4000000 -yMax 1.8014403E13 -zMin 0 -zMax 9.0071993E15 -mMin 0 -mMax 9.0071993E15 -coordsysName \"NZGD_2000_NEW_ZEALAND_TRANSVERSE_MERCATOR\" -description 'SRS NZTM'
@bohdanszymanik
bohdanszymanik / typescriptDb2.ts
Last active August 29, 2023 01:11
Typescript querying DB2
// Assumes you've installed
// * the free IBM docker db2 edition
// * ibm_db for node: https://github.com/ibmdb/node-ibm_db
// Brings back multiple records as well. Found on the net can't remember where - oh, lots of js docs here: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md
import * as db2 from 'ibm_db';
let cn: string = "DRIVER={DB2};DATABASE=testdb;HOSTNAME=127.0.0.1;UID=db2inst1;PWD=password;PORT=50000;PROTOCOL=TCPIP";
db2.open(cn, function(err: any, conn: any){
if (err) return console.log(err);
conn.query('select 1 from sysibm.sysdummy1', function (err: any, data: any) {
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"
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")
@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)
@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 / 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 = " "
)