Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
building the history web

Jason Heppler hepplerj

💭
building the history web
View GitHub Profile
@hepplerj
hepplerj / scrape.py
Created March 30, 2023 15:07
Simple Python scraper for the Internet Archive text
View scrape.py
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
url = "https://archive.org/stream/ahandbooksocial00blisgoog/ahandbooksocial00blisgoog_djvu.txt"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
pre_selector = "#maincontent > div > pre"
@hepplerj
hepplerj / server.rb
Created November 4, 2022 02:28
A small Ruby local server.
View server.rb
require "webrick"
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd)
trap("INT") { server.stop }
server.start
View bubble_sort.rb
def bubble_sort(arr)
for i in 0...arr.length
sorted = true
for k in 0...(arr.length - i - 1)
if arr[k] > arr[k + 1]
arr[k], arr[k + 1] = arr[k + 1], arr[k]
sorted = false
end
end
View twitterusers.py
#!/usr/bin/python3
import tweepy
import csv
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
@hepplerj
hepplerj / metro.R
Created March 16, 2020 20:53
Percentage of residents who take public transportation to work
View metro.R
library(tidycensus)
library(tidyverse)
# If not set, un-comment below and install your Census API key (https://api.census.gov/data/key_signup.html)
# census_api_key("YOUR KEY HERE", install = TRUE)
get_acs(geography = "metropolitan statistical area/micropolitan statistical area",
variables = "DP03_0021PE",
summary_var = "B01003_001",
survey = "acs1",
@hepplerj
hepplerj / census_cleanup.R
Created March 11, 2020 19:36
An example script for census data in R
View census_cleanup.R
library(tidyverse)
library(tidycensus)
# My recommendation is to use the tidycensus library to make getting this data
# easier than reading in the data from the Census website.
#
# Before you can begin, you'll need to get an API key from the Census Bureau.
# You can acquire one here:
#
# Once you have the API key, run the following in RStudio:
@hepplerj
hepplerj / messy.R
Created February 20, 2020 20:58
Messy data in R, for teaching the tidyverse
View messy.R
library(charlatan)
library(salty)
library(magrittr)
library(readr)
messydata <- ch_generate('name','job','phone_number', n = 200)
messydata <- messydata %>%
mutate(job = salt_capitalization(job)) %>%
mutate(phone_number = salt_na(phone_number)) %>%
@hepplerj
hepplerj / frequency_to_list.R
Created December 11, 2019 18:11
Turn a frequency table into a list of individual items
View frequency_to_list.R
library(tidyverse)
library(readxl)
data <- readxl::read_xlsx("data.xlsx")
reshaped <- data %>% gather(word, freq, 2:21)
reshaped <- reshaped %>% drop_na()
cleaned <- reshaped %>%
uncount(freq)
@hepplerj
hepplerj / geofilter.R
Created November 8, 2019 15:12
Checking points and filtering incorrect or unneeded data.
View geofilter.R
library(tidyverse)
library(maps)
library(mapdata)
data <- read_csv("~/Desktop/nplsuperfund.csv")
names(data) <- c("lat","lon","date")
# Filter down to USA extent to remove extraneous points
tidy <- data %>%
filter(lat < -67, lat > -125) %>%
@hepplerj
hepplerj / hex_logo.R
Last active January 14, 2020 19:32
Hex logo generator for R User Group
View hex_logo.R
library(hexSticker)
library(tidyverse)
library(tidycensus)
library(sf)
library(viridis)
options(tigris_use_cache = TRUE)
nebraska_raw <- get_acs(state = "NE",
geography = "tract",