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
// 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 / 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 / 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 / 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 / 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 / wp-edits.js
Created March 11, 2015 23:11
Count Wikipedia Edits by List of Users
// see also: https://gist.github.com/phette23/5575987
// used to count edits at California College of the Arts
// during Art+Feminism edit-a-thon on March 7, 2015
var uns = [
"Phette23",
"Circa73",
"Flyingpanther",
"Tericlaude",
"Berylbev",
"Cd heaven",
@phette23
phette23 / randpw.js
Created April 3, 2015 22:05
Simple Node Random Password Script
#!/usr/bin/env node
// usage:
// > randpw
// IKS1L2H1AMOx
// > randpw --length 22
// IKS1L2H1AMOxBs4d8qxDXY
// > randpw | pbcopy # pipe to Mac clipboard
var chance = new require('chance')()
var args = require('minimist')(process.argv.slice(2))
var pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
@phette23
phette23 / remove-leading-zeroes.fish
Created August 12, 2015 00:11
remove leading zeroes Fish script
#!/usr/bin/env fish
# remove leading zeroes from JPG file names
# e.g. page001.jpg => page1.jpg
set start (pwd)
for dir in (ls)
echo "About to rename files in $dir"
# optional, makes me less afraid when I step through one folder at a time
read
@phette23
phette23 / bookmarkletTemplate.js
Created January 28, 2012 04:03
JavaScript Bookmarklet Template
//self-executing anonymous function
(function (window, document, undefined) {
var d=document; w=window; //aliases to save bytes
//do something
}(window, document));
//remove comments, put in a bookmark preceded by "javascript:"
@phette23
phette23 / jquery-plugin-tpl.js
Created January 30, 2012 22:22
jQuery Plugin Template
(function($){
$.fn.myPluginMethod = function() {
// keep it chainable, jQuery objects
// include multiple DOM elements
return this.each(function(){
// do something
});
};
}(jQuery));