crud4playplugin

this plugin can be used to generate the boiler plate code to access a database and provide a rest api for it that offers create read update delete. I use Slick for the database access.

from the demo blog project for example

GET /tables/blog ( with optional query params sortBy and direction)

GET /tables/blog// (this queries database where = . You can also use optional query params sortBy and direction)

GET /tables/blog/

POST /tables/blog

PUT /tables/blog

DELETE /tables/blog/:blog_id

Note if GET / queries a timestamp it should be passes a long value not text representation

slick,controller and routes generated from single configuration file.

You have to create the database as well as configure it in application.conf

There are sample test projects under directory

https://github.com/bernardjason/crud4playplugin/tree/master/src/sbt-test/crudplugin

while a fuller project
https://github.com/bernardjason/tracking

which is deployed on Heroku here
https://bjason-tracking.herokuapp.com/#

vr

see https://github.com/bernardjason/daydream

libgdx and daydream vr

sample of using libgdx to produce dual display for VR headset, in this case Daydream View. Not a library so you can see camera displacement when rendering to offset one eye along with two render operations to a framebuffer followed by use of shader to alter final frame.

This is essentially standard libgdx, using a shader to handle lens distort, otherwise straight lines would be warped. The android version uses the handheld controller to move the player around the small world along with spacial audio, via the Google VR SDK. The code for this is just in the bespoke Android module.

While desktop version uses arrow keys and spacebar to move along with some basic stereo audio using libgdx apis.

For the HTML version there is a very basic use of device orientation to move player view, but without allowing movement. It looks possible to integrate Daydream handheld controller with HTML version, see https://github.com/mrdoob/daydream-controller.js though I’ve not tired it. HTML version was really to check project is as close as possible to being able to work on ios. Though like HTML version I don’t see official support for handheld controller. Got around full screen problem when viewed on browser but sound does not work on mobile browser as not driven by user interaction.

android

to build and deploy

./gradlew android:installDebug

to make just the apk ./gradlew android:assembleDebug

daydream apk debug build apk

Tilt controller to change direction. Touch the touchpad to move while click touchpad when close and looking directly at spinning cube to drop it. Press App button (immediately below touchpad) will re-centre controller.

desktop deploy

./gradlew desktop:run

./gradlew desktop:dist

daydream desktop jar

HTML deploy

./gradlew html:superDev ./gradlew html:dist

Try online daydream for browser

spiderzap

This is an augmented reality game developed with libgdx and scala. You must have a gyroscope on your smartphone. The aim is to kill the spiders dropping down, as well as stop the spiders making alien webs. You can get closer to the spiders by holding the bottom of the screen and walking. To fire press anywhere else apart from the bottom of the screen. The spiders will always keep coming.

The walking is simply implemented by checking vibrations of the phone and assuming if you hold the bottom of the screen then you are moving in the real world.

Cordova

I’ve created a small demo Cordova application for the browser and android here

https://github.com/bernardjason/cordovatictactoe

you can play from your browser with this link.
cordova browser

To try out the android version

git clone https://github.com/bernardjason/cordovatictactoe.git

cordova platform add browser --save
cordova platform add android --save
cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-dialogs
cordova plugin add cordova-plugin-splashscreen
cordova plugin add cordova-plugin-backbutton
cordova plugin save
cordova platform save

then to run browser version locally

cordova serve browser

or to deploy to android

cordova run android

to get the splash screen and logo into android build run

./copy.sh
I cannot get Cordova to pick this up from config.xml so this copy script places them in the correct directory for an android build.

plodder

you tube demo

This is a Play Framework application that stores markdown pages in a Sqlite database accessed using REST services.

The intention of the application is that it is deployed as a WAR file running alongside another web application. You can create notes about your application as you develop as well as keep those notes beside the application. I was inspired by poor documentation of webservices in a WSDL when I’m after are use cases for a webservice or something akin to a hello world that makes the usage of the service clear. This is also why I hooked in the SoapUI libraries so that I could import a WSDL and generated sample requests and responses. Also with a number of security caveats it is possible to also hit a “TryIt” button and call the webservice.

There is no accounting for multi user access to this application or security of any kind. What’s needed and not done yet is a facility to export the markdown documents in the Sqlite database and generate static pages.

