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
# Hyrax 3.0 Upgrade Notes
```
$ devstack down -v
$ devstack up -d arch
$ bundle exec rake arch:seed ADMIN_USER=bmq449 ADMIN_EMAIL=brendan-quinn@northwestern.edu SEED_FILE=seed.yml
```
- Update Gemfile
```
gem 'hyrax', '~> 3.0.0.beta.rc2`
@mbklein
mbklein / get_resource_ids.sh
Created February 17, 2020 16:13
Get Terraform resource IDs from state file
jq -r '[.modules[] | (.path|join(".")) as $path | .resources | to_entries[] | { "key": ($path + "." + .key), "value": .value.primary.id }] | from_entries'
@mbklein
mbklein / foo.ex
Last active February 13, 2020 21:30
Ecto validation for non-nil embedded schema
defmodule MyApp.Data.Schemas.Foo do
use Ecto.Schema
import Ecto.Changeset
import MyApp.Data.Schemas.PrepareEmbed
alias MyApp.Data.Schemas.EmbeddedMap
schema "foo" do
embeds_one :embedded_map, EmbeddedMap, on_replace: :update
@mbklein
mbklein / geoip_lookup.rb
Created November 5, 2019 16:56
GeoIP database queries in Ruby
#!/usr/bin/env ruby
require 'csv'
require 'maxminddb'
db = MaxMindDB.new('./GeoLite2-City.mmdb')
CSV.open('results.csv', 'w') do |output|
output << ['IP', 'City', 'Subdivision', 'Country', 'Latitude', 'Longitude']
File.new('ips.txt','r').each_line do |line|
line.chomp!
@mbklein
mbklein / gen.py
Created October 27, 2019 01:24
My dumb neural net generator
#!/usr/bin/env python3
import pathlib
import sys
from textgenrnn import textgenrnn
stem = sys.argv[1]
count = 100 if len(sys.argv) < 3 else int(sys.argv[2])
temp = [1.0, 0.5, 0.2, 0.2] if len(sys.argv) < 4 else float(sys.argv[3])
@mbklein
mbklein / gen.py
Created October 26, 2019 17:27
Bare Bones Neural Net
#! /usr/bin/env python3
import pathlib
import sys
from textgenrnn import textgenrnn
stem = sys.argv[1]
count = int(sys.argv[2])
hdfile = f"{stem}.hdf5"
path = pathlib.Path(hdfile)
@mbklein
mbklein / generate_sample_ingest_sheet.rb
Created July 26, 2019 19:00
Generate large spreadsheet
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 July 17, 2019 19:27
Report credo exit status based on severity, not category
#!/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
#
@mbklein
mbklein / main.rb
Created May 22, 2019 14:45
Ruby Lambda
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
<!-- 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 %>