Skip to content

Instantly share code, notes, and snippets.

View jcoyne's full-sized avatar

Justin Coyne jcoyne

  • Stanford University Libraries
  • Minneapolis, MN
View GitHub Profile
# lib/hydra/derivatives/psu_video.rb
# This class must live in the Hydra::Derivatives namespace
class Hydra::Derivatives::PsuVideo < Hydra::Derivatives::Video
def codecs(format)
case format
when 'mp4'
"-vcodec libx264 -acodec libflaac"
require 'active_support'
require 'active_support/multibyte/unicode'
string = "有名人やアニメ、風景などいろいろな画像を探したいならYahoo!検索(画像)。サイズ別、色別での絞り込みが可能なだけでなく、スライドショー機能も搭載。加えて、今検索されているキーワードもリアルタイムでわかるので、話題の画像がチェックできます。"
require 'benchmark'
n = 1_000_000
Benchmark.bmbm do |x|
x.report("for:") { for i in 1..n; ActiveSupport::Multibyte::Unicode.tidy_bytes(string); end }
end
@jcoyne
jcoyne / downloads_controller_spec.rb
Created January 6, 2014 18:44
DownloadsController spec
require 'spec_helper'
describe DownloadsController do
let(:technote) { Technote.new("title" => "MyString") }
let(:user) {User.create!(email: '[email protected]', password: 'drowssap')}
before do
sign_in user
technote.read_users = [user.user_key]
technote.technoteContent.content = "My ds content"
technote.save!
-------------------------------------------------------------------------------
Test set: org.fcrepo.integration.http.api.FedoraTransactionsIT
-------------------------------------------------------------------------------
Tests run: 5, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.963 sec <<< FAILURE! - in org.fcrepo.integration.http.api.FedoraTransactionsIT
testCreateAndTimeoutTransaction(org.fcrepo.integration.http.api.FedoraTransactionsIT) Time elapsed: 0.617 sec <<< FAILURE!
java.lang.AssertionError: expected:<200> but was:<500>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:743)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:555)
ERROR 10:37:49.705 (velocity) VelocimacroProxy.render() : exception VM = #triples()
java.io.IOException: I/O error occurred
at org.glassfish.grizzly.http.io.OutputBuffer.handleAsyncErrors(OutputBuffer.java:895) ~[grizzly-http-2.3.6.jar:2.3.6]
at org.glassfish.grizzly.http.io.OutputBuffer.write(OutputBuffer.java:639) ~[grizzly-http-2.3.6.jar:2.3.6]
at org.glassfish.grizzly.http.server.NIOOutputStreamImpl.write(NIOOutputStreamImpl.java:83) ~[grizzly-http-server-2.3.6.jar:2.3.6]
at org.glassfish.grizzly.servlet.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:116) ~[grizzly-http-servlet-2.3.6.jar:2.3.6]
at com.sun.jersey.spi.container.servlet.WebComponent$Writer.write(WebComponent.java:307) ~[jersey-servlet-1.17.1.jar:1.17.1]
at com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:134) ~[jersey-server-1.17.1.jar:1.17.1]
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) ~[na:1.7.0_07]
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.j
Failure/Error: subject.content.should be_equivalent_to expected_xml
expected:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#">
<mads:ComplexSubject rdf:about="info:fedora/foo">
<mads:elementList rdf:parseType="Collection">
<rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"/>
<mads:TopicElement>
<mads:elementValue>Relations with Mexican Americans</mads:elementValue>
Failure/Error: FactoryGirl.create_generic_file(:generic_work, user) { |gf|
NoMethodError:
undefined method `[]' for nil:NilClass
# /Users/justin/.rvm/gems/ruby-2.0.0-p247@curate/gems/active-fedora-6.4.5/lib/active_fedora/delegating.rb:26:in `array_reader'
# /Users/justin/.rvm/gems/ruby-2.0.0-p247@curate/gems/active-fedora-6.4.5/lib/active_fedora/delegating.rb:13:in `[]'
# /Users/justin/.rvm/gems/ruby-2.0.0-p247@curate/gems/sufia-models-3.1.1/lib/sufia/models/generic_file/web_form.rb:12:in `block in remove_blank_assertions'
# /Users/justin/.rvm/gems/ruby-2.0.0-p247@curate/gems/sufia-models-3.1.1/lib/sufia/models/generic_file/web_form.rb:11:in `each'
# /Users/justin/.rvm/gems/ruby-2.0.0-p247@curate/gems/sufia-models-3.1.1/lib/sufia/models/generic_file/web_form.rb:11:in `remove_blank_assertions'
# /Users/justin/.rvm/gems/ruby-2.0.0-p247@curate/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:407:in `_run__1889905316430041141__save__callbacks'
# /Users/justin
# Do you prefer option 'A'
makes_derivatives_of :content, when: :mime_type, is: 'application/pdf',
derivatives: { :thumb => "100x100>" }
makes_derivatives_of :content, when: :mime_type, is: 'audio/wav',
derivatives: { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processors: :audio
makes_derivatives_of :content, when: :mime_type, is: 'video/avi',
derivatives: { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processors: :video
[:ffmpeg_path, :libreoffice_path, :temp_file_base, :fits_path, :enable_ffmpeg].each do |method|
module_eval <<- RUBY
def #{method.to_s}
puts 'hey'
end
RUBY
end
/Users/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require': /Users/justin/workspace/hydra-derivatives/lib/hydra/derivatives.rb:26: syntax error, unexpected tSTRING_BEG, expecting ';' or '\n' (SyntaxError)
makes_derivatives_of :content, based_on: :mime_type, when: 'text/pdf',
{derivatives: { :text => { :quality => :better }, processors: [:ocr]}}
makes_derivatives_of :content, based_on: :mime_type, when: ['image/png', 'image/jpg'],
{ derivatives: { :medium => "300x300>", :thumb => "100x100>" }}