Sometimes the simplest solutions are the best solutions

How many times have you seen or written code like this (in any language):

if(someFlag){
    someFlag = false;
}
else{
    someFlag = true;
}

I’ve written code myself like this many times, and seen it in many places too. Usually for toggling display of some content: “if it’s hidden, show it; otherwise, hide it”.

Recently I’ve been spending a lot of time learning and coding an app using AngularJS and I keep seeing this pattern repeatedly in many code examples:


someFlag = !someFlag;

When I first saw a statement like this it took me a couple of seconds to understand the purpose, but then when it clicked I laughed out loud in one of those ‘ahah!’ moments, as the outcome of this code is exactly the same as the code above.

When we translate design to code, sometimes thinking in logical, procedural steps hurts the ability to translate to code that best uses the features of the language or platform that you are running on. Sometimes the simplest solutions really are the best solutions, although maybe it takes a different thought process to get there.

(Page views: 10)

Choosing an Issue Tracker for an Online Service

I’ve been working on an application that I’m getting close to publicly launching, and while the site is mostly functional with most of the development done (I’ve been working on it in my ‘spare time’ for almost a year), there’s some non-development tasks I need to complete before launching, including:

  • adding Google AdSense and Analytics
  • completing online documentation
  • setting up an online issue tracker

The options for an issue tracker has taken me by surprise as there are so many options, ranging from free to varying monthly fee options. I’m somewhat familiar with some of the older free development project focused options, like Bugzilla, Trac, Redmine, and commercial options like Atlassian’s Jira. Part of my app is open source on GitHub and so to use the GitHub issue tracker for that part is an easy choice. I’d also like to make sure whichever issue tracker I chose is easy to use from the point of view of my end users, the majority of which are unlikely to have existing GitHub accounts, or accounts on other online tracker sites, and I want to make sure it’s as easy as possible for them to log issues and enhancement requests.

(This article here has a good list of a number of issue trackers.)

Ranging from simplest to use, Trello is a stand-out from the crowd. Although it’s not a dedicated issue tracker, the approach of managing lists of items and moving items (cards) from one list (e.g. open items) to another (e.g.closed items) is trivial.

Categorized in interesting-but-with-high-technical-requirements is YouTrack from JetBrains, and free for upto 10 users … but requiring 1GB heap to run, this would cost me some monthly runtime costs for  medium gear on OpenShift, so I’m not sure  if this is worth the investment at this point.

Next up in the looks-interesting category is Asana – I’m not familiar with this service, it looks like it offers much more than I would need, but could be worth investigating.

I’ve some decisions to make here, and right now I’m thinking either using GitHub’s issue tracker or Trello. What would you recommend – leave me a comment!

(Page views: 15)

Happy 20th Birthday Java! What’s your Java story?

I started learning Java in 1996, from the book ‘Learn Java in 21 Days’, published by SAMS. For some reason I even still have the same book:wpid-20150521_081822.jpg

At the time I was working for Royal Sun Alliance and we were doing OS/2 client/server development using Application Manager, against a CICS/COBOL backend. One of the guys I was working with, Mike, said I should take a look at this new language called Java because it can run on any platform. At that time developing on OS/2 and seeing demand slowing for OS/2 AM developers, the promise of a development language not tied to a specific platform seemed an attractive offer, and a potential ticket to move away from OS/2.

I started working through the exercises in the book, building my first Applets – I think one of the first applets I built was a lottery ticket number generator that I had on my webpage at the time. In 1996 it was pretty cool to have interactive content on your web site! Even though this turned out to not be Java’s strong point (most Java development is arguably server side now days), it was where it all got started.

Although I continued to play with Java in my own time, it wasn’t until I changed jobs in 1997 and moved to TSW/Indus, a software house developing Enterprise Asset Manager software, that I had the opportunity to start Java development ‘on the job’. At the time the company had a Powerbuilder/Oracle PL/SQL based client/server product, and while in that first year I cross trained to Powerbuilder, we started prototypes of building a web-based replacement for the Powerbuilder client, against a Java backend. At the time this was using a ‘Java Cartridge’ on Oracle Application Server (I think it was called), and the Java code was invoked CGI-BIN style using HTTP GET query string parameters that were passed into Java code on the server.

At some point pretty soon after these first prototypes the Servlet API came along, and then EJB1.x came along… looking back which was an absolute nightmare from a developer productivity point of view. Somewhere in there I also dabbled with some CORBA based backend running on a server that I think was called IONA (although those memories are long gone now).

I’ve seen a lot of incredible changes in the Java space, and 19 years later from where I started, I’m still coding Java and it’s still going strong!

(Page views: 51)

Calling C printf from ARM ASM

A while back I started to learn some ARM assembly on the Raspberry Pi. In my previous snippets, I was using SWI to do a system call to write to stdout, but it appears syscall 4 to write to stdout only writes Strings – if you have a byte value, this approach doesn’t work (without converting to a String first?)

From this question here, it appears you can call C functions like printf, which seems like cheating a bit, but I guess it gets the job done.

Here’s a quick snippet to add two numbers, and then print the result using printf with a string containing %d to substitute the result into the String:

.global main
.extern printf
main:
    push {ip, lr}
    mov r3, #1          /* move 1 to r3 */
    mov r4, #2          /* move 2 to r4 */
    add r4, r3, r4      /* r4 = r3 + r4 */
