Skip to content

Instantly share code, notes, and snippets.

require 'application_system_test_case'
class ItemEditTest < ApplicationSystemTestCase
test 'download path is stable after edit' do
admin = users(:user_admin)
item = items(:item_admin)
item.save
# Need to add file to item to be able to go through editing wizard.
@pgwillia
pgwillia / W29 - Digital Services Outage events for Oncall.ipynb
Created July 24, 2023 21:13
Notebook to generate stacked histograms of oncall notifications for ERA, OJS and DMP
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pgwillia
pgwillia / after.txt
Last active September 21, 2022 20:42
How does pushmi_pullyu work?
$ tree 05296aa6-4ced-4cf0-a612-b008fd40a404_after_file_delete/
05296aa6-4ced-4cf0-a612-b008fd40a404_after_file_delete/
└── 05296aa6-4ced-4cf0-a612-b008fd40a404
├── bag-info.txt
├── bagit.txt
├── data
│   ├── logs
│   │   ├── aipcreation.log
│   │   └── files_logs
│   │   └── a8592fcf-af2c-4f44-921a-b98a0be467c3

Running rubocop can show where this code strays from best practices/community standards. It doesn't make sense to make these changes to the code, we've already talked about the code being somewhat disposable, but could be informative to know about.

For example

# rails/generate_report_12.rb:28:110
missing_community_collection_report[:community] << "Community Id %{community_id} does not exist" % {community_id: community_collection[0]}          

becomes "Community Id #{community_collection[0]} does not exist"

@pgwillia
pgwillia / empty_collections.rb
Created April 25, 2022 22:01
Empty Collections in Jupiter
empty_collections = Collection.find_each.filter {|collection| collection.member_objects.size == 0 }
CSV.open('empty_collections.csv', 'wb') do |csv|
csv << ['Community', 'Collection', 'url']
empty_collections.each do |collection|
community_title = Community.find(collection.community_id)
url = Rails.application.routes.url_helpers.community_collection_url(collection.community_id, collection.id)
csv << [community_title, collection.title, url]
end
end
@pgwillia
pgwillia / _README.md
Last active March 23, 2022 17:08
Preparing ERA Data for DSpace

The Ask

March 2022, Weiwei asked,

We are looking to create an extract of around 4 dozen items in ERA as sample data for Atmire to evaluate and propose for migration charges. See Leah's message below. I wonder if this could be something you coordinate with Leah and someone from the metadata team? You are probably the one who has the most comprehensive knowledge of ERA and the history of some of these items?

Ignace Deroost of Atmire said,

A CSV format usually works best. So if you could export your samples in CSV that would be great!

From our DSpace investigation I had observed a csv export from their software (dspace_sample_export)

The Work

@pgwillia
pgwillia / datacite_metadata.rb
Last active October 6, 2021 21:57
Datacite API planning
require "ostruct"
@item = OpenStruct.new(creators: ["Joe Shmoe"], title: "Test title", descripton: "Test description", sort_year: 2021)
def datacite_metadata
{
data: {
attributes: {
creators: @item.creators.map{|creator| {name: creator}},
titles: [{
title: @item.title
}],
@pgwillia
pgwillia / Validate ActiveStorage file.md
Created July 28, 2021 21:47
Validation of an attached ActiveStorage file

Problem:

I have an object that has a csv file attached using ActiveStorage.

I'm going to do some operations based on the content of that csv file so I want to validate that the file I'm attaching has the information I will need.

So the class looks something like this:

class MySpreadsheet < ApplicationRecord
@pgwillia
pgwillia / speaker_frequency.rb
Created September 23, 2020 05:46
conference speakers by frequency
require "csv"
headers = ["year", "date", "time", "speakers", "title", "abstract", "type", "tags", "slides", "video", "audio"]
# create new csv for the final output with the final header:w
CSV.open("all.csv", "wb", write_headers: true, headers: headers) do |csv|
Dir["csv/*.csv"].each do |path| # for each of your csv files
CSV.foreach(path, headers: true, return_headers: false) do |row| # don't output the headers in the rows
csv << row # append to the final file
end
end
@pgwillia
pgwillia / Gemfile
Last active June 6, 2019 18:03
wraith for visual comparison
source 'https://rubygems.org'
gem 'wraith'