Skip to content

Instantly share code, notes, and snippets.

View ianmcook's full-sized avatar

Ian Cook ianmcook

View GitHub Profile
@ianmcook
ianmcook / duckdb_ibis_example.py
Created January 24, 2023 18:01
Ibis + DuckDB example
# pip install 'ibis-framework[duckdb]'
import pandas as pd
import ibis
from ibis import _
# create a pandas DataFrame and write it to a Parquet file
df = pd.DataFrame(data={'repo': ['pandas', 'duckdb', 'ibis'],
'stars': [36622, 8074, 2336]})
df.to_parquet('repo_stars.parquet')
@ianmcook
ianmcook / clean_github_jira_ids.R
Last active October 26, 2022 21:26
Match Apache Arrow Jira user accounts with GitHub user accounts
# run this script second
library(dplyr)
df <- read.csv("dirty.csv")
agg <- df %>%
group_by(jira, github) %>%
summarise(n = n(), .groups = "keep") %>%
ungroup() %>%
@ianmcook
ianmcook / acero_execplan.cpp
Last active April 23, 2025 08:52
Create and execute an Acero ExecPlan
#include <iostream>
#include <arrow/api.h>
#include <arrow/result.h>
#include <arrow/compute/api.h>
#include <arrow/compute/exec/exec_plan.h>
arrow::Status ExecutePlanAndCollectAsTable(
std::shared_ptr<arrow::compute::ExecPlan> plan,
std::shared_ptr<arrow::Schema> schema,
arrow::AsyncGenerator<std::optional<arrow::compute::ExecBatch>> sink_gen) {
@ianmcook
ianmcook / create_and_print_arrow_table.cpp
Last active June 2, 2022 14:01
Create and print an Arrow Table in C++
#include <iostream>
#include <arrow/api.h>
#include <arrow/result.h>
#include <arrow/compute/api.h>
arrow::Status Execute() {
arrow::Int32Builder int_builder;
ARROW_RETURN_NOT_OK(int_builder.Append(1));
ARROW_RETURN_NOT_OK(int_builder.Append(2));
ARROW_RETURN_NOT_OK(int_builder.Append(3));
@ianmcook
ianmcook / enquo_helpers.R
Last active April 10, 2021 03:48
rlang::enquo() helpers for eager evaluation and idempotence
# enquo() helpers for eager evaluation and idempotence
# wrap eager() around enquo() to evaluate the quosure immediately in the calling
# environment *if* it can do so without error, otherwise return the quosure
eager <- function(quo) {
val <- try(eval_tidy(quo), silent = TRUE)
if (inherits(val, "try-error")) {
quo
} else {
val
@ianmcook
ianmcook / vcpkg_arrow_cpp_deps_install.txt
Last active January 25, 2021 16:25
output of vcpkg install arrow cpp dependencies
C:\Users\ian>vcpkg install --clean-after-build --triplet x64-windows --x-manifest-root C:\Users\ian\arrow\cpp
A suitable version of cmake was not found (required v3.19.2). Downloading portable cmake v3.19.2...
Downloading cmake...
https://github.com/Kitware/CMake/releases/download/v3.19.2/cmake-3.19.2-win32-x86.zip -> C:\vcpkg\downloads\cmake-3.19.2-win32-x86.zip
Extracting cmake...
A suitable version of 7zip was not found (required v18.1.0). Downloading portable 7zip v18.1.0...
Downloading 7zip...
https://www.nuget.org/api/v2/package/7-Zip.CommandLine/18.1.0 -> C:\vcpkg\downloads\7-zip.commandline.18.1.0.nupkg
Extracting 7zip...
A suitable version of nuget was not found (required v5.5.1). Downloading portable nuget v5.5.1...
@ianmcook
ianmcook / tx_la_weather_alerts.R
Created August 26, 2020 15:17
Map of active weather alerts for Texas and Louisiana
remotes::install_github("ianmcook/weatherAlerts")
remotes::install_github("ianmcook/weatherAlertAreas")
library(weatherAlerts)
library(leaflet)
alerts <- getAlerts(c("TX", "LA")) # takes about 45 seconds
severity <- alerts@data$severity
colorMap <- c(Minor = "green",
@ianmcook
ianmcook / nc_tornado_warnings_map.R
Last active March 18, 2021 22:07
Create map of North Carolina tornado alert polygons and home location
install.packages(c("ggmap", "leaflet", "sp"))
devtools::install_github("ianmcook/weatherAlerts")
devtools::install_github("ianmcook/weatherAlertAreas")
# geocode home address
library(ggmap)
register_google("ENTER_GCP_GEOCODING_API_KEY_HERE")
home <- geocode("University of North Carolina at Chapel Hill")
# or specify coordinates of home
@ianmcook
ianmcook / nc_tornado_warnings.R
Last active October 31, 2019 23:57
Map of active tornado warnings for North Carolina
library(weatherAlerts)
library(leaflet)
alerts <- getAlerts("NC") # takes a few seconds
alerts <- alerts[alerts$event == "Tornado Warning",]
leaflet() %>%
addTiles() %>%
addPolygons(data = alerts, color = "black", fillColor = "magenta", weight = 1)
@ianmcook
ianmcook / one_chess_set.csv
Last active October 4, 2019 21:53
Scatterplot of chess piece dimensions with ggplot2
piece base_diameter height weight
King 37.3086 95.1557 50.2774
King 36.9878 95.3598 51.5528
King 37.6846 94.8507 50.7298
King 37.4201 96.2158 50.9344
King 36.7413 95.5326 51.9347
King 36.8166 96.0273 51.2393
King 37.5822 95.8491 50.8103
King 37.4132 95.2667 52.2267
King 37.7643 94.9941 51.2417