Skip to content

Instantly share code, notes, and snippets.

Michael B. Klein mbklein

  • Northwestern University
  • Evanston, IL
Block or report user

Report or block mbklein

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View generate_sample_ingest_sheet.rb
require 'csv'
CSV.open('big_inventory_sheet.csv', 'w') do |csv|
csv << %w(work_accession_number accession_number filename description)
(1..50).each do |work|
(1..100).each do |file|
filename = (0..9).to_a.sample == 0 ? 'missing.tif' : 'present.tif'
csv << ["Test_%3.3d" % work, "Test_%3.3d_%4.4d" % [work, file], filename, "File %d for Work %d" % [file, work]]
end
end
@mbklein
mbklein / credo_level.sh
Created Jul 17, 2019
Report credo exit status based on severity, not category
View credo_level.sh
#!/bin/bash
######################################################
#
# This script will take the normal credo exit code
# (see https://github.com/rrrene/credo#exit-status)
# and add 64 if any high-severity (non-strict)
# issues are found and 128 if any low-severity
# (strict) issues are found
#
View main.rb
require 'aws-sdk-ecs'
require 'aws-sdk-sqs'
require 'json'
def handle_event(event:, context:)
handler = LambdaHandler.new(event, context)
handler.process!
end
class LambdaHandler
View 1. show.html.erb
<!-- events/show.html.erb -->
<%= form_tag(event_medfiles_release_many_path, method: 'POST') do %>
<%= hidden_field_tag 'id', @event.id %>
<% @event.medfiles.each do |medfile| %>
<%= render(partial: 'medfiles/release_form', object: medfile, as: 'medfile') %>
<% end %>
<%= submit_tag 'Do The Thing' %>
<%= end %>
@mbklein
mbklein / ulid_data.ex
Created Apr 17, 2019
Extracting timestamp and randomness from ULID (using Ecto.ULID)
View ulid_data.ex
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 Apr 9, 2019
Going from Zero to Rails on OS X
View README.md
  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 Mar 16, 2019
AWS ElasticSearch Snapshots
View elastic_snapshot.rb
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 Feb 7, 2019
Puppet Decommissioner
View decommissioner.rb
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 Jan 23, 2019
Basic info about NU Library's Fedora-on-AWS deployment
View fcrepo_aws_s3_info.md
  • 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
View batch_item_check.rb
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
You can’t perform that action at this time.