The mac pro 2019 edition with ARM-support

Current mac pro 2013 edition.

Apple released the now famous trash can macpro in 2013 that was supposed to serve the pro-community well for the years to come.

It did badly. In Apples own terms they painted them selves into a thermal corner. Around that time they seemed to have lost interest in the Intel-hardware-line.

But the ipad-device did not mature the way Apple had envisioned so they began to invest more in the mac-hardware some years after the trash can failure.


The imac pro 2017 edition.

Late 2017 Apple released a pro-version of the imac with xeon-cpu’s, ECC-ram, ssd-only storage. That packed a lot of power into the imac-enclosure. They also promised a new mac pro would see the light in 2019.


The mac pro 2019 edition. With ARM-support.

Apple have taken it’s time to design this mac pro so it can stand out as the obvious choice for the pro-user. It will retain the Intel Xeon to accomodate current software used by pro-users. It will  be more expandable than the trash can, more space inside so a return to some sort of tower model.

But to withstand the wear and tear of time it must also serve the needs five years from now. And being more expandable and upgradable I think it will have support for the ARM-cpu.

This way Apple can serve it’s current users while also paving the way for the expected ARM-transition that the mac-lineup will go through.

One way to solve this is with hardware-virtualization so both the Intel- and the ARM-cpu can run at the same time. This will require a lot of ressources from Apple. Another way to handle this is by choosing what architecture to boot when the mac pro is powered on.


Parsing XML in C++ the wrong way

I was approached by the IT-guy from the local ski-resort where I live and asked if I could integrate weather readings from the Norwegian Public Roads Administration. They have many sites where they collect temperature, dew-point, snow-depth, wind etc. And one is conveniently placed just across the road 100 meters away. It sends data every 10 minutes.

The data could be downloaded using curl so it was very simple to get it. Curl is written in C, and Jean-Philippe Barrette-LaPierre have written a nice C++ wrapper.

The weather data is in XML and I first thought of using RapidXML or LixXML2 but since I only needed weather data from one location I ended up with a very basic search-string that uniquely identifies the beginning and end of the XML-data from that particular weather station. That is not very bulletproof if the id changes, some fields are moved around or other changes to the data.

When I first get the site I then get the temperature, wind, snow-depth etc. and parse it into a double. This is then inserted into a postgresql-database. Every 10 minutes a cronjob then download the latest entries from the database and save it to a text-file. The text-file is then downloaded and parsed using the javascript-graph-utility Dygraph and the weather data can be seen at Breimsbygda Skisenter albeit 10-20 minutes delayed.


Apple’s support for the HEIF format in ios 11 and high sierra

HEIF stands for High Efficiency File Format and have been around for quite a while. It was developed by the Moving Pictures Experts Group (MPEG). It basically shows the same image using almost half the space compared to a JPEG-equivalent.

With iPhone 7 and newer and ios 11 you have the option to shoot photos using a space saving (HEIF) or more compatible (JPEG) format.

A few days ago I received a iPhone 8 and took an image in both formats. The HEIC image is 2.6 MB and the JPEG 4.9 MB. Both sizes in metric (base ten). So almost half the size in this case. The savings in size will vary according to the image taken but takes up a lot less space.

If you want to test the size reduction I have a site that can convert your JPEG images to HEIF. The server is written in Golang and hosted on Digital Ocean. Source code of course at Github.

Take care!


Oracle’s MOOC on Lambdas and streams

At the end of November I saw a post on Reddit about Oracle having a MOOC (Massive Open Online Course) on lambdas and streams in December 2016. I signed up and was enrolled. It was divided into three lessons starting in December, one lesson a week. At the end of each lesson there was a test.

Instructor Simon Ritter was very good at covering the subjects. The first lesson introduces lambda expressions, why it was added to Java 8, what problems it intends to solve. Then the syntax is described and basic usage.

One example is a list converted to uppercase:

List<String> myList = ...
myList.replaceAll(s -> s.toUppercase);

So instead of manually creating a loop to iterate over the list and convert each element it is now told what to do. This small example is of course a bit contrived but shows the essence of lambda expressions.

Lesson two introduces the streams api and functional programming concepts. It “allows functions to be treated as values” and is the reason “Lambda expressions were required in JDK 8” (page 9).

One or more stream operations can be chained together. The last operation is a terminal operation.

List<String> l = Arrays.asList("a", "b", "c");

List<String> r =;

