Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
mark-cooper / basename_counter.py
Created October 20, 2011 03:56
Count occurrences of file basenames from a single folder and select those that appear once ...
from os import listdir
from os.path import basename, isfile, join, splitext
src_dir = 'c:\\repository\\'
files = {}
for file in listdir(src_dir):
src_file = join(src_dir, file)
if isfile(src_file):
base = splitext(basename(src_file))[0]
@mark-cooper
mark-cooper / cw_counter.js
Created October 20, 2011 04:09
Display a count of characters and words from input fields
// CHARACTER / WORD counter demo - uses Jquery
$(document).ready(function () {
// input with #characters and accompanying span with #c_length
$("#characters").keyup(function() {
$('#c_length').html($(this).val().length);
});
// input with #words and accompanying span with #w_length
@mark-cooper
mark-cooper / archon_subjects.sql
Created November 29, 2011 05:37
Archon SQL for subject headings
INSERT INTO `tblSubjects_Subjects` (
`Subject`,
`SubjectTypeID`,
`SubjectSourceID`
)
VALUES
('Advisory boards, California, Sonoma County', 1, 1),
('Alien property, California, Sonoma County', 1, 1),
('Animal welfare, California, Santa Rosa', 1, 1),
('Sonoma County Teachers'' Institute', 3, 1),
@mark-cooper
mark-cooper / hcli.rb
Created December 11, 2011 20:58
Ruby script to convert video files using HandBrakeCLI
# Ruby script to convert video files using HandBrakeCLI
# @path from extension i_ to o_ using preset
# Skips processing if output file already exists
# http://handbrake.fr/downloads2.php
path = 'X:Movies/*' # Change to desired location
i_ext = 'mkv' # input file extension
o_ext = 'mp4' # output file extension
preset = 'iPad' # HandBrake preset
Dir[path].each do |file|
if file =~ /\.#{i_ext}$/
@mark-cooper
mark-cooper / NetUtilities.java
Created December 17, 2011 20:43
Java: Checks link validity by evaluating HTTP headers using JSoup
package net.libcode.www.frequentutilities.net;
import org.jsoup.Connection;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
public class NetUtilities {
/**
* Checks link validity by evaluating HTTP headers
@mark-cooper
mark-cooper / circ_title_acq_record.rb
Created December 22, 2011 18:13
Library database maintenance: find circulating titles with acquisition records
require 'marc_tools'
# https://github.com/mark-cooper/marc_tools
# SCL branches (to exclude consortial partner branches)
BRANCHES = [
'cent',
'clov',
'fore',
'guer',
'heal',
@mark-cooper
mark-cooper / acq_circ.rb
Created December 27, 2011 06:33
Cataloging database maintenance: find circulating titles with acquisition records
require 'marc_tools'
# https://github.com/mark-cooper/marc_tools
# SCL branches (to exclude consortial partner branches)
BRANCHES = [
'cent',
'clov',
'fore',
'guer',
'heal',
@mark-cooper
mark-cooper / contentdm_api_request.js
Created December 30, 2011 23:32
ContentDM API requests using Javascript/JQuery
jQuery(function() {
// Cross Domain Policy restricted (obviously)
$.get('https://server15763.contentdm.oclc.org/dmwebservices/index.php?q=dmGetItemInfo/p15763coll5/149/json', function(data) {
console.log(data);
}, 'json');
// JSONP not supported
$.get('https://server15763.contentdm.oclc.org/dmwebservices/index.php?q=dmGetItemInfo/p15763coll5/149/json', function(data) {
console.log(data);
}, 'jsonp');
@mark-cooper
mark-cooper / file_marc_equality.php
Created January 9, 2012 23:14
PHP File_MARC equality oddness
<?php // 5.3
// From: http://pear.php.net/package/File_MARC
require 'File/MARC.php';
// From: https://github.com/abelperez/php-commons
require '../lib/collections/SimpleIterator.php';
require '../lib/collections/Set.php';
require '../lib/collections/ArraySet.php';
// Create a datafield
$a = new File_MARC_Data_Field('245', null, 1, 0);
@mark-cooper
mark-cooper / transform.rb
Created January 10, 2012 23:40
Transforming subject headings using ruby-marc
# TRANSFORM SUBJECT HEADINGS EXAMPLE
require 'marc'
# Function: text_to_datafield
# Returns a vanilla MARC::DataField object from string
# Format examples:
# 655 _0 Account books.
# 655 _7 3-D films.|2lcgft
def text_to_datafield(text_field)