Skip to main content

Posts

Converting from linear to logarithmic scale

A simple function useful to plot a logarithmic scale. Just provide it with the min and max values of the scale and the value you want to convert - and you'll get in return a value as it should be positioned on a logarithmic scale in the given range. public double toLogScale(double min, double max,double val) { double logmin = Math.log(min); double logmax = Math.log(max); double logscale = (Math.log(val)-logmin) / (logmax-logmin); return min+(max-min)*logscale; }

Ubuntu desktop in the cloud accessible with VNC

To create a Ubuntu desktop on Amazon EC2 that can be accessed by VNC I did the following steps: 1. Create 64-bit Ubuntu server instance 2. Install ubuntu desktop: sudo apt-get install ubuntu-desktop 3. Install x11vnc sudo apt-get install x11vnc 4. Install xvfb sudo apt-get install xvfb 5. Configure x11vnc sudo nano /etc/init/x11vnc.conf start on login-session-start script /usr/bin/x11vnc -xkb -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /var/log/x11vnc.log end script And you should also set a password for your vnc sessions: sudo x11vnc -storepasswd /etc/x11vnc.pass 6. Configure X server to use xvfb: (Add the xserver-command line) sudo nano /etc/lightdm/lightdm.conf [SeatDefaults] greeter-session=unity-greeter user-session=ubuntu xserver-command=/etc/X11/xinit/xserverrc (Replace the exec line) sudo nano /etc/X11/xinit/xserverrc #!/bin/sh #exec /us...

Exporting Kendo UI GRID to Excel with Java

This is a simple method of creating an Excel export function on your Kendo UI grid with a Java EE server. JS function to trigger Excel export In your web-page with the grid - insert this JS function. You should create a button or similar that calls this when you want to perform the export from the UI. function exportGridToExcel() { var grid = $("#grid").data("kendoGrid"); var currentPage = grid.dataSource.page(); var allPages = new Array(); for(var n=1;n<=grid.dataSource.totalPages();n++) { grid.dataSource.page(n); var view = grid.dataSource.view(); for(var x=0;x<view.length;x++) { allPages.push(view[x]); } } $("#excelExportGridData").val(JSON.stringify({"rows": allPages, "cols": grid.columns})); $("#exportToExcelForm").submit(); grid.dataSource.page(currentPage); } Hidden form and iframe You also nee...

IOS Java App (RoboVM) communicating with server (Versile)

Before you continue - check out the demonstration video: The demonstration uses RoboVM to build an IOS app (written in Java), and Versile  to create a server and provide communication between the app and server. Details of configuring Versile and RoboVM are not described here. Go to RoboVM website, and check my earlier Versile blog posts for more info. The source for the IOS app is based on the RoboVM example: import java.util.Date; import org.robovm.cocoatouch.coregraphics.*; import org.robovm.cocoatouch.foundation.*; import org.robovm.cocoatouch.uikit.*; import org.robovm.objc.block.VoidBlock; import org.robovm.rt.bro.Bro; import org.robovm.rt.bro.NativeObject; import org.robovm.rt.bro.annotation.Bridge; import org.robovm.rt.bro.annotation.Library; import org.versile.Versile; import org.versile.orb.entity.VProxy; import org.versile.reactor.url.VUrl; import org.versile.vse.VSEResolver; import org.versile.vse.util.VFunction; public class VersileRoboVM...

Remote service interaction with Versile and Groovy - Part 2

In the previous post I showed you how to connect two peers using Versile. In this post I'll show how to authenticate the party requesting the connection. Authentication in Versile is done by checking the public key received from the other party. Both sides can check the identity of the other side. Identity key pairs can be generated using Versile Decentral Identity ( VDI ), which in many ways is similar to SSH-keygen. Using VDI is as simple as usernames and passwords, but not having to share this with the other party increase security - and the keys can be exchanged privately between the two parties, no certificate authority needs to be involved. A Versile Decentral Identity can be generated from Groovy/Java as simple as this: VPrivateCredentials key = new VPrivateCredentials(VDecentralIdentity.dia(1024, 'versilegroovy', 'peter', 'asdfghjkl12345')) And we can print the public key: print new String(key.getKeyPair().exportPublicArmoredPkcs()) ...

Remote service interaction with Versile and Groovy - Part 1

Versile is a compact but powerful technology for remote service interaction. I will write a few blog posts about using this technology with Groovy . In fact the examples presented should be applicable for other JVM scripting languages as well as pure Java - since Versile Java is the only library needed here. Creating a class which methods can be exposed remotely is easy with Versile. Simply inherit the VExternal class and annotate the methods with the @Publish annotation: class Svc extends VExternal {     @Publish(show=true, ctx=false)  public String hello(String name) { return "hello "+name     }     } A few more lines of code is needed to put this service on the air, but before we get to that, I'll show you how to connect to it and call the hello method remotely: // Get remote object proxy = VUrl.resolve("vop://localhost/") // Call method on remote object print proxy.hello("Peter") That was easy? To be able to call the servi...

Accessing and modifying openoffice base databases from Java

I made a little tool that makes it real easy to access and modify openoffice databases from Java, without having to open oo-base. Here's a code snippet from the unit test: OpenOfficeBaseJPA instance = new OpenOfficeBaseJPA(new File("testdb/TestDatabase.odb")); EntityManager em = instance.createEntityManager(); Integer rowcount = (Integer) em.createNativeQuery( "select count(*) from \"PUBLIC\".\"TestTable\"") .getSingleResult(); em.getTransaction().begin(); em.createNativeQuery( "insert into \"PUBLIC\".\"TestTable\" (\"TestField\") values ('Testvalue')") .executeUpdate(); em.getTransaction().commit(); Integer rowcount2 = (Integer) em.createNativeQuery( "select count(*) from \"PUBLIC\".\"TestTable\"")   .getSingleResult(); assertTrue(rowcount+1==rowcount2); em.close(); instance.saveChanges(); Thread.sl...