Skip to content

Instantly share code, notes, and snippets.

View greglinch's full-sized avatar

Greg Linch greglinch

View GitHub Profile
@greglinch
greglinch / arduino_input_incrementer
Created June 4, 2011 20:51
To measure the output of my desk pedals at work using an Arduino
// ARDUINO INPUT INCREMNENTER
// To measure the output of my desk pedals at work
// Adapted from Example 03A from "Getting Started with Ardunio" by Massimo Banzi
// Greg Linch
// http://www.greglinch.com
#define BUTTON 7 // input pin where the push button is connected; this will soon be replaced with alternative method to measure output of pedals
int val = 0; // store the state of the input pint
@greglinch
greglinch / udacity-cs101-unit-1-final-quiz.py
Created March 1, 2012 03:20
Example of how to extract a link in Python using only the find() function
page ='<div id="top_bin"><div id="top_content" class="width960"><div class="udacity float-left"><a href="http://www.xkcd.com">'
start_link = page.find('<a href=')
start_quote = page.find('"', start_link)
end_quote = page.find('"', start_quote+1)
url = page[start_quote+1:end_quote]
@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 / 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 / doccloud_delete_docs_in_project.py
Last active December 21, 2015 11:39
This Python script uses Ben Welsh's python-documentcloud API wrapper (http://datadesk.github.io/python-documentcloud) to delete every document in a specific DocumentCloud.org project. To use, enter in command: line $ pip install python-documentcloud. To execute, type: $ python ./doccloud_delete_docs_in_project.py
from documentcloud import DocumentCloud
"""
Delete each document in the specified project
"""
# define your variables
username = "USERNAME_HERE"
password = "PASSWORD_HERE"
@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
@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 / add-to-page.js
Last active December 15, 2015 15:41
Tired of verbose code embeds? Insert HTML, CSS or JS onto a page using one line per code block. Also handy when sharing across sites: you just update the main JS file and don't need to re-send updated embed codes. NOTE: I'd recommend renaming the variables and IDs to things that relate to the content so it's better self-documenting code.
//// JAVASCRIPT ////
// Set the vars
// be sure to minify the code: http://www.willpeavy.com/minifier
var cssContentOne = 'CSS HERE';
var htmlContentOne = 'HTML HERE';
var htmlContentTwo = 'HTML HERE';
@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 / 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!