Lesson three covers streams in more detail. Streams can be serial or parallel. If an element in the source input is computational intensive it can be beneficial to parallelize the stream but it also incurs some overhead. This lesson have some tips on how and when to convert a streams to either serial or parallel.

This course by Oracle is recommended when a person like me knows “something” about lambdas and streams and have begun to explore them but still would like to know more when and where it can be put to work in an efficient manner.

Add unit test to Spring Boot

As a project grows testing becomes more vital. It’s easy to perform these test manually when you have just begun (I’m looking at myself) and repeat and enhance these as the code evolves.

But sooner or later unit test will add structure to your tests, save time and maybe uncover some bugs or other errors. I found one that is not an error as such but a result of how Spring Boot parses the last part of a rest-endpoint and it did lead to imprecise results. The reason is that when Spring Boot encounters a dot (.) it considers this a file-extension. Thanks to the good folks at Stackoverflow this thread have some solutions. I decided to implement the solution Dave Syer suggested.

I’m passing latitude and longitude in the rest-api as a decimal number and Spring Boot would initially interpret longitude with a value 6.3968833 as 6 because it discarded anything after the decimal point. And this move westward is not desired.

This post is a continuation of my rest-api post where I show how to query a database for cities/locations within a radius. The source code for this project can be found here.

Back to unit test. Spring Boot integrates nicely with JUnit, and JUnit integrates nicely with the Eclipse IDE so testing the code is easy.

Add a class to the project, I’ll call mine WorldcitiesApplicationTests, and put it in the src/test/java-folder. The first test will test for a non-existing endpoint.

public class WorldcitiesApplicationTests {

