Skip to content

Instantly share code, notes, and snippets.

View mbklein's full-sized avatar

Michael B. Klein mbklein

  • Northwestern University
  • Evanston, IL
View GitHub Profile
@mbklein
mbklein / libvips.spec
Created February 13, 2018 01:42
libvips RPM spec for CentOS 6
Summary: A fast image processing library with low memory needs
Name: vips
Version: 8.6.2
Release: 1%{?dist}
License: LGPLv2.1+
Source0: https://github.com/jcupitt/libvips/releases/download/v8.6.2/%{name}-%{version}.tar.gz
URL: https://github.com/jcupitt/libvips
BuildRequires: chrpath, gtk-doc, libxml2-devel, libjpeg-turbo-devel, libpng-devel
BuildRequires: libtiff-devel, libexif-devel, libgsf-devel, lcms-devel
BuildRequires: ImageMagick-devel, gobject-introspection-devel, libwebp-devel
@mbklein
mbklein / audioplot
Created January 18, 2018 22:02
Convert audio file to waveform thumbnail
#!/bin/bash
linecolor="#44db97"
filename=$(basename "$1")
outfile="${filename%.*}.png"
magick -size 1280x720 canvas:none -stroke ${linecolor} -draw 'rectangle 0,0 1280,720' -fill black \
-draw 'line 0,80 1280,80' -draw 'line 0,150 1280,150' -draw 'line 0,210 1280,210' -draw 'line 0,260 1280,260' \
-draw 'line 0,300 1280,300' -draw 'line 0,330 1280,330' -draw 'line 0,350 1280,350' -draw 'line 0,360 1280,360' \
-draw 'line 0,370 1280,370' -draw 'line 0,390 1280,390' -draw 'line 0,420 1280,420' -draw 'line 0,460 1280,460' \
require 'benchmark'
ActiveFedora.fedora.instance_variable_get(:@config)[:base_path] = '/speedtest'
class TestObject < ActiveFedora::Base
has_subresource 'captions', class_name: 'ActiveFedora::File'
has_subresource 'poster', class_name: 'ActiveFedora::File' do |f|
f.original_name = 'poster.jpg'
end
end
@mbklein
mbklein / awssh
Created May 31, 2017 14:46
awssh
#!/bin/bash
env=$1
shift
if [[ $env =~ '.' ]]; then
ip=$env
else
ip=$(aws ec2 describe-instances --filters "[{\"Name\":\"tag:Name\",\"Values\":[\"$env\"]},{\"Name\":\"instance-state-code\",\"Values\":[\"16\"]}]" | \
jq -r ".Reservations[0].Instances[0].PrivateIpAddress")
fi

SpeedyAF

What?

  • A Solr-cached hybrid presenter for ActiveFedora

Where?

@mbklein
mbklein / copy_avalon_section.rb
Last active March 6, 2017 17:53
Copy an Avalon section
def copy_section(mf, attrs={})
mo = mf.media_object
attrs = mf.attributes.reject { |k,v| k =~ /id$/ }.merge(attrs).merge(media_object_id: mo.id)
dattrs = mf.derivatives.collect { |d| d.attributes.reject { |k,v| k =~ /id$/ } }
new_mf = begin
mo.master_files.create(attrs)
rescue Ldp::Gone
retry
end
course_map = Course.all.group_by { |c| c.title.split(/\s+/).first }.reject! { |k,v| k !~ /^201[567][A-Z0-9_-]+$/ }
course_map.each_pair do |course_id,courses|
label_course = courses.find { |c| c.label.present? }
label = label_course.nil? ? courses.first.title : label_course.label
canonical_course = Course.create(context_id: course_id, label: label, title: courses.first.title)
courses.each do |course|
$stderr.print "Rewriting #{course.context_id} as #{canonical_course.context_id}..."
MediaObject.find_each(read_access_virtual_group_ssim: course.context_id) do |mo|
mo.read_groups -= [courses.collect(&:context_id)]
mo.read_groups += [canonical_course.context_id] unless mo.read_groups.include?(canonical_course.context_id)
@mbklein
mbklein / Gemfile
Last active October 12, 2016 23:02
Internal Derby for ActiveFedora
# ...
gem 'derby'
gem 'capybara_discoball'
# ...
@mbklein
mbklein / MATTERHORN_INSTALL.md
Last active September 27, 2016 18:30
Manual Matterhorn Install and Config with OS X and Wowza

This assumes OS X and Wowza, but you can fix the Avalon settings and paths to point to whatever you need to.

  1. Clone matterhorn:

     git clone --depth 1 --branch 1.4.x git@github.com:avalonmediasystem/avalon-felix
     cd avalon-felix
     cp etc/config.properties.example etc/config.properties
    
  2. Edit etc/config.properties

@mbklein
mbklein / compound_properties.rb
Last active August 26, 2016 21:04
Overriding ActiveTriple setters without recursion
class MyFramedThing < ActiveFedora::Base
include ActiveFedora::Associations
property :width, predicate: (whatever), multiple: false
property :height, predicate: (whatever), multiple: false
property :frame_size, predicate: (whatever), multiple: false
alias_method :_width=, :width=
def width=(value)
setting_frame_size do