Skip to content

Instantly share code, notes, and snippets.

View BDF's full-sized avatar

Brian Forester BDF

View GitHub Profile
(clojure.contrib.str-utils/str-join "\n" (loop [s1 '((1 2 3) (4 5 6)) result '()]
(if (empty? s1)
result
(recur (rest s1) (conj result (clojure.contrib.str-utils/str-join "\t" (first s1)))))))
Babysitter Kata
Background
----------
This kata simulates a babysitter working and getting paid for one night. The rules are pretty straight forward:
The babysitter
- starts no earlier than 5:00PM
- leaves no later than 4:00AM
- gets paid $12/hour from start-time to bedtime
@BDF
BDF / gist:102891e882539e2a0e63
Created November 3, 2015 20:17
Clojure: Read an HTML resource and parse down to the text nodes with the following path ( /body/form/div[@id="qautil-display" )
(defn parse [src-to-parse]
(-> src-to-parse
(html/html-resource )
(html/select-nodes* #{[:body :form :div (html/attr= :id "qautil-display" ) html/text-node ]})
)
)
@BDF
BDF / validate-request.md
Last active November 13, 2015 14:14
A function to validate a request within the context of compojure application.

This code was written to validate a very simple map of the structure of {:body {:grepString "grepp" :date "2014-05-03" :environment "nightly"}

This snippet is not idiomatic clojure.

(defn validate-request [req]
  (let [json-vals (:body req)
        grepStr (:grepString json-vals)
        date (:date json-vals)
        env (:environment json-vals)
@BDF
BDF / gist:76255c60968fa6a4fedf
Last active November 17, 2015 19:38
Pass an xPath as parameter named 'xPathToContent' and evaluate/use that xPath
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="xPathToContent"/>
<xsl:template match="/">
<ol>
<!-- altova has an equivalent 'altova:evaluate' -->
<xsl:for-each select="saxon:evaluate($xPathThing)" xmlns:saxon="http://saxon.sf.net/">
<xsl:apply-templates/>
</xsl:for-each>
@BDF
BDF / XSLTSaxonFunctionExtension.java
Last active October 1, 2016 20:51
A very small example of using saxon:evaluate and saxon:linenumber(). I was having trouble getting the saxon:evaluate function to work correctly. The solution was very simple. When creating the processor pass in 'true' instead of 'false' (which is what most of the saxon examples use).
import net.sf.saxon.s9api.*;
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;
public class Main {
public static void main(String[] args) throws SaxonApiException {
String bookXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<books>\n" +
" <book category=\"reference\">\n" +
" <author>Nigel Rees</author>\n" +
@BDF
BDF / DeepEqualsWrapper.java
Created February 9, 2016 17:01
Code using net.sf.saxon.functions.DeepEqual.deepEquals to compare the equality of two XdmNodes. Very saxon specific. Is this the deepEquals method theadsafe?
import net.sf.saxon.Configuration;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.expr.sort.CodepointCollator;
import net.sf.saxon.expr.sort.GenericAtomicComparer;
import net.sf.saxon.functions.DeepEqual;
import net.sf.saxon.lib.UnfailingErrorListener;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.trans.XPathException;
@BDF
BDF / XsltServiceSaxonImpl.java
Last active October 1, 2016 20:50
Figuring out why saxon does not find license file in a Spring MVC application.
import net.sf.saxon.lib.FeatureKeys;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import org.springframework.stereotype.Service;
import javax.xml.transform.stream.StreamSource;
import java.io.IOException;
@BDF
BDF / mavenNotes.md
Last active March 8, 2021 12:21
Using the maven shade plugin on a Spring Boot application
  • Maven shade with Spring Boot

The goal was to create an uber-jar out of the Spring boot application. Following the directions given at Apache went very smoothly yet when I tried to execute the jar a large number of spring beans were missing and not getting loaded during runtime. For example, one of the beans not getting loaded was 'AutoConfigurationPackages'

jar -tvf name.jar | grep AutoConfigurationPackages showed that the class file was present in tha jar.