Skip to content

Instantly share code, notes, and snippets.

View kardeiz's full-sized avatar

Jacob Brown kardeiz

View GitHub Profile
@kardeiz
kardeiz / gist:3419688
Created August 21, 2012 21:42
Convert some Dublin Core XML from DigiTool to CSV with Ruby
#!/usr/bin/env ruby
# encoding: utf-8
require 'active_support/core_ext'
require 'pp'
require 'csv'
require 'nokogiri'
dc_terms = [ :contributor, :coverage, :creator, :date,
:description, :format, :identifier, :language,
@kardeiz
kardeiz / gist:3542022
Created August 30, 2012 21:46
Ugly code to get rough CSV into wrapped EAD XML chunks
#!/usr/bin/env ruby
# encoding: utf-8
require 'csv'
require 'pp'
require 'active_support/core_ext'
require 'nokogiri'
f = nil; File.open('/home/jhbrown/Dropbox/kaye.csv') do |file|
@kardeiz
kardeiz / gist:3553858
Created August 31, 2012 14:43
Replace curly quotes and other ugly MS Word conversions
# thanks to http://www.andornot.com/blog/post/Replace-MS-Word-special-characters-in-javascript-and-C.aspx
class UglyCharGsubber
# To replace characters in a string and return the substitution string
def self.replace(text)
text.
gsub(/[\u2018|\u2019|\u201A]/, "\'").
gsub(/[\u201C|\u201D|\u201E]/, "\"").
gsub(/\u2026/, "...").
@kardeiz
kardeiz / gist:3645223
Created September 5, 2012 21:33
some really bad google apps js code just for reference
function jbtest(a, b) {
var ss = SpreadsheetApp.getActiveSheet();
var rangeall = ss.getDataRange();
var rangeb = ss.getRange(ss.getLastRow(),1,1,ss.getLastColumn());
//rangeb.setBackgroundColor("#CC6666");
//var valyus = rangeb.getValues();
//Browser.msgBox(valyus[0][1]);
Browser.msgBox(hex_md5("message digest"));
}
@kardeiz
kardeiz / gist:3691648
Created September 10, 2012 15:44
get source, etc. from DigiTool objects. Check against CSV and update matches
#!/usr/bin/env ruby
require 'nokogiri'
require 'csv'
def get_stuff_from_dc(file)
ret_values = {}
my_xml = Nokogiri::XML(File.read(file))
# I know these rescue nils are bad but I don't know a more efficient way
ret_values[:pid] = my_xml.at_xpath('//xb:digital_entity/pid/text()', "xb" => "http://com/exlibris/digitool/repository/api/xmlbeans").content rescue nil
@kardeiz
kardeiz / gist:3694401
Created September 10, 2012 22:19
Batch editing with DigiTool Web Services
#!/usr/bin/env ruby
require 'nokogiri'
require 'csv'
require 'savon'
Savon.configure do |config|
config.log = false
end
HTTPI.log = false
@kardeiz
kardeiz / gist:3751638
Created September 19, 2012 19:19
Fix for ActiveRecord::Relation not including ORDER BY columns in SELECT statement
# Fix for ActiveRecord::Relation not including ORDER BY columns in SELECT statement (in PostgreSQL)
# e.g., ActionView::TemplateError (PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
# Note: use at your own risk. This works on my data but your results may vary.
def add_order_values_to_select(arel_object)
my_order_values = arel_object.order_values.map do |x|
x = x.to_sql if x.respond_to? :to_sql
x.gsub(/ASC|asc|desc|DESC|"/,"").strip
end.reject(&:blank?)
@kardeiz
kardeiz / index.html
Created October 12, 2012 21:52
starting point for my labels...
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="https://raw.github.com/ZJONSSON/d3-plugins/master/force_labels/force_labels.js"></script>
<style>
.anchor { fill:blue}
.labelbox { fill:black;opacity:0.8}
.labeltext { fill:white;font-weight:bold;text-anchor:middle;font-size:16;font-family: serif}
.link { stroke:gray;stroke-width:0.35}
@kardeiz
kardeiz / index.html
Created October 15, 2012 15:06
starting point for my labels v.2
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="https://raw.github.com/ZJONSSON/d3-plugins/master/force_labels/force_labels.js"></script>
<style>
.anchor { fill:blue}
.labelbox { fill:black;opacity:0.8}
.labeltext { fill:white;font-weight:bold;text-anchor:middle;font-size:16;font-family: serif}
.link { stroke:gray;stroke-width:0.35}
@kardeiz
kardeiz / gist:3893099
Created October 15, 2012 15:29
get unique lines from files
#!/usr/bin/env ruby
my_files = Dir.chdir(ARGV[0]) { Dir.glob("./*").map{|x| File.expand_path(x) } }
def my_array_steamer(oldarr, newfile)
lines = (File.readlines(newfile)).map(&:strip)
oldarr | lines
end
my_arr = Array.new