Skip to content

Instantly share code, notes, and snippets.

View greglinch's full-sized avatar

Greg Linch greglinch

View GitHub Profile
@greglinch
greglinch / datawrapper-install-instructions-detailed.md
Last active October 28, 2021 14:13
Datawrapper set up instructions: Below is a detailed, step-by-step guide for setting up your own installation of Datawrapper, an open-source data visualization tool. Questions? Suggestions? Please let a comment below. Happy installing!
@greglinch
greglinch / file-generator.py
Last active June 16, 2021 22:05
Python script to batch generate files based on a variable. Save this file in a new directory and make the desired modifications. Open terminal and cd into that directory. Type $ python ./file-generator.py to execute the script.
values = ['comma','separated', 'list', 'of','values', 'each', 'surrounded', 'by', 'quotes']
# for each item in the list of items
for value in values:
# construct the filename; prefix or suffix optional
filename = 'prefix-' + value + '.jpt'
# open the file to be written
fo = open(filename, 'w')
@greglinch
greglinch / test-page.html
Last active October 18, 2018 15:19
Sample HTML page from Howard University ONA event
<html>
<head>
<title>This is my test page</title>
</head>
<body>
<h1>My article headline</h1>
<p>This is <em>my</em> article.</p>
<p>It's the <strong>greatest</strong> article ever written.</p>
</body>
</html>
@greglinch
greglinch / the_slug.php
Created December 5, 2012 04:28
create the_slug() function for WordPress
function the_slug($echo=true){
$slug = basename(get_permalink());
do_action('before_slug', $slug);
$slug = apply_filters('slug_filter', $slug);
if( $echo ) echo $slug;
do_action('after_slug', $slug);
return $slug;
}
// credit: http://www.tcbarrett.com/2011/09/wordpress-the_slug-get-post-slug-function/
@greglinch
greglinch / google_sheets_json.py
Last active March 14, 2017 17:35 — forked from nickjevershed/google-sheets-json.py
Python script (based on @nickjevershed's original) to convert Google spreadsheets to simple JSON file and save it locally and/or to S3. Assumes your data is on the left-most sheet (i.e. the default) and that you've already clicked the "Publish to the web" option in the "File" menu. S3 requires environment variables.
import os
import json
import argparse
import requests
import tinys3
'''
Modified version of nickjevershed's code
@greglinch
greglinch / download_congress_photos.py
Last active March 10, 2017 22:26
Set a list of congressional bio directory IDs in order to download members' photos. I used wget instead of requests because of a TLS handshake issue. For getting the IDs, see https://gist.github.com/greglinch/5197267b6ff8fcb19192ba5443f1f71d
import os
# dimensions = '225x275'
dimensions = 'original'
## add a list of IDs here based on http://bioguide.congress.gov/biosearch/biosearch.asp
id_list = []
images_downloaded = 0
@greglinch
greglinch / convert_congress.py
Last active March 10, 2017 22:26
Converts HTML table from congressional bio directory to a csv. For downloading images, see https://gist.github.com/greglinch/608001fa0ae39834af18354c9e8c6f09
from bs4 import BeautifulSoup
'''
Prereqs:
- Go to the congressional bio directory http://bioguide.congress.gov/biosearch/biosearch.asp
- Search the parameters you want
- inspect element and copy the html
- paste into a file and (optional?) wrap with <html></html> tags
@greglinch
greglinch / doccloud_upload_urls_from_csv.py
Last active January 29, 2017 17:23
Upload PDFs from URLs in csv to DocumentCloud.org using Ben Welsh's python-documentcloud API wrapper https://python-documentcloud.readthedocs.io/en/latest/gettingstarted.html#uploading-a-pdf-from-a-url
from documentcloud import DocumentCloud
import urllib, cStringIO, csv
## Create the DocumentCloud.org client
client = DocumentCloud("USERNAME", "PASSWORD")
## Set additional data to store with document by mapping csv field keys to new values that will be they keys on Document Cloud
## you could abstract this by providing these key-value pairs in a separate csv, then supplying the data csv and field mapping csv as args in the command line
field_mapping = {
@greglinch
greglinch / 0_reuse_code.js
Created April 11, 2016 19:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@greglinch
greglinch / doccloud_annotation_urls.py
Last active December 21, 2015 14:38
Script using python-documentcloud API wrapper to get the first annotation URL for each document in a specified project.
from documentcloud import DocumentCloud
import csv
"""
Return a list of annotation URLs for each document in the specified project.
TK: output to a CSV file.
"""
# define your variables