Wednesday, December 30, 2015

D plugin for Intellij IDEA

I've been programming in D for over a year now and for the most part I've used Sublime Text as my editor of choice. This has been fine for experimenting with little bits of code but a proper IDE with good auto completion, code inspections and other such features can really boost productivity.

For the last five years I've been using Intellij IDEA and have grown accustomed to it's ease of use so using it for D projects would be really handy. Fortunately Kingsley Hendrickse (kingsleyh) wrote a D Programming Language plugin for Intellij (there is another plugin for dlang in the JetBrains plugin repo but this is the one to use). Kingsleyh's plugin makes use of some D tools that were written by Brian Schott (Hackerpilot):

DCD (D Completion Daemon, auto-complete program for the D programming language)
D-Scanner (tool for analyzing D source code)
dfmt (formatter for D source code)
dfix (Tool for automatically upgrading D source code)

Brian Schott did a talk about these projects at this years DConf so it's worth checking out the video on youtube. As they are stand-alone programs they need to be installed on your system manually. There are not pre-compiled binaries available currently so to get them installed you have to clone the repositories, build the projects, then put them somewhere on the system PATH. This can be done with the following steps:
git clone git@github.com:Hackerpilot/DCD.git
git clone git@github.com:Hackerpilot/Dscanner.git
git clone git@github.com:Hackerpilot/dfmt.git

cd DCD
git submodule update --init --recursive
make
sudo mv bin/dcd-client /usr/local/bin/
sudo mv bin/dcd-server /usr/local/bin/

cd ../Dscanner
git submodule update --init --recursive
make
sudo mv bin/dscanner /usr/local/bin/

cd ../dfmt
git submodule update --init --recursive
make
sudo mv bin/dfmt /usr/local/bin/
Then it's just a case of installing the plugin from the plugin repo and configuring it to use the tools. This is done in:

File > Settings > Other Settings > D Tools

Simply clicking the 'Auto Find' buttons should do the job.


Now that's all done you're good to go with dlang on Intellij.

Monday, July 27, 2015

Updating all guids in a file using Powershell

I'm getting to really like powershell. Today I needed to generate a whole lot of guids in multiple build files and was able to do what I needed with a single line:

(Get-Content 'filename') | ForEach-Object { $_ -replace "[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}", [guid]::NewGuid() } | Set-Content 'filename'

Friday, May 15, 2015

Conways Game Of Life

Like many students studying software engineering, when I was at university one of my assignments was to write an implementation of John Conway's Game of Life. At the time I found the assignment fairly tricky but out of the whole three years in University it was probably my favorite piece of work.


Saturday, May 09, 2015

AES File Encryptor for Windows

This week I spent some time working on a powershell script which will use AES Encryption to encrypt a file prior to it being transffered to a remote destination. The receiver will be able to unencrypt the file using a provided key.


I decided it would be a good idea to use the script as a basis for a Windows application that provides the same functionality. Using Visual Studio 2013 I quickly put together a simple user interface using WPF (Windows Presentation Foundation) and wired up the controls. It took hardly any time to get the whole thing working and with the inbuilt Git integration it's been pushed up to Visual Studio Online for future reference.

Wednesday, March 04, 2015

How To: Migrate from svn to git

Source control is a vital tool to any developer, if you're not using some form of source control when doing development then you're missing out. Creating a zip file with a version number in it does not count. Amazingly I still come across people doing this.

Most of the projects I work on are using git but there are still a few projects that are kept in subversion. There's nothing wrong with svn, it's perfectly fine but git does make it convenient to work on different features locally.

In the past I've moved projects from svn over to git by simply doing svn export then adding the exported code base to git. The drawback here is that you lose all the commit history and tags/branches.

Fortunately it's possible to migrate a svn repository over to git whilst keeping all of the history and some of the developers at Atlassian have made a handy tool to make it even easier.

Naturally you'll need svn and git but you will also need git-svn, Java, and 'svn-migration-scripts.jar' (available from BitBucket).

I did the process on a Fedora Linux system (you should use a caps specific system) so the commands used on this page could differ. For full details of the process you can refer to Atlassian's Migrating Overview page.

