Skip to content

Instantly share code, notes, and snippets.

View arvi1000's full-sized avatar

Arvi Sreenivasan arvi1000

View GitHub Profile
# Process all JPEG files in the current dir and apply timestamp, using imagemagick
import glob
import re
import os
jpgs = glob.glob('*.jpeg')
for j in jpgs:
newfile = re.sub('\\.jpeg$', '_stamp.jpeg', j)
im_command = f'convert {j} -undercolor Black -fill white -pointsize 100 -auto-orient -gravity NorthWest -annotate 0 "%[EXIF:DateTimeOriginal]" {newfile}'
print(f'Processing {j}')
@arvi1000
arvi1000 / commute_mode.R
Created September 9, 2021 23:58
census: commute mode by state leg dist
library(tidycensus)
library(tidyverse)
# find the variables we care about
acs5_2019 <- tidycensus::load_variables(year = 2019, dataset = 'acs5', cache = T)
# ok here they are
my_vars <- paste0("B08006_", sprintf('%03d', 1:17))
# select just the most important top level responses
# (e.g. no public transportation break out)
options(tigris_use_cache = TRUE)
library(tigris)
library(sf)
# get shapefiles (coarse resolution)
sd_sf <- school_districts(state = 'CA', cb = T)
zip_sf <- zctas(cb=T, state='CA')
# which zips overlap OUSD?
library(tidycensus)
library(tidyverse)
census_api_key(Sys.getenv('CENSUS_API_KEY'))
vars <- load_variables(2017, "acs5", cache = TRUE)
il <- get_acs(geography = "county",
variables = "B00001_001",
state = "IL", geometry = TRUE)
ggplot(il) +
geom_sf(aes(fill=estimate/1000), size=0.4, color='black') +
scale_fill_viridis_c() +
library(lubridate)
library(tidyverse)
# data ----
full_dat <- data.frame(
dt = mdy(c('9/19/16', '2/27/17', '4/9/18', '9/17/18', '2/25/19', '8/5/2019',
'1/13/2020', '6/22/2020')),
num = c(2188,1833,1302,1171,1067,988, 892, 831)
)
obs <- nrow(full_dat)
holdout_days <- 2
library(tidyverse)
streak_len <- 7
ref_denom <- 276
tibble(x=1:streak_len,
y=(1/6)^x) %>%
ggplot(aes(x=x+1, y=y)) +
geom_point() +
geom_line() +
@arvi1000
arvi1000 / .bcc_map.txt
Last active May 20, 2020 02:48
put some points on a map and calc centroid
just to rename gist
library(tidyverse)
# data ----
"JonPear6 10:21 AM
1 8 9
plättyjö:plattyjo: 10:22 AM
3 1 8
swirving 10:22 AM
# survey of crank beauty
# https://forms.gle/CNqHkmeQa6n1cJxL7
library(tidyverse)
library(data.table)
library(patchwork)
# data ----
"DA 7400 DA 7700 DA 7800 DA 7900 DA 9000 DA 9100
8 7 6 2 5 4
library(ggplot2)
library(data.table)
dat <- fread(
'name, delegates
"BUTTIGIEG", 22
"SANDERS", 21
"WARREN", 8
"KLOBUCHAR", 7
"BIDEN", 6
"Still\nremaining", 3915')