Skip to content

Instantly share code, notes, and snippets.


Adam Bradley atbradley

View GitHub Profile
View cryptarithm.mzn
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 /
Last active Apr 17, 2020
django-admin command to import model data from an Excel spreadsheet.
#Goes in <your_app>/management/commands
from collections import OrderedDict
from import BaseCommand, CommandError
from django.apps import apps
from django.db import models
from openpyxl import load_workbook
def workbook_name(filename):
atbradley /
Created Jan 9, 2020
List and download files in Google Drive. Utility class for a data dashboard.
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 / jquery-3.4.1.min.js
Last active Jul 19, 2019
Chrome extension to insert a "Your Librarian" widget in Josiah's ( search results sidebar.
View jquery-3.4.1.min.js
/*! jQuery v3.4.1 | (c) JS Foundation and other contributors | */
!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,,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[]||"object":typeof e}var f="3.4.1",k=function(e,
atbradley / profile.ps1
Created Dec 20, 2018
Custom PowerShell prompt with current time and available drive space.
View profile.ps1
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") }
atbradley / touch.ps1
Created Sep 18, 2017
Powershell equivalent of POSIX 'touch' command.
View touch.ps1
param([string] $fn)
if(!(New-Item $fn -ErrorAction SilentlyContinue)) {
Set-ItemProperty -Path $fn -Name LastWriteTime -Value (get-date)
View array_column.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 / bingspellcheck.php
Created Dec 1, 2016
Simple use of the Bing Spell Check API in PHP
View bingspellcheck.php
// See for API details.
namespace bing\spellcheck;
function _getSuggestions($input) {
atbradley / animate.css
Last active Mar 28, 2019
Animates the "Best Bets" search results on Josiah (e.g. in case they aren't obvious enough yet.
View animate.css
@charset "UTF-8";
* animate.css -
* Version - 3.5.1
* Licensed under the MIT license -
* Copyright (c) 2016 Daniel Eden
atbradley / librarything.php
Created Sep 22, 2016
Retrieve book data from the LibraryThing Common Knowledge API.
View librarything.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 = '';
$lturl = sprintf($lturl, $isbn, LIBRARYTHING_API_KEY);