Java EE course

I have been teaching a class on Java EE at the University of Technology Sydney. The subject is called “Advanced Internet Programming”.

The videos, guided practical sessions and sample solutions are now available online.

The materials cover HTTP, Servlets, JavaServer Pages, JavaServer Faces, database connectivity (JDBC), naming (JNDI), dependency injection (CDI), Enterprise JavaBeans, object-relational mapping (JPA), web services (JAX-WS and JAX-RS), asynchrony and message driven beans.

(Published 4 November 2016)

Answer Set Programming in Python

Potassco is an Answer Set Solving system. There is a native library for embedding Answer Set Solving in Python. However, the library does not work under Windows.

Fortunately, the Potassco tools can output data in JSON format. One integration option is to invoke the compiled binary directly. The PyASP Python library uses this strategy.

The same effect can be achieved in just a few lines of code:

import subprocess
import json

clingo_path = 'path\\to\\bin\\clingo.exe'
clingo_options = ['--outf=2','-n 0']
clingo_command = [clingo_path] + clingo_options

def solve(program):
    input = program.encode()
    process = subprocess.Popen(clingo_command, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    output, error = process.communicate(input)
    result = json.loads(output.decode())
    if result['Result'] == 'SATISFIABLE':
        return [value['Value'] for value in result['Call'][0]['Witnesses']]
        return None

Note that the clingo_path (the third line) must be set appropriately.

The output is a list of solutions, each solution is a list of strings corresponding to terms that the ASP solver could prove.

Suppose this library is named, it may be used as follows:

import asp

solutions = asp.solve('1 { a; b } 1.')
# Print out the solutions
# Output: [['b'], ['a']]

(Published 11 June 2016)

Simple Solar Model

Here is a very simple tool to calculate the sun’s position in the sky. It uses a minimal model based on a few orbital parameters. Despite its simplicity, it makes predictions that are very close to more complete models.

The tool is inspired by a recent discussion I had with somebody who claims the world to be flat. He seemed otherwise sane but he genuinely believed modern science to be a lie.

I was shocked and upset for days. Not only is it a rejection of our amazing technological progress but also it represents a failure of science and engineering education.

Continue Reading (Published 8 January 2016)

Published 1 January 2016 by Benjamin Johnston.