Skip to content

Instantly share code, notes, and snippets.

View maxant's full-sized avatar

Ant Kutschera maxant

View GitHub Profile
@maxant
maxant / Buyer.java
Created December 24, 2014 22:47
Code for the Java trading engine solution
package ch.maxant.tradingengine.model;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ch.maxant.tradingengine.model.TradingEngine.Listener;
@maxant
maxant / market.js
Last active November 18, 2022 09:53
Files for creating a trading engine with Node.js.
// /////////////////////////////////////////////////
// this file contains all the classes related to a
// market.
// /////////////////////////////////////////////////
var log4js = require('log4js');
var logger = log4js.getLogger(require('path').basename(__filename, '.js'));
require('es6-collections');
var _ = require('underscore');
/**
{
"model": {
"input1.xml": {
"servlet1": {
"name1": "value1"
},
"servlet2": {
"name1": "value1",
"name2": "value2"
},
# 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
@maxant
maxant / Main.scala
Last active November 6, 2017 20:41
Scala version of read_xml_out_csv.py
/*
* 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}
<?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>
filename servlet name name1 name2
input1.xml servlet1 value1
input1.xml servlet2 value1 value2
input1.xml servlet3 value2
input2.xml servlet4 value4
// 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();
@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);
...
@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) {