Skip to content

Instantly share code, notes, and snippets.

View phette23's full-sized avatar
🌹
"you're right, no human being would stack books like this"

Eric Phetteplace phette23

🌹
"you're right, no human being would stack books like this"
View GitHub Profile
@phette23
phette23 / unt-json-to-equella-taxonomy.js
Created January 27, 2015 18:46
UNT JSON to EQUELLA Taxonomy
// take http://digital2.library.unt.edu/vocabularies/agent-qualifiers/json/
// and insert into an EQUELLA taxonomy, preserving URL & definition info
// EQUELLA taxo format is CSV-like:
// term1/term/term2,key,value,key2,value2…
// can then upload with their included Python scripts or write your own
var fs = require('fs')
var data = JSON.parse(fs.readFileSync('agent-qualifiers.json'))
var terms = data.terms
var getDescription = function(term) {
@phette23
phette23 / a-unix-use-case.mdown
Last active August 29, 2015 14:10
A *NIX Use Case

Almost immediately after declaring a hiatus seems like a great time for a blog post.

Inspired by nina de jesus and Ruth Tillman's libtech level up project, here's something on the value of command-line text processing. Some of these common UNIX tools that have been around since practically the 1980s are great for the sort of data wrangling that many librarians find themselves doing, whether their responsibilities lie with systems, the web, metadata, or other areas. But the command prompt has a learning curve and if you already use text editor tools to accomplish some tasks, it might be tough to see why you should invest in learning. Here's one case I've found.

Scenario: our digital repository needs to maintain several vocabularies of faculty who teach in different departments. That information is, of course, within a siloed vendor product that has no viable APIs. I'm only able to export CSVs that looks like this:

"Namerer, Name","username"

"Othern

@phette23
phette23 / wrapper.ftl
Created August 27, 2014 18:50
EQUELLA - Expose User Role to JavaScript
<#-- NOTE this style should be removed for home page portlet
also should really use an ID rather than hide all portlet headings -->
<style>
/* hide header */
.portlet_freemarker_content .box_title_wrapper h3 {
display: none !important;
}
</style>
<#-- these role IDs will need to be researched & changed -->
<#if user.hasRole('490b1b93-10cd-b8fa-3291-93c357efe57b')>
@phette23
phette23 / tif2jpg.fish
Created August 20, 2014 16:38
Convert all tif files in a directory to jpg
for f in *.tif
convert $f (basename -s .tif $f).jpg
end
@phette23
phette23 / csv2patron-marc.py
Last active August 7, 2022 01:18
Converting CSV into Patron Records for III Millennium
#!/usr/bin/env python
# note final, more robust version at https://github.com/cca/millennium_patron_import
import sys
import csv # https://docs.python.org/2/library/csv.html
# PCODE mappings, etc.
from mapping import *
import datetime
import re
@phette23
phette23 / clip.js
Created June 18, 2014 23:55
Pipe to Clipboard in Node.js (Mac OS X only)
var clipboard = require('child_process').spawn('pbcopy')
, data = 'put whatever data here';
clipboard.stdin.write(data);
clipboard.stdin.end();
@phette23
phette23 / one-liners.js
Last active April 24, 2021 15:33
A few JavaScript One-Liners
// taken from https://medium.com/html5-css3/7c80a4b731f8
// and expanded, unreadable one-liners are kind of pointless
//pad zeroes
function pad(num) {
return ('0' + num).split('').reverse().splice(0,2).reverse().join('')
}
// get page query params
var qp = document.location.search.replace(/(^\?)/,'')
// stupid Node.js tricks
// accepts JS object literal of commands & their args
// executes each in series, pipes child process output to parent
// e.g. `node hellspawn.js '{"ls": "-al", "pwd": null, "echo": "Hello world!"}'`
var spawn = require('child_process').spawn
, cmds = JSON.parse(process.argv[2])
, cmd
, key
, val;
@phette23
phette23 / update-repos.fish
Last active May 21, 2024 18:33
Shell script to run `git pull` inside all subdirectories which are git repositories. I keep a number of projects in a folder & this helps me avoid manually updating each.
#!/usr/bin/env fish
# similar script in Fish
# still under construction, need to quiet `git status` more effectively
function update -d 'Update git repo'
git stash --quiet
git pull
git stash apply --quiet
end
@phette23
phette23 / doaj.php
Last active February 9, 2023 17:32
Web Scraping Examples in a Few Languages
<?php
// need to download simple_html_dom.php from SourceForge
// http://sourceforge.net/projects/simplehtmldom/files/
// and place it in the same directory as this script
require_once( 'simple_html_dom.php' );
// http://simplehtmldom.sourceforge.net/manual_api.htm
$base = 'http://www.doaj.org/doaj?func=search&template=&uiLanguage=en&query=';
$query = urlencode( 'librarianship' );