Skip to content

Instantly share code, notes, and snippets.

View billdueber's full-sized avatar

Bill Dueber billdueber

View GitHub Profile

Install a skeleton Rails app with Hyrax

(from Seth Johnson)

$ ruby -v
    => ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linu

$ rails -v
    => Rails 5.0.2
# A simpler example: create an object which takes
# in a file name and allows you to iterate over
# only the comments (lines that start with '#')
#
# Obviously, it'd be pretty easy to do this inline, but it's just an
# example. One could also imagine it returning every set of
# contiguous comment lines as a single comment, or even being smart enough to
# do C-style /* ... */ comments and extract those.
#
# The point is that you've got that all hidden in a class, and the user
@billdueber
billdueber / taghosts
Created February 5, 2016 15:25
Modification to taghosts to list available tags
#!/usr/bin/env ruby
require 'optparse'
ACTIVE_SERVERS = '/l/local/active-servers'
def alltags
alltags = []
File.open(ACTIVE_SERVERS).each do |line|
tokens = line.split(/\s+/)
@billdueber
billdueber / marc_html.rb
Last active February 3, 2016 03:38
Simple render of a ruby MARC::Record with slim
# encoding: UTF-8
require 'slim'
require 'marc'
# Get a record somehow. Here, I just nab the marc-in-json from the HT catalog and use that.
require 'json'
require 'open-uri'
rec = MARC::Record.new_from_hash(JSON.parse(open('http://catalog.hathitrust.org/Record/100113248.json').read))
@billdueber
billdueber / emtest.rb
Last active August 29, 2015 14:26
Traject extract_marc default value
require 'traject'
include Traject::Macros::Marc21
r = MARC::Record.new
r << MARC::ControlField.new('001', '12345')
r << MARC::DataField.new('245', ' ', ' ', ['a', 'My Title'])
context = Traject::Indexer::Context.new
module A
def hello
puts "Hello from A"
end
def goodbye
puts "Goodbye from A"
end
end
class B
class A
include Enumerable
def each
(1..10).each do |i|
raise RuntimeError.new("SIX") if i == 6
yield i
end
end
end
@billdueber
billdueber / marc-threadedreader.rb
Created February 25, 2015 18:53
Threaded MARC Reader
require 'concurrent'
require 'thread'
require 'marc'
class MARC::ThreadedReader < MARC::Reader
include Enumerable
include Concurrent::Async
def initialize(file, options={})
super
@billdueber
billdueber / threaded_read.rb
Created February 25, 2015 17:33
Threaded MARC reads
require 'concurrent'
require 'thread'
require 'json'
require 'stringio'
require 'marc'
require 'benchmark'
# OK. Try to read in a line, and then have another thread transform it, and expose
# via #each.
@billdueber
billdueber / index.rb
Last active August 29, 2015 14:16
Unrolling traject ToFieldStep loop
require 'library_stdnums'
require 'traject/macros/marc21_semantics'
extend Traject::Macros::Marc21Semantics
require 'traject/macros/marc_format_classifier'
extend Traject::Macros::MarcFormats
require 'traject/solr_json_writer'
require 'traject/marc_reader'