Skip to content

Instantly share code, notes, and snippets.

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 November 25, 2024 18:18
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'
# if you start with a file of MARC records, you can convert them to a text file using yaz-marcdump
yaz-marcdump records.mrc > records.txt
# To edit the records on the command line, you can use vim (or whatever your favorite text editor is).
# When you’re done, to convert them back to MARC, use
yaz-marcdump -i line -o marc records.txt > edited-records.mrc
@pgwillia
pgwillia / setDiscardTitle.pl
Last active December 19, 2018 20:30
Jim's scripts for Symphony extract to Solr [Jul 9, 2018, 3:06 PM]
#!/u/sirsi/Unicorn/Bin/perl
system("echo \" \"");
system("echo Find Call Number Shadow Status");
@callShad = `cat sorted_adds | selcallnum -iC -oK2`;
open(SHAD,">allShadowed");
open(NSHAD,">noShadowCall");
$ckeyPrev = 0;
[16] pry(main)> icons = "\n \n 6665\n 165\n ualib-logo.png\n licensed for U of A\n https://www.library.ualberta.ca/about-u
s/policies/restricted-resource-info\n 11710698\n 6665\n \n \n \n 15484\n 165\n cou-user.png\n User Registratio
n Required\n https://www.library.ualberta.ca/about-us/policies/conditions-of-use/registration-required\n 11710698\n 15484\n \n \
n \n 15485\n 165\n cou-sign-in.png\n CCID Login Required\n https://www.library.ualberta.ca/about-us/policies/conditions-of-
use/restricted\n 11710698\n 15485\n \n \n "
=> "\n \n 6665\n 165\n ualib-logo.png\n licensed for U of A\n https://www.library.ualberta.ca/about-us/policies/restricted
-resource-info\n 11710698\n 6665\n \n \n \n 15484\n 165\n cou-user.png\n User Registration Required\n htt
ps://www.library.ualberta.ca/about-us/policies/c