Presentation slides with Reveal.js

Using the reveal javascript library its possible to build intricate presentation slides for the browser. While its possible to create a sample using a web client over at https://slides.com/ I personally prefer to download the latest version directly from the github account Latest release in order to generate your slide presentation by hand.

Steps to get it all up and running:

 

  1. Create a new folder and extract the latest reveal.js code into a sub-folder called “reveal.js”
  2. In the root of your project copy the following html code into a file named index.html
  3. Open the index.html file with your browser of choice (note: chrome seems to be the preferred option)

The above sample is just a quick setup to get you going but there are many features in this library that you can take advantage of:

  • Markdown support using “<section data-markdown> …”
  • PDF support by going to “?print-pdf” in chrome. The sample above provides support for this using a small javascript tag which makes use of some inbuilt javascript libraries.
  • Hidden notes support using “<section data-separator-notes=…>”
  • Slide data transitions such as “fading” in and out, zooming as well as controlling the speed

There are many more features that you can play about with including embedded videos, images and other multimedia. One feature that particularly interests me is embedding external markdown files. In terms of project development teams would be able to provide customer demos along side your versioned code base. It’s also possible to override the existing css but you may find this to be difficult when using the markdown content due to the way that this is converted by reveal.js on the fly.

For a quick introduction on other features in the current version 3 release have a look at the following slideshare from the author of Reveal.js Hakim El Hattab:

Advertisements

Creating a Gists Webpage With ReactJS

I decided to build a simple ReactJS webpage to render my personal Gists from GitHub as an basic kata.

However while the ReactJS part was fairly straightforward I was once again reminded about Cross Site Scripting (XSS) issues when trying to call API’s from another domain using javascript. Thankfully JQuery jsonp still works:

componentDidMount(){
    $.ajax({
      url: "https://api.github.com/users/m-x-k/gists",
      jsonp: "$jsonp"
    }).done(function(data) {
      console.log(data);
      this.setState({gists: data});
    }.bind(this));    
}

Obviously in a production situation this isn’t what we would rely on. Reverse proxies like Nginx, HAProxy or Apache are much better suited to revolve these types of issues. Ideally we would setup a reverse proxy on “api.github.com” so that we can share a common domain for the client side requests. For example if your web page url was http://my.gists.com/index.html you might setup a reverse proxy like http://my.gists.com/api/m-x-k/gists.
Note: while its possible to mitigate the problem with headers it’s not an ideal solution as it depends on browser support.

Rapid prototyping with code templates

Over the last few years I have been using Python quite a lot to build rapid prototypes. By far the best command line tool I’ve found for this is the python ‘cookiecutter’ project below:

https://github.com/audreyr/cookiecutter

There are a large number of sample cookiecutter projects out there but it makes sense to build and maintain your own if you want to get the latest setup.

For ease of use I have a number of linux command line aliases to create new projects from my own code template projects:

In some cases these code template projects have been customised to my own preferences with IDE support etc … but for the most part they tend to be fairly vanilla in case other people might find them useful and also to allow me to customise each new project. So for example with Java applications I tend to prefer IntelliJ with Gradle but beyond that for me it doesn’t make sense to preload all of your favourite java libraries.

In some work places I have noticed a tendency to try and standardise code structure with similar code template tools (e.g. maven archetypes). In many cases this can save project setup time but I tend not to favour this approach. Ideally in agile development teams it is best to reach a group consensus based on the project requirements first and then trying to agree on code standards such as naming, structure etc … A good place to start is often Uncle Bob’s Clean coders book which is widely distributed and possibly combining this with Extreme Programming techniques such as TDD, Pair Programming or Mobbing. This combined approach often gets extremely good results allowing for a wider group consensus and shared ownership.

However in many situations the first place to start on a project is a quick prototype. It can therefore be convenient to use code templates in these situations. This actually helps to reinforce the concept that code implemented as part of the prototype is ‘temporary’ and therefore should be discarded and reimplemented by the team from scratch.

Building a responsive photo gallery

Recently I needed to build a photo gallery for a website built with ReactJS. I came across a convenient react library “react-photo-gallery” which was ideal for this purpose. As a proof of concept I built a small Spring Boot app with ReactJS support:

https://github.com/m-x-k/photo-gallery

The application contains a few sample images which can easily be orientated to fit various devices and screen sizes for responsive behaviour.

I also needed to provide a demo to show off some of the functionality before implementing further. Luckily Heroku provides a great environment for sample demo sites. As usual Heroku can be a little slow on the first load as it builds the app on demand. You can reach the demo site below:

https://responsive-photo-gallery.herokuapp.com/

The code implementation was straight forward to setup with the project split into two separate folders. One for the spring boot ‘src’ code and the other ‘ui’ folder for the ReactJS code. Support for Docker has been included as well as details and scripts on to upload the app and any photos to a Heroku account. The only tricky part was getting the folder permissions just right for the photos to load successfully.

At the minute I tend to favour Gradle for building Java projects it provides a robust DSL with various plugins and support for Maven etc … When it comes to Javascript building I tend to favour NPM/Yarn with Webpack especially for the ease of setup when it comes to ES6 transpiling. The combination allowed me to quickly setup an application which could allow the full stack to be built on demand.