Skip to content

Instantly share code, notes, and snippets.

View jsfenfen's full-sized avatar

Jacob Fenton jsfenfen

View GitHub Profile
@jsfenfen
jsfenfen / test_for_pdf.py
Last active February 18, 2017 06:40
test if a file is a pdf by only downloading the first 4 bytes. It may be better to use http headers, but if you think those may be wrong...
import requests
def test_for_pdf(url):
r = requests.get(url, stream=True)
return ( next(r.iter_content(chunk_size=4)) == '%PDF' )
# See pdf file spec, p. 92: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
if __name__ == '__main__':
# a pdf:
url = 'https://fremont.gov/DocumentCenter/View/31856'
print(url + " is pdf? " + str(test_for_pdf(url)) )
@jsfenfen
jsfenfen / read_procurements.py
Created March 13, 2017 17:00
Read Roseburg, OR's pdf "check report"
import csv
import re
""" Roseburg_Procurement.txt created with "$ pdftotext -layout Roseburg_Procurment.pdf """
infile = open("Roseburg_Procurement.txt","r")
outfile = open("Roseburg_Procurement_output.csv", "w")
paymentfile = open("Roseburg_Procurement_payment.csv", "w")
trashfile = open("Roseburg_Procurement_trashlines.txt", "w")
@jsfenfen
jsfenfen / gist:eceeb74a10a91e963f51615fdc7e542e
Created April 6, 2018 22:16
201700969349301030_public.xml
<?xml version="1.0" encoding="utf-8"?>
<Return xmlns="http://www.irs.gov/efile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.irs.gov/efile" returnVersion="2015v3.0">
<ReturnHeader binaryAttachmentCnt="0">
<ReturnTs>2017-04-06T17:02:24-05:00</ReturnTs>
<TaxPeriodEndDt>2016-06-30</TaxPeriodEndDt>
<PreparerFirmGrp>
<PreparerFirmEIN>930743240</PreparerFirmEIN>
<PreparerFirmName>
<BusinessNameLine1Txt>Hoffman Stewart &amp; Schmidt PC</BusinessNameLine1Txt>
</PreparerFirmName>

Keybase proof

I hereby claim:

  • I am jsfenfen on github.
  • I am jacobfenton (https://keybase.io/jacobfenton) on keybase.
  • I have a public key ASDZS1fJ_YxvKE7xmX-HbKYpKOM8fiADdK2GlQ1xgC0nygo

To claim this, I am signing this object:

@jsfenfen
jsfenfen / axis_titles.html
Last active November 6, 2018 16:47
Adding some axis titles to layercakes histogram example
#### AxisXTitled.html
<g class='axis x-axis'>
{#each ticks as tick, i}
<g class='tick tick-{ tick }' transform='translate({$xScale(tick)},{$yScale.range()[0]})'>
{#if opts.gridlines !== false}
<line y1='{$height * -1}' y2='0' x1='0' x2='0'></line>
{/if}
<text y='16' text-anchor='{textAnchor(i)}'>{opts.formatTick ? opts.formatTick(tick) : tick}</text>
</g>
library("RPostgreSQL")
# connect to postgres
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname = "database_name",
host = "localhost", port = 5432,
user = "user_name")
# execute query
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jsfenfen
jsfenfen / ppb.kml
Created September 15, 2020 14:01
ppb
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2">
<NetworkLinkControl>
<minRefreshPeriod>30</minRefreshPeriod>
</NetworkLinkControl>
<Document>
<name>911 Incidents</name>
<open>1</open>
<description>Recent 911 dispatch incidents in Portland, Oregon </description>
library(ggplot2)
library(dplyr)
# See https://healthdata.gov/dataset/covid-19-reported-patient-impact-and-hospital-capacity-state-timeseries
fileurl = "https://healthdata.gov/sites/default/files/reported_hospital_utilization_timeseries_20210227_1306.csv"
hospraw <- read.csv(url(fileurl), header=TRUE, sep=",")
# parse the dates
hospraw$dateob = as.Date(hospraw$date)