Skip to content

Instantly share code, notes, and snippets.

View kardeiz's full-sized avatar

Jacob Brown kardeiz

View GitHub Profile
@kardeiz
kardeiz / gist:1723883
Created February 2, 2012 15:07
xslt for concatenating multiple xml files
<!-- Option 1: Use an index XML file to list file names to be combined. Transform that XML file (root: files) with this XSL. -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xml>
<xsl:for-each select="files/file">
<xsl:copy-of select="document(.)/xml/*"/>
</xsl:for-each>
</xml>
</xsl:template>
</xsl:stylesheet>
@kardeiz
kardeiz / gist:1723916
Created February 2, 2012 15:13
powershell script to combine multiple xml files
# See best option below
# Option 1: Simple, but breaks with "xml" element
# based on an answer posted on stackoverflow by user "Start-Automating"
# see http://stackoverflow.com/questions/2972264/merge-multiple-xml-files-into-one-using-powershell-2-0
$files = get-childitem "full path to parent directory"
$finalXml = "<xml>"
foreach ($file in $files) {
[xml]$xml = Get-Content $file.fullname
$finalXml += $xml.xml.InnerXml
}
@kardeiz
kardeiz / gist:1781007
Created February 9, 2012 16:43
powershell script to harvest all DC metadata from OAI server. returns xml and csv files
# define the oai server and base request string
$baseurl = "http://digitalrepository.smu.edu/cgi/oai2.cgi/OAI-script?"
$payload = "verb=ListRecords&metadataPrefix=oai_dc"
# set up the webclient to grab the xml. some servers reject oai-pmh requests with no user-agent specified
$wc = New-Object System.Net.WebClient
$wc.Encoding = [Text.Encoding]::UTF8
$wc.Headers.add("User-Agent", "PowerShell Script")
# set the first request and load the xml into variable. note: this assumes server response is xml
@kardeiz
kardeiz / gist:2998621
Created June 26, 2012 20:17
jQuery AJAX call to show computer lab availability feed
// Do everything inside AJAX call
$.ajax({
url: "https://restapi.tcu.edu/labs/labs.jsonp",
dataType: "jsonp",
jsonp: false,
// Custom callback required due to hardcoded server callback variable
jsonpCallback: "labsCallback",
success: function(data) {
newarr = [];
// Get data, frame, and push to empty array
@kardeiz
kardeiz / gist:3006106
Created June 27, 2012 19:09
Generic user story collection tool using Twitter Bootstrap, Select2, and Google Forms
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>User story collection tool</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
@kardeiz
kardeiz / gist:3043781
Created July 3, 2012 22:19
Excel VBA: t-test for summary results
Function ttest_from_sum(x As Range, y As Range, values As Range)
' Set up for dragging over names with lookup
' Change this to fit your needs
Set temp = values.Find(x.Value, LookIn:=xlValues)
avga = CDec(temp.Offset(1, 0).Value)
stda = CDec(temp.Offset(2, 0).Value)
numa = CDec(temp.Offset(3, 0).Value)
@kardeiz
kardeiz / gist:3177463
Created July 25, 2012 17:41
Generate simple sitemap for DigiTool archive
#!/bin/bash
for i in {1..50}
do
# ea=$(wget -O - --user-agent="botbotbot" "http://specoll.lib.tcu.edu/dtl_publish/$i/index.html" | grep -oh 'href="[0-9]*.html"' | grep -oh [0-9]*)
ea=$(cat "/exlibris/dtl/u3_1/dtle/apache/htdocs/dtl_publish/$i/index.html" | grep -oh 'href="[0-9]*.html"' | grep -oh [0-9]*)
for jj in $ea
do
ace="http://specoll.lib.tcu.edu/dtl_publish/$i/$jj.html"
if ! grep $ace "/exlibris/dtl/u3_1/dtle/apache/htdocs/sitemap.txt"
@kardeiz
kardeiz / gist:3363686
Created August 15, 2012 21:06
UMI ETD XML to MARCXML with Ruby
#!/usr/bin/env ruby
require 'nokogiri'
# where the files at
my_files = Dir.chdir(ARGV[0]) { Dir.glob("./*").map{|x| File.expand_path(x) } }
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
xml.collection(:xmlns => 'http://www.loc.gov/MARC21/slim') {
my_files.each do |my_file|
@kardeiz
kardeiz / gist:3373244
Created August 16, 2012 20:13
CRUD objects in a DigiTool repository
#!/usr/bin/env ruby
# encoding: utf-8
# please install these gems
require 'nokogiri'
require 'savon'
# define wsdl connection
client = Savon::Client.new do
wsdl.document = ""
@kardeiz
kardeiz / gist:3406777
Created August 20, 2012 19:06
Super simple date parser
# Toggle the comments below to switch between American/rational date parsing
require 'american_date'
require 'active_support/core_ext'
# require 'date'
class SimpleDates
def self.parse(mystring)
mystring = mystring.to_s.downcase.strip
# Date._parse likes '/' better than '-', I guess?