Skip to content

Instantly share code, notes, and snippets.

View hepplerj's full-sized avatar
💭
building the history web

Jason Heppler hepplerj

💭
building the history web
View GitHub Profile
@hepplerj
hepplerj / pairs.py
Created April 15, 2024 15:54
Pairing up names
#!/usr/bin/python3
import random
def pair_names(filename, output_filename):
with open(filename, 'r') as f:
names = [line.strip() for line in f]
random.shuffle(names)
pairs = [names[n:n+2] for n in range(0, len(names), 2)]
if len(names) % 2 != 0:
@hepplerj
hepplerj / custom.css
Created April 12, 2024 16:44
Adjustment to navigation hyperlink color for Omeka
.autumn a:link {
color: #F16100;
}
.autumn a:visited {
color: #F16100;
}
.autumn a:hover, .autumn a:active, .autumn a:focus {
color: #FFA300;
}
@hepplerj
hepplerj / collection_item.html
Last active December 14, 2023 20:00
Django pass html template args
<div class="card" style="width: 18rem;">
<img src="{{ image }}" class="card-img-top" alt="#">
<div class="card-body">
<h5 class="card-title">{{ title }}</h5>
<p class="card-text">{{ description }}</p>
<a href="#" class="btn btn-primary">{{ collection_purl }}</a>
</div>
</div>
@hepplerj
hepplerj / scrape.py
Created March 30, 2023 15:07
Simple Python scraper for the Internet Archive text
#!/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.
require "webrick"
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd)
trap("INT") { server.stop }
server.start
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
#!/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
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
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
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)) %>%