Skip to content

Instantly share code, notes, and snippets.

public static String format(String unformattedXml) {
try {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
writer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
LSOutput output = impl.createLSOutput();
ByteArrayOutputStream out = new ByteArrayOutputStream();
output.setByteStream(out);
@liyuntao
liyuntao / build fat jar.gradle
Last active August 29, 2015 14:15
build a fat jar with all dependency inside with Gradle
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.mkyong.DateUtils'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task createJavaProject << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs()}
}
@liyuntao
liyuntao / TowersOfHanoi.scala
Created January 27, 2017 04:58 — forked from jrudolph/TowersOfHanoi.scala
Scala-Metaprogramming: Towers of Hanoi
/*
* This is the Towers of Hanoi example from the prolog tutorial [1]
* converted into Scala, using implicits to unfold the algorithm at
* compile-time.
*
* [1] http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_3.html
*/
object TowersOfHanoi {
import scala.reflect.Manifest
@liyuntao
liyuntao / gist:ac74d553fc296c3aa4b26eae15a870f2
Created April 18, 2017 09:26 — forked from levicook/gist:4132037
modeling friends and calculating mutual friends w/ mongodb
// ------------------------------------------------------------------
// Friend collection, where _id is a user.Id and Friends is a list, of user.Id.
// Note: friending and unfriending is a two step operation in this scheme:
> db.friends.find()
{ "_id" : 1, "friends" : [ 2, 3, 4 ] }
{ "_id" : 2, "friends" : [ 1, 3, 5 ] }
{ "_id" : 3, "friends" : [ 1, 2, 4, 5 ] }
{ "_id" : 4, "friends" : [ 1, 3, 5 ] }
{ "_id" : 5, "friends" : [ 2, 3, 4 ] }
@liyuntao
liyuntao / ldap-client.js
Created June 29, 2017 15:14
simple ldap-client in js
const ldap = require('ldapjs');
const Promise = require("bluebird");
class LDAPClient {
constructor(ldap_url, ldap_user, ldap_pwd, ldap_base_dn) {
this.ldap_url = ldap_url;
this.ldap_user = ldap_user;
this.ldap_base_dn = ldap_base_dn;
this.domain = this._getDomain(ldap_base_dn);
@liyuntao
liyuntao / docker-compose.yml
Created July 1, 2017 17:45
rancher with external mysql(docker-compose)
version: '2'
services:
rancher-server:
image: 'rancher/server:stable'
container_name: rancher-server
restart: always
volumes_from:
- rancher-db
ports:
- "8080:8080"
import java.util.ArrayList;
import java.util.function.Predicate;
public class User {
private String name;
private String email;
public String getName() {
return name;
@liyuntao
liyuntao / TcpDiscoveryRancherIpFinder.java
Created March 17, 2018 16:24
Apache Ignite discovery for Rancher
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.spi.IgniteSpiException;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@liyuntao
liyuntao / VisualisationMetricHandler.kt
Created April 15, 2018 02:58
first tmp version for Promviz
const val UPSTREAM_SERVICE_NAME_HEADER = "x-client-name"
class VisualisationMetricHandler : Handler<RoutingContext> {
val httpGauge = Gauge.build()
.name("status:http_requests_total:rate5m")
.help("Requests per 5m")
.labelNames("service", "client", "status")
.register()