Skip to content

Instantly share code, notes, and snippets.

View grosscol's full-sized avatar

Colin grosscol

View GitHub Profile
@grosscol
grosscol / SHSViking Date Comparisons
Last active August 29, 2015 14:18
A naive implementation of doing some counting after data logic for a list of dates and a given source data frame.
# Generate your list of dates
mydays <- seq.Date( as.Date('2015-01-01'), as.Date('2015-03-09'), by="day")
# Write function to sum the number of open dates that occur in sourceData at least 31 days prior to given date.
numOpenDates <- function( givenDate ){
retValue <- sum( (givenDate - sourceDate$openDate) > 30 )
retValue
}
# Apply function to each date in your list of dates(mydays)
@grosscol
grosscol / active-fedora 9 demo
Last active August 29, 2015 14:09
ActiveFedora9 persisting to Fedora4 beta
# Simple ActiveFedora9 (Fedora4) Example
# Make sure hyda-jetty, using the fedora-4/edge branch, is running (rake jetty:start)
require "active_fedora"
class Dum < ActiveFedora::Base
# The Hydra convention is to minimally have descriptive and rights metadata.
# The Fedora4 paradigm is to define properties directly on the object as opposed to the datastreams of Fedora3
property :title, predicate: ::RDF::DC.title
@grosscol
grosscol / copy_node_btw_docs
Last active August 29, 2015 13:55
Nokogiri copy node between documents and DOMException WRONG_DOCUMENT_ERR
require 'nokogiri'
# The following illustrates unexpected behavior of the Nokogiri::XML::Document.add_child method.
# When called from a new document, the behavior is different depending on if the argument
# is a newly created node or duplicate node.
# String of XML for Nokogiri to parse.
dummy_xml = '<?xml version="1.0" encoding="UTF-8"?>
<root>
<Dummy>Text1</Dummy>