I’m using the excellent javascript library https://github.com/chjj/marked to actually do the presentation work here.

building

I’ve checked in a demo Sqlite database with the code btw

clone the code, then

./activator run

Visit from a browser (tested with firefox and chrome)

http://127.0.0.1:9000/plodder/

deploying as a war


./activator war

then copy file plodder-1.0-SNAPSHOT.war to your application then make sure its context path is /plodder. There is an example application cxfdemo that uses plodder here.

create a page

Once running, I am assuming using activator run rather than as a WAR for now go to

http://127.0.0.1:9000/plodder/

From the top menu select “edit”

The next page shows the path that the page would be saved to, use /hello and the box on the left is where the markdown source goes. To create a new page hit the create button and to update an existing page use save. These 2 buttons equate to POST and PUT a page of markdown while there is a get to.

run time environment

Visit

http://127.0.0.1:9000/plodder/markdown/home

this accesses a home page for your application. If it doesn’t exist it creates a list of pages. There is no ability to edit pages now.

BEEB

Bernard’s Enterprise Edition Basic

Basic for the JVM. The github project at https://github.com/bernardjason/beeb allows a basic program to be developed and compiled to Java classes.

YouTube demo video

The project was/is a rough and limited attempt at implementing something like BBC Basic on the Java Virtual Machine. There are plenty of things missed out as well as a couple of extras like making it capable of being a webserver, database access and some JSON support.

I’ve included a version of the hangman program in the BBC user guide as well as a simple webserver that offers a blog writing to a database in BEEB basic.

play rest swagger and some google charts

I’ve got an article published in Linux Format issue 214 https://www.linuxformat.com/archivesabout Rest,Swagger and Play with a demo application using Google Charts to display a timeseries overtime. There are 2 demos, one tracking the share price of BT compared to FTSE 100 and the temperature difference between London and Darlington.

The share price information uses Yahoo’s YQL to query a source of stock quotes yahoo.finance.quotes.
stockprice_graph

The temperature information is available from Open Weather Map API
temperature_graph

The database for Play implementation is Sqlite. The play implementation is 2.4 as 2.5 was too fresh to support Swagger at the time. I wanted to show how easy it is to add Swagger annotations to a simple interface.
weather_api

Finally as it’s Play it was easy to deploy this to Heroku. Albeit changing the database from Sqlite to Postgres. See
https://secure-retreat-29275.herokuapp.com/

and the 2 charts

Source code is available here
https://github.com/bernardjason/rest-swagger-app

weather chart
stock chart

tictactoe swagger,oauth, jsf with cucumber and selenium

Added a project to github today

https://github.com/bernardjason/tictactoe

Screenshot3-Swagger UI - Google Chrome

There is a version running on heroku too see

swagger ui – http://bjason-tictactoe.herokuapp.com/swagger/swagger-ui.html

or the demo game
tictactoe – http://127.0.0.1:8080/swagger/home.xhtml

It’s a springfox swagger implementation of oauth using spring(with hibernate/h2), jsf, cucumber and selenium

Quick note, the tests use Selenium and are set to use Firefox and Chrome. See file JsfFeatureSteps.java in package bjason.swagger.jsf. Also note that to test Chrome at least I’ve had to include copies of chromedrive for Linux. You’ll need copies for other platforms from here https://sites.google.com/a/chromium.org/chromedriver/

The aim of the project was to look at a more recent copy of swagger than I’ve used before. Then to use JSF rather than the usual JSP. Finally I wanted to see the oauth feature built into swagger working. So the implementation features are built around my tool choice and what I wanted to see rather than best way to do it. Biggest “choice” being heavy use of javascript in JSF pages to call rest resources when I think I’d have done that on the backend in this case.

What does the game do? It just allows 2 players to have a game of tic tac toe. It doesn’t check who wins, so it isn’t finished. it just shows the use of a simple rest api.

Note the use of spring profile below, as default is to deploy to heroku (postgress) rather than in memory h2 db.

to run up to play tictactoe as well as see the swagger gui

mvnw clean spring-boot:run -Dspring.profiles.active=local

then visit http://127.0.0.1:8080/swagger/swagger-ui.html

or to play the game

http://127.0.0.1:8080/swagger/home.xhtml

