Skip to content

Instantly share code, notes, and snippets.

View adamretter's full-sized avatar
🎩
Down the Code Mine

Adam Retter adamretter

🎩
Down the Code Mine
View GitHub Profile
@adamretter
adamretter / pedb.xml
Last active August 13, 2018 12:56
pedb example for Luca
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="pedb">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Database of persons</title>
</titleStmt>
<publicationStmt>
<ab/>
</publicationStmt>
<sourceDesc>
@adamretter
adamretter / Unzip.scala
Created June 15, 2018 09:52
Unzip with Cats Effect
import java.io.IOException
import java.nio.file.{Files, Path, StandardOpenOption}
import java.util.zip.{ZipEntry, ZipInputStream}
import cats.effect.{IO, Resource}
object Unzip {
@throws[IOException]
@adamretter
adamretter / AsymmetricalLockingExample.java
Created October 21, 2017 15:48
Potential design pattern for Asymmetrical lock release
import java.util.Optional;
import java.util.function.Supplier;
// See https://stackoverflow.com/questions/46864834/best-design-pattern-for-managing-asymmetrical-resource-use
public class AsymmetricalLockingExample {
public static void main(String args[]) throws Exception {
try (final ManagedRelease<Collection> mcol =
new ManagedRelease<>(getCollection("col1 name", LockMode.WRITE_LOCK))) {
@adamretter
adamretter / ant-show-deps.xqy
Created September 25, 2017 15:03
XQuery to display the dependencies tree of an Ant target
(:~
: XQuery to display the dependencies of an Ant target.
:
: There are two modes of operation:
: 1) Display all targets and immediate dependencies, specified by $project-file
: 2) Show a tree of a single targets dependencies, this happens when $target-name is set as well.
:
: External parameters:
: $project-file The initial Ant file to start parsing from (imports will be expanded)
: $target-name If specified we examine only a single target and produce a tree of all dependencies (recursively)
@adamretter
adamretter / .jdk1.8.jinfo
Created July 7, 2017 16:39 — forked from olagache/.jdk1.8.jinfo
Generate ".jdk1.8.jinfo" and "alternatives.sh" files to install java 8 using ubuntu alternatives.
alias=jdk1.8
section=non-free
jre servertool /usr/lib/jvm/jdk1.8/jre/bin/servertool
jre keytool /usr/lib/jvm/jdk1.8/jre/bin/keytool
jre java /usr/lib/jvm/jdk1.8/jre/bin/java
jre jcontrol /usr/lib/jvm/jdk1.8/jre/bin/jcontrol
jre rmid /usr/lib/jvm/jdk1.8/jre/bin/rmid
jre ControlPanel /usr/lib/jvm/jdk1.8/jre/bin/ControlPanel
jre rmiregistry /usr/lib/jvm/jdk1.8/jre/bin/rmiregistry
jre orbd /usr/lib/jvm/jdk1.8/jre/bin/orbd
package org.rocksdb;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
/**
* Created by aretter on 30/05/2017.
/*
* eXist Open Source Native XML Database
* Copyright (C) 2001-2011 The eXist-db Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
@adamretter
adamretter / CompTest.java
Created June 14, 2016 10:06
RocksDB 4.5.1 JNI Comparator Example
package comptest;
import org.rocksdb.*;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Created by aretter on 14/06/2016.
*/
public class CompTest {
@adamretter
adamretter / upload.scala
Created September 26, 2015 14:58
extract file from multipart-form-data
def storeUploadedFile(data: Source[ByteString, Any]): \/[Seq[Throwable], Future[DefaultPath]] = {
val tmpUpload = Path.createTempFile(prefix = "uploaded", dir = settings.TempDir, deleteOnExit = true)
try {
val os = new FileOutputStream(tmpUpload.jfile)
val sink = OutputStreamSink(() => os)
val f = data.runWith(sink).map(_ => tmpUpload)
f.onComplete { _ =>
info(s"Stored temporary uploaded PDF ${tmpUpload.path}")
os.close
@adamretter
adamretter / anon-recursion.xqy
Created September 18, 2015 14:01
Anonymous function recursion in XQuery
xquery version "3.0";
(:~
: Anonymous function recursion in XQuery
:
: @author Adam Retter <adam.retter@googlemail.com>
:)
let $factorialHelper := function($f, $x) {
if($x eq 0) then