Skip to content

Instantly share code, notes, and snippets.

View ar-puuk's full-sized avatar
💭
💩🚗

Pukar Bhandari ar-puuk

💭
💩🚗
View GitHub Profile
# DuckDB Vector Tiles with mapgl Example
# This script demonstrates how to serve vector tiles from DuckDB using ST_AsMVT()
# and display them in a mapgl map using httpuv
library(mapgl)
library(duckdb) # Requires the latest DuckDB version (>= 1.4.0)
library(httpuv)
library(sf)
library(duckspatial)
library(tigris)
@ar-puuk
ar-puuk / settings.json
Last active September 21, 2025 20:58
Positron Setup
{
// this is the settings.json file
// file behaviour
"files.hotExit": "onExitAndWindowClose",
"files.defaultLanguage": "r",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"files.associations": {
# Load necessary libraries
library(sf)
#> Linking to GEOS 3.13.1, GDAL 3.10.2, PROJ 9.5.1; sf_use_s2() is TRUE
library(tmap)
library(tmaptools)

url <- "https://gisco-services.ec.europa.eu/distribution/v2/nuts/shp/NUTS_RG_20M_2024_3035.shp.zip"

EU_eflsk_2 <- sf::read_sf(
# Load necessary libraries
library(sf)
library(tmap)
library(tmaptools)
url <- "https://gisco-services.ec.europa.eu/distribution/v2/nuts/shp/NUTS_RG_20M_2024_3035.shp.zip"
EU_eflsk_2 <- sf::read_sf(
paste0("/vsizip/","/vsicurl/", url)
) |>
@ar-puuk
ar-puuk / nvd_download.sh
Created April 13, 2025 20:02 — forked from christiangalsterer/nvd_download.sh
Script to download the National Vulnerability Database files from https://nvd.nist.gov
#!/bin/sh
# https://gist.github.com/christiangalsterer/5f55389b9c50c74c31b9
# Copyright 2015 Christian Galsterer
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#### ---------------------------------------------
## Edit via: RStudio > Tools > Edit Code Snippets
# Released under a MIT license
snippet fragment
[${1:text}]{.${2:type}}
snippet aside
[${1:text}]{.aside}
@ar-puuk
ar-puuk / county-epsg.csv
Created February 20, 2025 23:24 — forked from fitnr/county-epsg.csv
List of State Plane coordinate systems and their various ID codes.
COUNTYFIPS NAME STATEPLANEFIPS EPSG
16079 Shoshone County 1103 26970
16073 Owyhee County 1103 26970
16071 Oneida County 1101 26968
16077 Power County 1101 26968
16075 Payette County 1103 26970
06115 Yuba County 0402 26942
06111 Ventura County 0405 26945
06113 Yolo County 0402 26942
31177 Washington County 2600 32104
@ar-puuk
ar-puuk / county-epsg.csv
Created February 20, 2025 23:23 — forked from fitnr/county-epsg.csv
List of State Plane coordinate systems and their various ID codes.
16079 Shoshone County 1103 26970
16073 Owyhee County 1103 26970
16071 Oneida County 1101 26968
16077 Power County 1101 26968
16075 Payette County 1103 26970
06115 Yuba County 0402 26942
06111 Ventura County 0405 26945
06113 Yolo County 0402 26942
31177 Washington County 2600 32104
## function to split "label: text" into data.frame(label = text)
v1 <- function(x) {  
  x <- gsub(": ", ":", x)  ## first clear that whitespace
  dd <- read.delim(text = x, sep = ":", header = FALSE); 
  setNames(data.frame(dd[[2]]), dd[[1]][1])
}

library(sf)
sf::sf_use_s2(FALSE)
@ar-puuk
ar-puuk / split_lines.R
Created January 15, 2025 21:22 — forked from dblodgett-usgs/split_lines.R
Splits lines longer than a given threshold into the minimum number of pieces to all be under the given threshold.
#' @title split lines
#' @description Splits lines longer than a given threshold into the minimum number of pieces to all be under the given threshold.
#' @param lines data.frame of class sf with LINESTRING sfc column.
#' @param max_length maximum segment length to return
#' @param id name of ID column in data.frame
#' @return only the split lines.
#' @importFrom dplyr group_by ungroup filter left_join select rename mutate
#' @export
#'
split_lines <- function(input_lines, max_length, id = "ID") {