Skip to main content

Posts

Generating aesthetically pleasing colours that go well together

So the other day at work, my boss had another request for me, he wanted me to write some code that auto-generates a bunch of colours that go well together such that they could be used in a chart i.e something similar to what Google uses for their Google visualization API . So i wrote some code that generated decent enough colours and showed it to him, to which he responded, "is this what Google uses?" i was like no this is something we wrote, but he insisted that he wants exactly what Google uses and that is it. Now this was interesting as, Google provides a charting API for generating charts, but they don't exactly give access to the their colour generating algorithm. So to keep my boss happy, i came up with a little hack which solved our problem. You see the way to do this would be to generate a mock chart using the Google Visualization API and then extract the colours out of the chart itself. You see the chart is an SVG object and with the use of JQuery ( I assume ...

Transpose of a Google Visualization data table object

Since i spend a lot of time at my day job working with the Google Visualization  tools for the charting needs of my work, i figured it is inevitable that i will be requested to draw a chart with transposed data. ok...let us backtrack a little. So to draw a chart using the Google Visualization tools, the first step is to prepare a DataTable , which is a data structure provided by Google. The DataTable as the name suggests is simple table of rows and columns, hence it can be thought of a 2D matrix . Obviously now once you start to perceive your data as a matrix, what you can do with a matrix is only limited by the type of data stored in it. In this case the matrix operation of interest to me, was the transpose . Transpose is one of the simpler concepts of linear algebra, where by in a given matrix , rows become columns and columns become rows. Ok so now onto business? FYI, this is a quick and dirty solution and is in no way optimal. Since my need was to transpose a table that h...

Consistent with equals and unique values in Set

So the other day one of my friends was trying to solve a problem and he decided to share his problem with me. So based on my understanding of what he was trying to do was, that he had 2 disparate groups of data stored in Lists, the two lists were likely to have duplicates. His objective was to consolidate the two lists such that the consolidated list would only have unique entries. The lists had custom data structures, so straightforward methods of adding elements to a Set by itself wasn't enough, nor was it the situation where you add all the elements to one big list and somehow use the removeAll method. My first reaction to this problem was, hmm why not exploit the consistent with equals concept with a Comparator . Now this may or may not be a good solution, it was a fun one for me to knock up and it builds on my last post about Sorting in Java. The problem Say we are getting two streams of data, which may or may not contain duplicates and our goal is to get data that is ...

Fun with sorting (Java)

So every once in a while my boss makes an interesting sorting request, something like, i want the list of users sorted by locked, then production, then date joined and then name. Now sorting is generally a fun little problem in any capacity and some of the fancier requests from my boss make it even more interesting. So as with most other things, even for sorting the general rule to only write something from scratch if there is absolutely nothing out there applies. I mean seriously even on those really boring days in the office where you are doing the most repetitive of tasks, it is generally a good idea to resist the urge to make things more interesting by writing something from scratch or worse configuring your servers to support Gopher . Ok back to the point, so.....sorting in Java is pretty easy actually, all you need to do is call the Collections.Sort() method to a collection of objects that implement Comparable or better pass a specific ...

Auto updating the play framework messages file for admin section

So the other day at work, my boss asked me to do a really boring task, which was to give meaningful names to some 30 to 50 labels in an html form i.e. I had to go in an manually type in proper names for all the labels in the form. Ok a little bit of backstory, at work we have this large application that does all sorts of data processing and analysis amongst other things. Naturally the heart of this application is in the complex data processing tasks and therefore some UI aspects, only used internally by staff are largely ignored, well at least until there is time for it. The application is built using the play framework for Java and for the admin tasks, we use the auto admin generator provided by Play, that gives us the basic functionality. As those who have use Play framework would already know, when it generates the admin UI form, it maps the variable name to the field label in the html form. So for a class called Person with a property lastNa...

Coloring individual columns of a column chart (Google Visualization)

Now before i get into the nuts and bolts of my problem. I must confess that i was quite skeptical about the google charts API, mainly because of using the mostly awesome Jfreecharts  in the past. However having used it for a bit now, i am warming up to the idea of it, because quite frankly it is much simpler to use. You are likely to have a "cool" looking chart with tooltips etc in a much shorter time when compared to JFreeCharts. Anyway so about my problem, recently i was asked to create a column chart such that each column is colored differently.  My data looked something like this    var  data  =  google . visualization . arrayToDataTable ( [      [ 'Year' ,  'Games Finished' ] ,      [ '2003' ,   12 ] ,      [ '2004' ,   6 ] ,      [ '2005' ,   15 ] ,    ] ) ; The problem with this was that each column in the column chart is the same...

Consuming a RESTFul web service with Java Part 1 (java.net way)

Its incredible how common RESTFul web services have become now, i mean i have only started hearing about them in the last couple of years and the usage surge is a little interesting, especially since the style was originally proposed by Roy Fielding back in 2000. I guess one of the reasons could be all the big players getting onboard the REST bandwagon, but anyway this post is not about an analysis of the "RISE Of The REST", its really about how to consume them. If you want to know more about how REST works have a read of this post by Stefan Tilkov.   Ok so now there have been two projects where i have had to write REST clients, projects such as: Data capture automation tool: This was a java client i wrote for the School of Chemistry at UNSW, which basically helps them upload their experiments data to a server via a web service. I loved this project, i mean i had a chance to do commercial Swing programming, how often does that happen? ohh and i also had a chance to flex...