This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def randomize(str) | |
vowels = ['a','e','i','o','u'] | |
consonants = ('a'..'z').to_a - vowels | |
digits = ('0'..'9').to_a | |
replacements = {} | |
[vowels, consonants, digits].each { |set| | |
order = set.sort { rand(2) == 0 ? -1 : 1 } | |
set.each_with_index { |char,i| replacements[char] = order[i] } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'oai/provider' | |
class SolrProvider < OAI::Provider::Base | |
# Implement the provider here | |
end | |
get '/oai' do | |
content_type :xml | |
SolrProvider.new.process_request(options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
method user system total real | |
.find 19.770000 1.130000 20.900000 ( 80.396740) | |
.load_instance 19.500000 1.400000 20.900000 ( 78.594387) | |
.load_instance_from_solr 2.130000 0.280000 2.410000 ( 10.900572) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def structure_from_solr(solr_doc, prefix) | |
prefixed_fields = Hash[solr_doc.select { |k,v| k =~ /^#{prefix}_\d+_/ }] | |
result = {} | |
prefixed_fields.each_pair do |path_str,value| | |
h = result | |
path = path_str.sub(/_[^_]+$/,'').reverse.split(/_(?=\d+)/).collect { |k| k.reverse }.reverse.collect { |k| k.split(/_(?=\d+)/) } | |
path.each do |step, index| | |
if index.nil? | |
h[step.to_sym] = value | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.8.7 :009 > Blacklight.solr.class | |
=> RSolr::Client | |
1.8.7 :010 > Solrizer::Fedora::Indexer.new.solr.class | |
=> RSolr::Client | |
1.8.7 :011 > ActiveFedora::SolrService.instance.conn.class | |
=> Solr::Connection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Nokogiri::XML::Document | |
def prettify | |
xslt = Nokogiri::XSLT <<-EOC | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output omit-xml-declaration="yes" indent="yes"/> | |
<xsl:template match="node()|@*"> | |
<xsl:copy> | |
<xsl:apply-templates select="node()|@*"/> | |
</xsl:copy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveFedora::Config::FileSystem | |
def self.init *args | |
# Find files, identify environments, etc., but don't actually | |
# reach back into ActiveFedora and change anything | |
end | |
def self.fedora_config | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.fedora | |
if config.sharded? | |
raise "Cannot use ActiveFedora.fedora() in a sharded configuration. Use ActiveFedora::Base.connection_for_pid(pid) instead" | |
else | |
@@fedora_connection ||= RubydoraConnection.new(config.credentials) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/core_ext' | |
require 'tzinfo' | |
require 'time' | |
# Uses a year's worth of GMT offsets from Time.now to guess the | |
# closest local time zone within the country specified | |
def guess_local_timezone(country='US') | |
offset = Time.now.gmt_offset | |
zones = TZInfo::Country.get(country).zone_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.8.7 :003 > s = 'HTML & stuff' | |
=> "HTML & stuff" | |
1.8.7 :004 > s.html_safe? | |
=> false | |
1.8.7 :005 > m = Marshal.load(Marshal.dump(s)) | |
=> "HTML & stuff" | |
1.8.7 :006 > m.html_safe? | |
=> false | |
1.8.7 :007 > h = s.html_safe | |
=> "HTML & stuff" |