To start off make sure you have git-svn:
sudo yum install git-svn
Then if you havn't already downloaded it, get the svn-migration-scripts.jar:
wget https://bitbucket.org/atlassian/svn-migration-scripts/downloads/svn-migration-scripts.jar
The first part of the migration is to map all the users that have done a commit to the svn repo, to their corresponding git user. To do this use the migration-scripts tool then manually edit the generated 'authors.txt' file:
java -jar svn-migration-scripts.jar authors https://mydomain.com/svn/repos/myproject/ > authors.txt
For every user that has done a commit to the project in the svn repo, map them to a name/email combination that is used by git. eg:
BGATES = Bill Gates bill.gates@microsoft.com
Once that's done it time to get git-svn to get all the commits from the svn repo:
git svn clone --stdlayout --username=SVN_USERNAME_HERE --authors-file=authors.txt https://mydomain.com/svn/repos/myproject/ myproject
Change in to the newly created directory that the code has been cloned to. It's worth noting that git can be configured to a particular user both globally and for a particular repository so you may want to set your name/email for the repository before continuing:
git config user.name "name"
git config user.email "name@domain.com"
Now to convert all the svn tags to tags in git (assuming you have the standard svn layout of tags, branches, and trunk):
java -Dfile.encoding=utf-8 -jar ../svn-migration-scripts.jar clean-git --force
That's just about it. Assuming you already have an ssh key and a remote git server to push to then you can add the remote is the usual way and push the code. Note that by default git won't push the tags up to the server so use '--tags' or '--all' (not both):
git push -u origin master --all

Tuesday, January 27, 2015

Simple Java Ray Tracer

This evening I decided to go through a few old folders on my laptop and delete anything I don't need anymore. One of the items was a zip file of some source code for a ray tracer written in Java. I downloaded it a few years ago from another blog that's no longer online. I believe it was originally written in 2008 by Barak Cohen and Gur Dotan.


As the authors blog is no longer available I couldn't bring myself to deleting it and have put a copy on GitHub in case any other people out there want to take a look. I've rejigged the project structure a little and removed all the Eclipse related files in favour of a Gradle configuration.

Friday, January 23, 2015

Vendor specific meta tags

The company I work for use IE almost exclusively. Every member of staff has been on IE9 for some time and are now on IE11 which means that I'm in the fortunate position of not needing worry too much about implementing CSS and Javascript workarounds for old browsers. What I am seeing more of though is vendor specific meta data.

Although the company use IE on the desktop (I still use Chrome & Firefox for development), we do also test projects on Android and iOS. All three platforms we support have their own tags for icons and the like.

It would be good see some standards introduced so that developers can add this type of information in a way that can be used by multiple browsers.

Thursday, January 22, 2015

How To: Deploy a Java war file to OpenShift

I recently put together a responsive web application for someone that wanted a convenient way to keep track of the types of food they've had each day with the ability to perform some statistical analysis on the data recorded. The application uses Spring, Hibernate, JSF, Primefaces, and Twitter Bootstrap. They've opted to have it hosted in the cloud using Red Hat's OpenShift which gave me an opportunity to use the platform for the first time.

Openshift provide a range of options for Java. My app needed Java 7 and Tomcat 7 (there currently doesn't seem to be an option for Java 8) so I selected the appropriate option and set about getting my app deployed.
$ git clone
$ cd nutritionapp/
A directory structure and pom file is already setup for those wanting to commit source code to be built by Openshift prior to deployment. This wasn't what I wanted as I've already compiled a war file and just want a quick way to deploy it. For this option, Red Hat have also put a 'webapps' folder in the root of the repository so I needed to do was delete the 'pom.xml' and the 'src' folder, add the war then push.
$ git rm pom.xml
$ git rm -r src/
$ git add webapps/nutritionapp-1.1.war
$ git commit -am "deploy v0.1 to cloud"
$ git push
I then ssh'd into OpenShift using the url provided in the web interface and did 'tail -f app-root/logs/jbossews.log' to see what was happening with deployment. There was a problem during start up but the log entry wasn't too helpful. Luckily I found a post here which helped out, seems that in OpenShift the 'web.xml' in the app needs to have the Log4jConfigListener removed.

    org.springframework.web.util.Log4jConfigListener
So after a quick edit of the 'web.xml' one last commit was needed.
$ git commit -am "removing Log4jConfigListener"
$ git push
That was it, the whole process was pretty simple.