Skip to content

Instantly share code, notes, and snippets.

@rsinger
rsinger / file-input
Created November 4, 2013 16:59
Webkit file inputs style to look more or less like other form buttons
input[type="file"]::-webkit-file-upload-button {
-webkit-appearance: button;
padding:7px;
font-size: smaller;
}
for f in *.dat ; do echo "Processing $f" ; yaz-marcdump -f MARC-8 -t UTF-8 -o marc -l 9=97 $f > ../loc_utf8_records/$f ; cd ../loc_utf8_records ; gzip $f ; cd ../loc_records ; done
@rsinger
rsinger / method_missing.rb
Created May 31, 2012 17:45
method_missing example
class Foo
def method_missing(method_name, *args)
# method_name is a symbol
if method_name.to_s =~ /^find_by_/
self.find_by_magic_method(method_name, args)
elsif method_name.to_s =~ /^other_dynamic_method_/
self.do_other_dynamic_method(method_name, args)
end
# If we get here, we'll get a NoMethodError
end
@rsinger
rsinger / record.mrc
Created May 29, 2012 13:17
Record that seems to cause the LinkedList error
<record xmlns="http://www.loc.gov/MARC21/slim">
<leader>00488nam a2200193 4500</leader>
<controlfield tag="001">vtls002817361</controlfield>
<controlfield tag="003">WlAbNL</controlfield>
<controlfield tag="005">20060313054800.0</controlfield>
<controlfield tag="008">060313 || | ||| d</controlfield>
<datafield tag="016" ind1=" " ind2=" ">
<subfield code="a">FREPO</subfield>
</datafield>
<datafield tag="020" ind1=" " ind2=" ">
# to get the field as a string, without the tag and indicators
# useful in situations where you want a legible version of the field
#
# print record['245'].value
def value(delim='')
return(@subfields.map {|s| s.value}.join(delim))
end
@rsinger
rsinger / jcode19.rb
Created October 10, 2011 15:50
Dealing with jcode in 1.9
if RUBY_VERSION < '1.9'
$KCODE = 'u'
require 'jcode'
end
DB.create_table :journals do
primary_key :id
string :title, :size=>1024, :index=>true
string :issn, :size=>8, :index=>true
string :e_issn, :size=>8, :index=>true
text :journal_url
text :publisher
require 'httparty'
require 'rdf'
require 'rdf/ntriples'
require 'rdf/nquads'
require 'json'
class Fuseki
include HTTParty
headers 'Accept' => 'text/plain; charset=utf-8'
base_uri 'http://localhost:3030/'
class DbConnection
require "jruby"
attr_reader :conn
require 'jdbc/sybase-jconnect-5.5.jar'
@@connection = nil
def initialize
java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader)
import java.sql.Statement
import java.sql.Connection
import java.sql.SQLException
@rsinger
rsinger / gist:955704
Created May 4, 2011 18:19
threach error
bash-3.2$ jruby -J-Djruby.thread.pooling=true openlibrary_modeler-rdf.rb ~/tmp/ol_dump_2011-04-30.txt.gz /Volumes/External/storage/openlibrary/
3007
6014
9021
12028
15035
#<ThreachDone:0x145d424>
ThreachDone: all_threads_done
to_ntriples at /usr/local/Cellar/jruby/1.6.1/jruby/lib/ruby/gems/1.8/gems/rdf-0.3.1/lib/rdf/ntriples.rb:101
to_ntriples at openlibrary_modeler-rdf.rb:689