Swagger requires a recent version of the browser, be that Chrome, Firefox or IE. The oauth functionality uses Object.assign which is added in ECMAScript 6th edition.

I’ve included the swagger-ui here, as I’ve tested this works, at least for my 2 browsers, Chrome and Firefox.

To run selenium tests

mvnw package -Dspring.profiles.active=local

selenium

test class JsfFeatureSteps.java sets up the use of 2 browsers. If you aren’t using Chrome or Firefox, or are a
non Linux 64 bit please visit http://www.seleniumhq.org/download/ to see links to the various third party drivers

you may need to change this entry if using windows
System.setProperty(“webdriver.chrome.driver”,
“./chromedriver.” + System.getProperty(“os.name”) + “.”
+ System.getProperty(“sun.arch.data.model”));

to simple reference the drive explicitly, e.g. System.setProperty(“webdriver.chrome.driver”,”chromedrive.exe”);

the test is setup to use 2 browsers, Chrome and Firefox. To change simply set these lines accordingly.
_chromePlayer2 = new ChromeDriver();
_firefoxPlayer1 = new FirefoxDriver();

I chose these browsers simply because they are the 2 I use for testing on my system.

TicTacToeController.java

this file creates the actual game resources. Using lots of swagger annotations it defines the interface alongside the implementation.
It is here that the rest api definitions have their scope’s defined as well. There’s a lot of annotations but the entire api is configured in one place,
then the actual code just implements the api functionality. The authorisation is specified here but actually implemented in CheckBearer.java.

CheckBearer.java

this class extends HandlerInterceptorAdapter and implements the check to ensure the token is valid. Massive cheat here as I use a
spring bean rather than call the check externally via a rest call or similar.
CheckBearer is added as an intercepter in HelloworldApplication..java

OauthController.java

this class implements the rest api’s to support oauth operations. It supports the GET that the tictactoe web app makes to get a token, along
with the POST create of a token that authorization/authorization_server.html uses before it redirects back to the calling tictactoe web app

authorization/authorization_server.html

this page is simply the simple page that the oauth provider implements, here you just enter an email address that isnt validated and it will then
create a token and allow a redirect back to the app using the specified redirect_uri

spring,h2/hibernate

the app is using h2 in memory db to store information about the game in progress.

HelloworldApplication.java

Sets up JSF servlet, adds a logging filter plus adds the CheckBearer for calls to the tictactoe rest resources.

<2h>WEB-INF/ faces-config.xml and web.xml

This is needed just to keep JSF happy. Otherwise not required.

cucumber

setup is via src/test/resources/bjason/swagger/jsf/jsf.feature, and classes CucumberJsfTest.java and JsfFeatureSteps. I’ve described the
scenarios for driving the GUI pages using selenium. Sorry no proper unit tests.

Screenshot6-Swagger UI - Google Chrome

Screenshot5-authorization page - Google Chrome

Screenshot4-authorization page - Google Chrome

Screenshot3-Swagger UI - Google Chrome

Screenshot2-Swagger UI - Google Chrome

Screenshot1-Swagger UI - Google Chrome

hole in one, demo android/dekstop scala game using libgdx

I’ve produce this very simple game

source code available here https://github.com/bernardjason/holeinone

I’ve pulled together some code I had to show how to put together something using libgdx and scala that can run on either desktop or android platform. I’ve not tried it with a Mac. This wont work with HTML flavour libgdx as it’s scala.

The game uses the arrow keys, mouse or screen press to move the gun. Press and hold the spacebar, mouse button or screen then release to fire a missile at the bouncing ball.

The intention of this code is something to pick the bones out of or use as a start for something else.

Things of note
file local.properties contains the location of the android sdk. So this needs to be changed to where you’ve installed it.

core/build.gradle has been changed to build scala source

class FlatTerrain extends class BaseTerrain. This class supports an uneven terrain as well as the simple flat terrain shown in the game.

class bernardcjason.gdx.basic.shape.Cuboid shows mapping parts of a texture to a cube. This is a change to the usual mapping of a texture shape which is
base

to a linear

terrain

For collision detection I’ve not used Bullet physics but rather sphere collision bernardcjason.gdx.basic.shape.CollideSphere.