 private MockMvc mvc;
 public void getUnknowPath() throws Exception {

To run the unit test mark the class and click on the green play button with the white triangle on the top of the IDE. At the bottom click at the JUnit tab to see result of the tests. Here I have all nine test passing.


This first test is a nice start. But it doesn’t really test anything except it verifies that an endpoint does not exist. A useful test will return an array with zero or more items in it. Counting items in a json-response is described here and my first real test looks like this.

 public void getEmptyCity() throws Exception {
 .andExpect(jsonPath("$.*", org.hamcrest.Matchers.hasSize(0)));

hasSize() accepts an integer and here I want an empty array. Lets test for the nearest town called Sandane. In my case there is only one Sandane in the database, a city like Barcelona or Berlin will have more items in the array.

 public void getOneCity() throws Exception {
 .andExpect(jsonPath("$.*", org.hamcrest.Matchers.hasSize(1)));

I define latitude and longitude with a default value and then parse them in a try-catch.

 Float lat = (float) 61.7428745;
 try {
 lat = Float.parseFloat(latitude);
 } catch (NumberFormatException e) { }

If latitude and longitude isn’t parsed into a float it retains the default value, which is where I live. So /citites/a/b will query locations within a radius of 20 km from my home. This test looks like this and will return 29 items in the array.

 public void getCitiesNearBreimWithMalformedLatitudeAndLongitude() throws Exception {
 .andExpect(jsonPath("$.*", org.hamcrest.Matchers.hasSize(29)));

Next I wanted to test for the real location. Copied, pasted and modified the test and expected 29 items.

 public void getCitiesNearBreimWithDefaultRadius() throws Exception {
 .andExpect(jsonPath("$.*", org.hamcrest.Matchers.hasSize(29)));

But this time I received 37 items and the test failed. Hmm, what is going on? I added a println() and saw longitude was changed from 6.3968833 to 6. As it turns out Spring Boot cuts of the decimal part as explained above. Adding this class to the projects modifies the parsing so I get to keep the decimal part.

public class AllResources extends WebMvcConfigurerAdapter {

 public void configurePathMatch(PathMatchConfigurer matcher) {

After this I received 29 items and the test passed. If unit testing is added early in the process it quickly becomes a part of the coding routine. And it can uncover bugs or parsing peculiarities like this before it hits production.


Create a rest-api with the Spring Boot Java framework, part two

Hi. In the previous post I showed one way to get a Spring Boot project up and running. Then added a single endpoint to display some text.

The source code for this project is available from github.

Now we’ll connect to a postgresql-server. I chose postgresql because I am familiar with it but mysql would work just as well. I use JPA and Hibernate to abstract the database.
Configuring Spring Boot to use postgresql it very easy. This guide was helpful.

Add the following code to pom.xml for postgresql. And to prepare Spring Boot for the rest-protocol. I forgot to select this during the initial configuration of the program.


Spring Boot should download any dependencies automatically. Then add the following lines to the file If you don’t use a password you can omit the third line.

spring.datasource.url= jdbc:postgresql://localhost:5432/worldcities

Just make sure postgresql have been installed and configured. I use macports on os x, others use homebrew.

Then we’re ready to add our first class called City. This is not the complete class, constructors and getters are not included for brevity. Other than that it includes the @Entity and @Table annotation to tell Spring Boot what the table in the database looks like.

I have an old habit of using lowercase names for table names. And class names start, as an convention, with an uppercase letter and would look for a table called City if I didn’t override it in @Table.

@Table(name = "city")
public class City implements Serializable {
    private static final long serialVersionUID = 1L;
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", columnDefinition = "serial")
    private final Integer id;
    private final String countrycode;
    private final String name_lowercase;
    private final String name;
    private final String region;
    private Integer population;
    private Float latitude;
    private Float longitude;

You define the endpoints for the rest-api in CityController. Lets define an endpoint to get a cityname.

private CityRepository cityInterface;

@RequestMapping(value = "/city/{name}", method = RequestMethod.GET)
public List<City> cityByName(@PathVariable("name") String name) {
 return cityInterface.findByName(name);

The database-calls are handled via the interface defined in CityRepository.

public interface CityRepository extends CrudRepository<City, Long> {
 List<City> findByName(String name);

So pretty easy to follow it turns out. Extract the cityname  from the path with @PathVariable and assign it to the string variable name. The call to findByName() returns zero or more City objects in a ArrayList.

I had an issue with a null-pointer exception when I called findByName() without @Autowired prepended to the CityRepository interface. I’m not sure why since it was not mentioned in the examples I looked at on the Spring Boot site. After some digging a Stackoverflow thread helped.

To get cities/locations within a radius I add the endpoint /cities/latitude/longitude/radius.

@RequestMapping(value = "/cities/{latitude}/{longitude}/{radius}", method = RequestMethod.GET)
public List<City> cityByLatitudeLongitudeRadius(
 @PathVariable("latitude") String latitude,
 @PathVariable("longitude") String longitude,
 @PathVariable("radius") String string_radius)

First I define a variable with a default value for latitude, longitude and radius. And try to parse the string. Then call get_locations() that returns a List<City>.

Float lat = (float) 61.7428745;

try {
 lat = Float.parseFloat(latitude);
} catch (NumberFormatException e) { }

return get_locations(lat, lng, radius);

In get_locations() I use SimpleLatLng to calculate the latitude west and east and longitude south and north of the center. Then select all locations with this square. And lastly iterate through this list and remove locations outside the radius and return the remaining items.

List<City> cities = cityInterface.findByLatitudeBetweenAndLongitudeBetween(lat_west, lat_east, lng_south, lng_north); 

for (Iterator<City> iterator = cities.iterator(); iterator.hasNext();) {
 City city =; 
 LatLng p = new LatLng(city.getLatitude(), city.getLongitude());
 double d = LatLngTool.distance(center, p, LengthUnit.KILOMETER);
 if (d > radius) {

return cities;


Create a rest-api with the Spring Boot Java framework

Here is an example on how to write a simple rest-api using the Spring Boot Java framework. This first post will get you up and running with a simple hello spring page. The next post will go into detail on how to add endpoints and code to access the database, parse the result and return it as json.

The source code is available on my github-page with a tiny description which assumes how to assemble the parts.

Lately we have seen some pretty awesome Java frameworks like Jooby and SparkJava that gets you up and running in a few minutes. This is great since Java thus becomes a viable alternative to web frameworks written in javascript, ruby, php etc.

Spring Boot is almost as easy to get started with as Jooby and SparkJava. And being such a capable framework it’s remarkable how easy Pivotal, the company behind the Spring projects, have made the process that gets you there.

I’ll outline the steps I took to put together this simple rest-api. It can search for cities/locations within a radius specified by latitude and longitude. I found many good examples in Spring Boots getting-started guides and the web and Stackoverflow is a great help when issues arises.

The guides show how to create the folders and the file pom.xml. This is the build-file maven use. You can also go to Springs starter page where you can select database, functionality etc. Download and unzip and start coding.

For this project I’ll show mostly the latter and also show how to edit pom.xml to add extra functions I forgot to select rest-functionality so this will show how to add it to pom.xml. And that is nowhere near fatal if some desired functionality is left out in the beginning.

Hab kein angst. Nur viel spaß.


First head over to Springs starter page.



Click at the link at the bottom to expand to the full version.



Select Cache and DevTools. The latter is nice during development since it reloads your code on changes. This way you don’t have to stop and start your web-server on changes.



Then select JPA, JDBC and Postgresql.



Then click on Generate Project and your file is being downloaded.



I use Eclipse as my IDE. It has it’s quirks but I like the way it tries not to be too helpful while still give some good advice when I make mistakes. Other nice IDE’s are IntelliJ and Netbeans. You decide.

You can also edit the files using an editor and run the maven project from the command line.

Import the folder into Eclipse from File->Open Projects from File System.



After import the main-function is ready to run.



From now on you can either start the program from the command line using “mvn spring-boot:run” or add a run-configuration to Eclipse.

From the menu select Run->Run As->Maven build… and enter “spring-boot:run” in Goals. Just remember to select Maven build with the three dots (…).



Then select the Source tab and click Add…



Select the project worldcities and click OK.



When you get back to the previous windows mark the Default folder and click remove so we are left with the worldcities folder. Then click Run and the program starts. It may need to download some files the first time it is being run.



To show a message from Spring Boot create the Java class CityController in Eclipse. Make sure the package name is the same. In this case no.gnome.

Add @RestController shown on line 6. Usually Eclipse will automatically import the necessary functions when annotations like this is added to the code. This annotation add functionality to the Spring Boot environment so your program can handle rest-request.

On line 9 add @RequestMapping(“/”) and create the function on line 10-12.

public String index() {
    return "Hello from Spring Boot!";



When you save the file Spring Boot will automatically reload to include the changes. Open a browser and go to localhost:8080 and you are greeted with the hello message.



In the next episode I will show how to add the parts to query and filter locations. Until then take care.

My iphone-app has been approved by Apple

My iphone-app is now available on the app store in Norway, Denmark and Sweden. The app is for signing up on training sessions with the personal trainers Anne-Merete and Oddny Kleppenes, the first being my wife and the latter sister in law, hence the name of their company PT-Amok was coined. Buying the app gives one free training session.

Navigate to the app store and go exercise.

Amazon CloudFront with custom certificate

Hi there.

I recently wrote a javascript app with some dash of html for my wife and sister in law. They are personal trainers in their sparetime and announce their activities on Facebook and link to a page where one can sign up. The code resides in a S3 bucket and can be served from there. The app uses the web-based Facebook login.

Select the bucket, mark index.html and then click on the Properties button in the upper right side. The link can then be pasted into the announcement on FB. Which we also did to begin with but the URL is neither very pretty nor easy to remember. But good enough just to get started with the sign up process and get some feedback.

Amazons CloudFront is a CDN (Content Delivery Network). CloudFront is build for speed and S3 buckets for storage. When you create a CloudFront distribution you can connect to your S3 bucket in the wizard. Log in to your Amazon account and select CloudFront from the leftmost column.


Then click on the top most ‘Get Started’ button in the section Web.


When you enter ‘Origin Domain Name’ a list with your S3 buckets appears. Select the bucket you want to add to the CloudFront distribution.

Then select ‘Redirect HTTP to HTTPS’ in ‘Default Cache Behaviour Settings’ so it always serves encrypted https.

In ‘Allowed HTTP methods’ you can change the value as needed. Use the bottom option if you need to write content.

Leaving the rest of the settings at their default will create a distribution and assign it a domain name. I got, shorter than the S3 bucket URL but still odd looking.


To use your own domain name enter this in ‘Alternate Domain Names (CNAMESs)’ in the section ‘Distribution Settings’, in my case it’s Head over to your DNS and add the CNAME and point it to


Then click on ‘Request an ACM certificate’ to have Amazon create a certificate for this domain.


Enter the domain name, use an asterix (*) so you can add any subdomains and click on ‘Review and request’.


Click on ‘Confirm and request’ and a mail is sent to the domain, and hostmaster is one of the recipients. Just make sure that one of the recipients have their mail forwarded to your account. When the mail arrives confirm you want to create this certificate. I selected the region N. Virginia when I requested the certificate.


Select ‘Custom SSL Certificate (’ and the appropriate certificate. When these changes are saved the distribution settings must be propagated throughout CloudFront and this step take some minutes. You can specify the default html file to be served by adding the filename to ‘Default Root Object’, in my case index.html. So now the link is prettier.


Amazon Cognito/IAM and Facebook login, part two

This is the second part of the post which shows how to integrate Amazon Cognito and IAM (Identity & Access Management) and Facebook login. The first is here and is a series of screenshots.

This post will briefly explain how to set up a local environment and develop and test it before deploying it to Amazon S3. This and the first guide relies in part heavily on Serverless Single Page Apps by Ben Rady which you can buy from

I use OS X and macports for package management on the command line so the examples provided are on this platform. Seasoned Linux- and BSD-users knows the difference and will apply appropriately.

I have very little experience with cygwin and mingw.

When you start developing the app you can do so on your local machine. It’s faster to test changes on local code instead of having to upload it to S3 first, easier to install extra programs etc.


At the bottom of the page you specify the ‘Site URL’ you are using. When I developed the app on my local machine my URL was ‘https://localhost/’. I had plain http to begin with but got some error messages that said I was mixing http and https so I changed it to encrypted https.

You may want to install a webserver. OS X ships with apache but sometimes Apple is slow updating apache, sometimes you want a custom-build apache server. I use nginx which can be installed issuing the command

$ sudo port install nginx

The default installation path is /opt/local and the configuration file is located at /opt/local/etc/nginx/nginx.conf.

After nginx is installted you will create a local snakeoil certificate. I followed this guide. When you have the certificates copy them to this location or choose your own path and edit nginx.conf and add or change these lines accordingly

# HTTPS server
server {
  listen 443 ssl;
  server_name localhost;

  ssl_certificate /opt/local/etc/openssl/certs/selfserve.crt;
  ssl_certificate_key /opt/local/etc/openssl/private/selfserve.key;

  location /cielo {
    root /Users/claus/devel/;
    index index.html;

Don’t forget to reload the nginx configuration, this can be done with

$ sudo nginx -s reload

I have created a github repo with some example code which you are welcome to clone and modify. The poolId in utils.js

var poolId = 'eu-west-1:82de430e-6f53-4d84-90fa-509d6b6775d3';

is from the example code in ‘Federated Identities’ in the Cognito console.


The poolId is paired with the appId that was entered when the pool was created.


The appToken in the javascript code and the ‘Site URL’ shown in the first image is used by Facebook to grant your app access. So I conveniently changed the URL before publishing the code. Otherwise the code can easily be cloned and run from any local machine and possibly be abused.

var appToken = '860675960666169|00_5tkwxjsUj_u6P1-U1IXjj9mE';

The appToken consists of your appId and a token separated with a pipe symbol (|). You can generate the token using curl. Run the following command on the command line.

$ curl ''

The output can look like


Copy the string between the equal- and percent-sign and paste it into your own code. I think I got the curl-command from a stackoverflow thread. You can read this blog for additional information.

Don’t reveal the app secret to others.

Create a bucket on S3. Bucket names are unique so if you have a domain add this. Descend down to the folder where the code is and issue this command

$ aws s3 sync . s3://

Before you can use the aws command you have to install and configure it. Ben Rady explains the procedure in great detail in his book.

After the code is synchronized to S3 enable ‘Static Website Hosting’ on the right hand side and specify the ‘Index Document’. In this case it’s index.html.


Grant Everyone access to index.html and click Save. Repeat the process for other files where needed.


There is a publicly available link to index.html. The URL could be used but only the hostname is used by Facebook to restrict where the app can be run from. So anything after the forward slash after the hostname is ignored. Which means that you can’t rely on this to prevent others from impersonating you.

Instead you can use another service provided by Amazon called CloudFront. This also has the advantage they can provide encrypted https to your S3 bucket.

Ivan Kusalic have some advise if you use CloudFront with a third-party certificate. I did not have some of the problems Ivan mentions but maybe the service have matured since he tried it.

Creating a CloudFront service is easy. I feel that Amazon have put great efforts into the creation of services as effortless as they can become. Click on ‘Create Distribution’.


Click ‘Get Started’ in the Web section.


In ‘Origin Domain Name’ a list with your buckets will be available. Select the bucket you created above. If you only want encrypted https select ‘HTTPS Only’ in ‘Viewer Protocol Policy’. The other settings can be left as they are. I have selected ‘Use only US and Europe’ in ‘Price Class’ in the section ‘Distribution Settings’ since performance is not a concern. The section is in the same window but further down and thus not visible. Just scroll down and you’ll see it.


Click ‘Create Distribution’. It will take a while before it is ready. I went to bed when I created the distribution and it was finished when I woke up again but I doubt it takes all night.

Copy the domain name to the site URL in your Facebook app settings and you should be all set.

This app only show the content of a table. In a later update I’ll add the possibility to enter some information and update the table. Till them take care.