Skip to content

Instantly share code, notes, and snippets.

Ant Kutschera maxant

Block or report user

Report or block maxant

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View read_xml_out_csv_model.json
{
"model": {
"input1.xml": {
"servlet1": {
"name1": "value1"
},
"servlet2": {
"name1": "value1",
"name2": "value2"
},
View read_xml_out_csv.ts
// npm install xml2js
// compile using "./node_modules/.bin/tsc read_xml_out_csv.ts -w"
// run using node read_xml_out_csv.js
const parseString: any = require('xml2js').parseString;
import * as fs from "fs";
const model = {}; // dictionary of dictionaries with filename -> servlet -> parameter name -> parameter value
const params = {}; // all params that are found (mapped to undefined)
const start = Date.now();
View read_xml_out_csv_example_output.csv
filename servlet name name1 name2
input1.xml servlet1 value1
input1.xml servlet2 value1 value2
input1.xml servlet3 value2
input2.xml servlet4 value4
View read_xml_out_csv_example_xml.xml
<?xml version="1.0"?>
<config>
<!-- 0..n servlets -->
<servlet>
<name>servlet1</name>
<!-- 0..n name-value pairs -->
<param-name>name1</param-name>
<param-value>value1</param-value>
@maxant
maxant / Main.scala
Last active Nov 6, 2017
Scala version of read_xml_out_csv.py
View Main.scala
/*
* built using Scala 2.12.4 in intellij
* prerequisites: add library for org.scala-lang.modules:scala-xml_2.12:1.0.6
*/
package ch.maxant.readxmloutcsv
import java.io.{File, PrintWriter}
import scala.xml.XML
import java.lang.System.{currentTimeMillis => now}
View read_xml_out_csv.py
# prerequisites:
# https://github.com/stchris/untangle/blob/master/examples.py
# C:\temp>c:\Python27\Scripts\pip.exe install untangle
# run: C:\temp\read_xml_out_csv>c:\Python27\python.exe read_xml_out_csv.py
import untangle
import os
import time
def now():
return time.time()*1000.0
View AsyncServlet5.java
@Resource UserTransaction ut;
@Override
protected void doGet(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
ut.begin();
...
CompletableFuture<String> cf = new CompletableFuture<>();
service.foo(cf, pw);
...
View Service5.java
@Stateless
public class Service5 {
@Resource ManagedExecutorService mes;
@Resource EJBContext ctx;
@PersistenceContext(name="asdf") EntityManager em;
@Asynchronous
public void foo(CompletableFuture<String> cf, final PrintWriter pw) {
View Client.java
//type 1
Future<String> f = service.foo(s);
String s = f.get(); //blocks the thread, but at least others can run
//... do something useful with the string...
//type 2
Future<String> f = service.foo(s);
while(!f.isDone()){
try {
Thread.sleep(100);
View Service2.java
@Stateless
public class Service2 {
@Asynchronous
public Future<String> foo(String s) {
// simulate some long running process
Thread.sleep(5000);
s += "<br>Service2: threadId=" + Thread.currentThread().getId();
return new AsyncResult<String>(s);
You can’t perform that action at this time.