Skip to content

Instantly share code, notes, and snippets.

View atbradley's full-sized avatar

Adam Bradley atbradley

View GitHub Profile
@atbradley
atbradley / smode.R
Created December 17, 2015 20:11
Function to return the statistical mode in R.
smode <- function(x) {
which(tabulate(x)==max(tabulate(x)))
}
@atbradley
atbradley / import_excel_workbook.R
Created January 24, 2016 04:19
Import all sheets from an Excel workbook, using readxl.
library(readxl)
sheet_list <- lapply(excel_sheets('workbook.xlsx'), read_excel, path='workbook.xlsx')
@atbradley
atbradley / pinboard_remove_unread_tweets.py
Created April 1, 2016 17:24
Remove "unread" tweets from Pinboard.
USER_TOKEN = 'pinboard:ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
import re
import requests
import sys
import time
links = requests.get('https://api.pinboard.in/v1/posts/all?auth_token='+USER_TOKEN+'&format=json')#&count=100')
if links.status_code != 200:
@atbradley
atbradley / find_marc_field.php
Last active July 26, 2016 18:14
Parse Blacklight's JSON representation of MaRC records.
<?php
/**
* Functions for treating (blacklight-based) Josiah as an API.
*/
namespace ocra\josiah;
/**
* Find a field (and optionally subfield) in the JSONified MaRCXML record.
*
@atbradley
atbradley / Ocrify.user.js
Created July 28, 2016 14:47
Add an "Add to Course Reserves" link to Josiah (Brown University Library's discovery tool)
// ==UserScript==
// @name Ocrify
// @namespace http://library.brown.edu/
// @version 0.1
// @description Try to reserve an item on Josiah.
// @author Adam Bradley <atb@brown.edu>
// @match https://search.library.brown.edu/catalog/*
// @grant none
// ==/UserScript==
@atbradley
atbradley / blink_sandbox.py
Created August 18, 2016 14:12
The product of some experimentation with a Blinkstick Nano (https://www.blinkstick.com/).
@atbradley
atbradley / librarything.php
Created September 22, 2016 12:37
Retrieve book data from the LibraryThing Common Knowledge API.
<?php
namespace ocra\libraryThing;
/**
* Search LibraryThing's Common Knowledge API for a book and return and array with author/title and maybe year.
*/
function find_by_isbn($isbn) {
$lturl = 'http://www.librarything.com/services/rest/1.1/?method=librarything.ck.getwork&isbn=%s&apikey=%s';
$lturl = sprintf($lturl, $isbn, LIBRARYTHING_API_KEY);
@atbradley
atbradley / animate.css
Last active March 28, 2019 19:52
Animates the "Best Bets" search results on Josiah (e.g. https://search.library.brown.edu/?utf8=%E2%9C%93&q=naxos) in case they aren't obvious enough yet.
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.5.1
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2016 Daniel Eden
*/
@atbradley
atbradley / bingspellcheck.php
Created December 1, 2016 18:37
Simple use of the Bing Spell Check API in PHP
<?php
// See https://www.microsoft.com/cognitive-services/en-us/bing-spell-check-api for API details.
namespace bing\spellcheck;
require_once('conf/base.conf.php');
function _getSuggestions($input) {
$subkey = MICROSOFT_COGNITIVE_API_KEY;
<?php
/**
* Implement the array_column() function built-in to PHP 5.5+
*/
if (!function_exists('array_column')) {
function array_column($inpt, $columnKey, $indexKey = false)
{
if ( $indexKey !== false ) {
$outp = array_combine(
array_map(function($element) use($indexKey){return $element[$indexKey];}, $inpt),