Skip to content

Instantly share code, notes, and snippets.

View eerohele's full-sized avatar

Eero Helenius eerohele

View GitHub Profile
@eerohele
eerohele / xmlpretty.sh
Created October 26, 2012 06:21
Prettify XML file in place.
#!/bin/bash
INPUT_FILE=$1
if [ -z $INPUT_FILE ]; then
echo "You have to give an input file."
exit 1
fi
# TODO: Add --stream if the file is bigger than n Kbytes.
@eerohele
eerohele / xfc.xml
Created November 6, 2012 14:49
Integrate XMLmind XSL-FO Converter into DITA-OT
<!-- plugin.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<plugin id="org.dita.ooxml">
<feature extension="dita.conductor.transtype.check" value="ooxml"/>
<feature extension="dita.conductor.target.relative" value="integrator.xml" type="file"/>
<feature extension="dita.conductor.lib.import" file="lib/xfc.jar"/>
</plugin>
@eerohele
eerohele / xfc.xml
Created November 8, 2012 07:54
XMLmind XSL-FO Converter Ant MacroDef (DITA Open Toolkit)
<?xml version="1.0" encoding="UTF-8"?>
<project name="xfc">
<macrodef name="xfc" description="XMLmind XSL-FO Converter">
<attribute name="inFile"/>
<attribute name="outFile"/>
<attribute name="outputFormat" default="docx"/>
<attribute name="prescaleImages" default="true"/>
<attribute name="singleSidedLayout" default="false"/>
@eerohele
eerohele / build.xml
Created November 9, 2012 12:22
Enabling support for saxon:line-number() when running Saxon via Ant
<xslt style="${xsl.stylesheet}" extension="${output.file.extension}" classpathref="classpath"
filenameparameter="input.file" out="${output.dir}${file.separator}${input.file.basename}"
in="${input.file}" destdir="${output.dir}" filedirparameter="input.dir" basedir="${input.dir}">
<factory name="net.sf.saxon.TransformerFactoryImpl">
<attribute name="http://saxon.sf.net/feature/linenumbering" value="true"/>
</factory>
</xslt>
@eerohele
eerohele / saxon.rb
Created November 19, 2012 17:19
Saxon XSLT transformation using JRuby
raise "You can only use #{__FILE__} with JRuby." unless RUBY_PLATFORM == "java"
require "java"
require "uri"
module XSLT
TRANSFORMER_FACTORY = "javax.xml.transform.TransformerFactory"
import "javax.xml.transform.TransformerFactory"
import "javax.xml.transform.Transformer"
import "javax.xml.transform.stream.StreamSource"
@eerohele
eerohele / install-ruby-1.8.5-ubuntu-rbenv.md
Created January 4, 2013 12:11
Installing Ruby 1.8.5 on Ubuntu with rbenv
  1. Install rbenv.

  2. Download and compile OpenSSL 0.9.8x:

     $ tar zxvf openssl-0.9.8x.tar.gz
     $ cd openssl-0.9.8x
     $ ./config
     $ make
     $ make test
     $ make install
    
@eerohele
eerohele / ant.java.lang.NullPointerException.markdown
Last active December 10, 2015 18:18
Apache Ant throws java.lang.NullPointerException

Apache Ant throws java.lang.NullPointerException

Scenario

Ant throws an error like the one below when you try to run it:

java.lang.NullPointerException
        at org.apache.tools.ant.launch.Locator.getLocationURLs(Locator.java:524)
        at org.apache.tools.ant.launch.Locator.getLocationURLs(Locator.java:475)

at org.apache.tools.ant.launch.Launcher.getUserURLs(Launcher.java:360)

@eerohele
eerohele / file-exists.xsl
Created January 14, 2013 17:56
Check whether a file exists with XSLT2 (a Java extension -powered function)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:java="http://www.java.com/"
exclude-result-prefixes="java xs">
<xsl:function name="java:file-exists" xmlns:file="java.io.File" as="xs:boolean">
<xsl:param name="file" as="xs:string"/>
<xsl:param name="base-uri" as="xs:string"/>
@eerohele
eerohele / fcd.sh
Created January 23, 2013 12:01
File count diff: show the difference in the number of files in two directories
fcd() { echo "$(($(ls -1 "$1" | wc -l) - $(ls -1 "$2" | wc -l)))" }
@eerohele
eerohele / factorial.js
Last active December 14, 2015 18:49
Factorial
var factorial = function (n) {
var a = [];
var calculate = function (n) {
if (n < 2) return 1;
if (a[n] > 0) return a[n];
else return a[n] = calculate(n - 1) * n;
};
calculate(n);