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 / ulid_data.ex
Created April 17, 2019 18:26
Extracting timestamp and randomness from ULID (using Ecto.ULID)
defmodule ULID.Data do
defstruct time: nil, random: nil
def from_binary(<<time::integer-size(48), random::binary-size(10)>>) do
time
|> DateTime.from_unix(:millisecond)
|> parse(random)
end
def from_string(ulid) do
@mbklein
mbklein / README.md
Last active April 9, 2019 15:06
Going from Zero to Rails on OS X
  1. Open a Terminal window

  2. Install Xcode command line tools:

    xcode-select --install
    

    (Follow pop-up prompts to install command-line tools)

  3. Install the homebrew package manager:

@mbklein
mbklein / elastic_snapshot.rb
Last active March 16, 2019 05:51
AWS ElasticSearch Snapshots
class ElasticSnapshot
attr_accessor :host, :repository, :region
def initialize(host:, repository:, region: 'us-east-1')
@host = host
@repository = repository
@region = region
end
def list_repositories
@mbklein
mbklein / decommissioner.rb
Created February 7, 2019 19:55
Puppet Decommissioner
require 'net/https'
require 'uri'
class Decommissioner
attr_reader :auth_cert, :auth_key, :pe_server
def initialize(pe_server, auth_cert, auth_key)
@pe_server = pe_server
@auth_cert = OpenSSL::X509::Certificate.new(auth_cert)
@auth_key = OpenSSL::PKey::RSA.new(auth_key)
@mbklein
mbklein / fcrepo_aws_s3_info.md
Created January 23, 2019 16:27
Basic info about NU Library's Fedora-on-AWS deployment
  • Version/Infrastructure info:
    • Fedora 4.7.5
    • In a private VPC with the rest of our applications
    • Deployed via Elastic Beanstalk on the Multicontainer Docker platform
      • t2.xlarge instance type
      • Behind a classic load balancer
    • Docker image: nulib/fcrepo4:s3fix
  • Prerequisites:
    • An RDS Postgresql instance for Fedora to use for metadata
    • An S3 Bucket for Fedora to use for binaries
@mbklein
mbklein / batch_item_check.rb
Created January 18, 2019 15:23
Batch Item Check
def check
return false if work.nil?
attached_titles = work.ordered_members.to_a.collect { |fs| fs.title.first }
expected_titles = attribute_hash[:file].collect { |fn| File.basename(fn) }
extra_titles = attached_titles - expected_titles
missing_titles = expected_titles - attached_titles
return true if extra_titles.empty? && missing_titles.empty?
yield(work: work, missing: missing_titles, extra: extra_titles)
false
end
@mbklein
mbklein / move_old_pyramids.rb
Last active December 21, 2018 17:53
Move old DONUT pyramids to new names
def move_old_pyramids
bucket = Settings.aws.buckets.pyramids
FileSet.find_each do |fs|
begin
file_id = fs.original_file.id
old_file_id = file_id.split(%r{/files/}).last
new_file_id = file_id.split(%r{/files/}).first
old_key = IiifDerivativeService.s3_key_for(old_file_id)
new_key = IiifDerivativeService.s3_key_for(new_file_id)
@mbklein
mbklein / reindex_with_utf8.rb
Created November 16, 2018 00:01
Add force_encoding(UTF-8) to full text indexing
ActiveFedora::Base.class_eval do
def self.reindex_everything(batch_size: 50, softCommit: true, progress_bar: false, final_commit: false)
$stderr.puts "We're at it again, jerks!"
# skip root url
descendants = descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true)
batch = []
progress_bar_controller = ProgressBar.create(total: descendants.count, format: "%t: |%B| %p%% %e") if progress_bar
@mbklein
mbklein / nginx.conf
Created October 8, 2018 15:53 — forked from regadas/nginx.conf
nginx cached forward proxy #example
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
arch avalon donut glaze
cantaloupe X X
db O O O
elasticproxy X
elasticsearch X X X X
fedora X X X
hls X
kibana X
matterhorn X