Skip to content

Instantly share code, notes, and snippets.

View kardeiz's full-sized avatar

Jacob Brown kardeiz

View GitHub Profile
@kardeiz
kardeiz / gist:4323126
Created December 17, 2012 22:46
d3 fragments for stacked charts
<html>
<head>
<title>Sankey Diagram</title>
<script src="../assets/d3.v2.js"></script>
<script src="../assets/sankey.js"></script>
<script src="../assets/jquery-1.8.3.min.js"></script>
<script src="../assets/underscore.js"></script>
<script src="../assets/underscore.nest.js"></script>
<script src="../assets/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.js"></script>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
@kardeiz
kardeiz / cni12f.md
Created December 16, 2012 15:42
CNI Fall 2012 Meeting

CNI Fall 2012 Meeting


Website: Fall 2012 Meeting
Twitter: #cni12f

Disclaimer 1: These notes provide my perception and understanding of the CNI conference presentations. It is possible that errors were made in the reporting or that speaker statements have been inadvertently misrepresented.

@kardeiz
kardeiz / gist:3959343
Created October 26, 2012 15:12
Convert relative links to absolute in HTML
#!/usr/bin/env ruby
# encoding: utf-8
# This works pretty well, but can't yet go up dir tree
# Also doesn't work on JS generated hrefs/srcs
# I was surprised there wasn't a ready-made solution online (that I could quickly find)
require 'open-uri'
require 'nokogiri'
require 'active_support/core_ext'
@kardeiz
kardeiz / gist:3941080
Created October 23, 2012 19:40
d3 data array to summary object (e.g., "SELECT x, count(*) FROM y GROUP BY x")
// This may not be the most efficient way to do this, but it's pretty clean
var yourObject = d3.nest()
.key(function(d) { return d; })
.rollup(function(d) { return d.length; })
.map(yourArray);
// e.g.,
// var input = ["this","is","a","test","for","this","method"];
// var output = {"this":2,"is":1,"a":1,"test":1,"for":1,"method":1}
@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
@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 / 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 / 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 / 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: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