Skip to content

Instantly share code, notes, and snippets.

View atbradley's full-sized avatar

Adam Bradley atbradley

View GitHub Profile
enum LETTERS = {dmy, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z};
LETTERS: dummy = dmy;
array[int, int] of LETTERS: ADDENDS;
array[int] of LETTERS: SOLUTION;
array[int] of LETTERS: USED;
array[LETTERS] of var 0..9: solution;
constraint solution[dummy] = 0;
@atbradley
atbradley / import_excel.py
Last active April 17, 2020 16:02
django-admin command to import model data from an Excel spreadsheet.
#Goes in <your_app>/management/commands
from collections import OrderedDict
from django.core.management.base import BaseCommand, CommandError
from django.apps import apps
from django.db import models
from openpyxl import load_workbook
def workbook_name(filename):
try:
@atbradley
atbradley / gdrive.py
Created January 9, 2020 19:00
List and download files in Google Drive. Utility class for a data dashboard.
#Standard.
import io
#External (`pip install google-api-python-client google-auth-httplib2` should give you these.)
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
from apiclient.http import MediaIoBaseDownload
import httplib2
class Tool():
@atbradley
atbradley / jquery-3.4.1.min.js
Last active July 19, 2019 20:52
Chrome extension to insert a "Your Librarian" widget in Josiah's (https://search.library.brown.edu/) search results sidebar.
/*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */
!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],E=C.document,r=Object.getPrototypeOf,s=t.slice,g=t.concat,u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.4.1",k=function(e,
@atbradley
atbradley / profile.ps1
Created December 20, 2018 19:35
Custom PowerShell prompt with current time and available drive space.
Function PrettySize([int64]$bytes) {
if ( $bytes -gt 1TB ) { $result = [string]::Concat([math]::Round($bytes/1TB, 2), " TB") }
elseif ( $bytes -gt 1GB ) { $result = [string]::Concat([math]::Round($bytes/1GB, 2), " GB") }
elseif ( $bytes -gt 1MB ) { $result = [string]::Concat([math]::Round($bytes/1MB, 2), " MB") }
elseif ( $bytes -gt 1KB ) { $result = [string]::Concat([int]($bytes/1KB), " KB") }
$result
}
@atbradley
atbradley / touch.ps1
Created September 18, 2017 19:45
Powershell equivalent of POSIX 'touch' command.
param([string] $fn)
if(!(New-Item $fn -ErrorAction SilentlyContinue)) {
Set-ItemProperty -Path $fn -Name LastWriteTime -Value (get-date)
}
<?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),
@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;
@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 / 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);