_ouput:
    ldr r0,=output      /* load address of output string */
    mov r1, r4          /* move r4 result to r1 to include as param in string */
    bl  printf          /* call printf */
_exit:
    MOV R1, #0
    MOV R7, #1
    SWI 0
.data
output:
.asciz "Result: %d\n"

Where previously I was compiling and linking in two steps with as and ld, it seems this doesn’t work if you are referencing C functions too, so for this example, compile with: ‘gcc add.s -o add’

This snippet and a few others I’ve started to collect I’ve shared in a github repo here: https://github.com/kevinhooke/learning-arm-asm

(Page views: 24)

Enjoy your additional ‘leap second’ on June 30th 2015

This year on June 30th at 23:59:59 UTC, rather than the 59th second ticking to 00, there is an additional second added so clocks will tick to 60 before going to 00.

If this sounds rather odd, check out a more detailed explanation here on Wikipedia.

So what does this mean for us as software developers? Well, for Java JVMs, you can use the provided tzupdater tool (updates described here, and usage described here), download the updated timezone file and apply the update. For other platforms and operating systems, check release notes and updates from your vendors (e.g. For RHEL, check here).

Should you be worried about the impact to your systems? Well that depends on how sensitive your system is to the date/time and synchronization with other systems that you integrate with. For example, the ICE futures exchange have announced they are taking their systems down for an hour overlapping with 23:59:59 on June 30th to avoid any unexpected issues. Whether you have to go that far depends on your system.

 

(Page views: 59)

node.js process.cwd() “no such file or directory” starting http-server

When starting the node.js http-server, I got this error:

Error: ENOENT, no such file or directory
at Error (native)
at Function.startup.resolveArgv0 (node.js:720:23)
at startup (node.js:63:13)
at node.js:814:3

From the post here, it seems this error can occur if you attempt to start the server in a dir that’s already been deleted. In my case I had renamed a folder that contained the folder where I was attempting to start the server. cd’d up a couple and into the new/renamed folder, and problem solved.

(Page views: 37)

JEP 222 – REPL proposed for Java SE9

A REPL (Read-Eval-Print-Loop) feature is becoming a common feature for many languages (Scala and Groovy both have a REPL commandline shell), and JEP-222 proposes adding this same feature to Java for SE9. This feature is useful for quickly trying out and evaluating an expression, and will be a valuable addition to Java SE.

(Page views: 51)

Nvidia drivers on Windows 10 Insider Preview

I’ve installed the Windows 10 Insider Preview, but after installation the display driver was just a generic driver, and I couldn’t increase my resolution to the 1920×1080 on my LG monitor.

Nvidia have Windows 10 drivers available, but when I ran the installer it said that my GeForce 6150SE was not supported. In other posts elsewhere, someone suggested to just use the latest Windows 8 driver. The latest driver for the 6 series is here. I downloaded it and ran it, and everything looks good, it even detected the highest resolution for my monitor and set it for me. Very cool!

First thoughts on 10? The Spartan browser crashes randomly, it just closes without any errors, When it is open and running, page rendering seems pretty snappy, although rather than showing a progressive page load of elements, it seems to be rendering everything in the background and then swapping in a fully loaded page when it’s ready. At least that’s what it appears to be doing. Rather than seeing a page progressively load, pages delay for a while and then instantly appear. Not sure if I like that approach.

The new Start menu with the Metro tiles embedded in it is one approach to keep the Metro stuff around if that’s your thing, but moving it into the Start menu instead of a full screen. Maybe a better approach would be to just throw that stuff away and go back to a normal looking Start menu. Do I need to see news headlines in my Start menu? No. If I want to see news do I want to have it pop up in a tiny unreadable tile in the Start menu? No. Terrible idea if you ask me. Seems like MS really doesn’t want to do away with the Metro UI. “Ok, so we’re not removing it, so where can we put it?” … “I’ll let you put it in the Start menu” … “Really? That’s terrible, but ok then”.

(Page views: 64)

Creating test data in MongoDB using node.js

I need to create a fairly large number of test documents in my MongoDB to test some functionality that will be retrieving pages of data, ordered by date.

Rather than doing this by hand, using the Node.js driver for MongoDB makes this pretty easy with only a few lines of code. This is a starting point, in my case I need to add some additional logic to increment a date value and create some other random values on each doc, but this is a rough outline of an approach:

Assuming Node.js already installed, install the MongoDB Node.js driver with:

npm install mongodb

Then the code to install multiple docs in one shot looks something like this:


var MongoClient = require('mongodb').MongoClient,
  test = require('assert');

var ObjectId = require('mongodb').ObjectID;

MongoClient.connect('mongodb://localhost:27017/databasename', function(err, db) {
  test.equal(err, null);

  var col = db.collection('collectioname');
  var docs = [];

  //update this for how many docs to insert

  for(i=0; i<10; i++){
    docs[i] = {a:i}; // create doc here using json
  }

  col.insertMany(docs, function(err, r) {
    test.equal(err, null);
    console.log(r.insertedCount);
    db.close();
  });
});

Run the script with:

node scriptname.js

Additional info in the MongoDB Getting Started Guide for node.js.

(Page views: 227)