Skip to content

Instantly share code, notes, and snippets.

View jimjam-slam's full-sized avatar
📊
Building data vis!

James Goldie jimjam-slam

📊
Building data vis!
View GitHub Profile
@jimjam-slam
jimjam-slam / islandscape.js
Created October 23, 2023 06:04
Quick observer for reacting to screen orientation in Observable and Quarto notebooks. Assumes portrait on desktop.
isLandscape = Generators.observe(next => {
// yield initial value
next(screen.orientation?.angle == 90 || screen.orientation?.angle == 180);
// define event listener
const listener = () => next(screen.orientation?.angle == 90 || screen.orientation?.angle == 180);
// attach event listener
screen.orientation.addEventListener("change", listener);
@jimjam-slam
jimjam-slam / test.r
Last active September 30, 2023 06:36
ggflags-top10-economics-example
gdp <- data.frame(
name = c("us", "cn", "jp", "de", "in", "gb", "fr", "it", "ca"),
gdp = c(26854, 19374, 4410, 4309, 3740, 3160, 2924, 2170, 2090),
x = c(1,2,3,1,2,3,1,2,3),
y = c(3,3,3,2,2,2,1,1,1))
p1 <- ggplot(gdp) +
aes(x, y) +
geom_flag(aes(country = name, size= gdp)) +
@jimjam-slam
jimjam-slam / test.r
Last active July 27, 2023 01:06
pmapping by position #experiments
my_func <- function(alpha, beta, gamma) alpha + beta + gamma
# no
tibble(a = 1:5, b = 6:10, c = 11:15) %>%
mutate(z = pmap_int(., my_func))
# yes
tibble(a = 1:5, b = 6:10, c = 11:15) %>%
mutate(z = pmap_int(
dplyr::select(., alpha = a, beta = b, gamma = c),
@jimjam-slam
jimjam-slam / notes.md
Last active June 29, 2023 01:15
diagram-svelte-notes

In Svelte:

  • export each Illustrator layer as a separate SVG (using the same artboard)
  • modify the SVG files:
    • remove the xml parent node;
    • rename the extension to .svelte
    • if using several layers, rename the classes to avoid collisions between them when inlining
  • import the components in svelte: `import FileName from "./FileName.svelte"
  • use the layer components sequentially in a parent component with <FileName>. wrap them in a parent div.
  • stack the layers visually by giving the parent div position: relative and the map layers position: absolute; top: 0; left: 0;. use :global([selector]) to inject the styles into the svgs
  • insert other svelte components, like buttons, in between or on top of the layers
@jimjam-slam
jimjam-slam / _quarto.yml
Created February 15, 2023 04:36
Accessing custom, nested Quarto document metadata in other listings
project:
type: website

flutter_pytorch_mobile

lib/model.dart:

  • Defines:
    • getPrediction: calls the predict method
    • getImagePrediction: calls the predictImage method and then compares the maximum score agains tthe label list
    • getImagePredictionList: calls the predictImage method, returns all scores

android/src/main/java/io/funn/pytroch_mobile/PyTorchMobilePlugin.java:

@jimjam-slam
jimjam-slam / query.r
Last active November 2, 2022 21:53
Get ASGS geometry from ABS ArcGIS REST API #experiments
library(sf)
library(httr2)
library(ggplot2)
# based on https://community.esri.com/t5/gis-blog/
# accessing-arcgis-rest-services-using-r/ba-p/898451
api_query <- url_parse("https://geo.abs.gov.au")
api_root <- "/arcgis/rest/services"
@jimjam-slam
jimjam-slam / prep-tiles-from-osm.md
Last active June 11, 2024 06:03
Notes on extracting, processing and hosting vector tiles

tl;dr

Shapefile(s) to vector tile set

graph LR
    A[Vector source - eg. shapefile] --> |ogr2ogr| B[geoJSON]
    B --> |tippecanoe| C[Set of .pbf tiles]
@jimjam-slam
jimjam-slam / netflows.r
Created March 24, 2022 06:16
Pivot an origin/destination/value tibble to calculate net values #rstatstips
# in hindsight i probably should've used a network analysis package to do this
library(tidyverse)
set.seed(1)
# create a sample data frame of origins and destinations
testdf <-
tibble(
origin = sample(letters, 10),
destination = sample(letters, 10),
@jimjam-slam
jimjam-slam / ggiraph-flags-fonts.r
Created March 3, 2022 03:11
Combine an interacgive with ggflags and custom fonts with Google Fonts (that work even for remote viewers without the font installed) #rstatstips
library(tidyverse)
library(ggiraph)
library(ggflags)
library(gfonts)
library(here)
mydata <- tribble(
~ x, ~ y, ~ flag, ~ is_home,
1, 1, "au", "yes",
2, 2, "us", "no",