Posts

Showing posts from 2013

Doing some SVG drawings on a web page (Raphael.js)

So for this tree based problem that i am currently trying to solve, one of the first perquisites was to get better at Recursion , the next thing to work out was, how do I draw shapes and lines on an HTML page? So prior to this my only experience with drawing on an HTML page was this simple badly presented snake game that i had created using the canvas. Anyway for this little project i decided to look around for some libraries that would allow me to draw some shapes and I found a couple of libraries such as Raphel.js and D3.js that would let me draw SVG shapes on a web page. After very briefly investigating them, it seemed that Raphaeljs would be a better fit for my problem and hence i began my SVG drawing journey with Raphael. Now when i think about this problem, i can think of it as a sequential list of little sub-problems that i need to individually solve before i can build my great grand tree drawing solution. This is a slightly larger problem and hence it will be spread ou...

Fun with Recursion: back to basics.

I am currently working on solving a problem that is about trees, lots and lots of them. Looking at this problem, the first thing I realised was that, while I can solve this problem using stacks, this is really a problem for which a recursive solution is a natural fit. Recursive problem solving is something that I have quite lost the hang of in recent years, using only iteration on a day to day basis. Hence I decided to go about rectifying it and learning what is essentially early uni years stuff. This is harder than it sounds, not because of the problem itself but because of how "dumb" I felt, given that this is really something that I should be naturally good at. Now once I got over my emotional issues and hours of self loathing, I actually had a strategy of how I can get better at recursion. The strategy was simple, forget about my work experience, the education, the scientific publications etc etc, all in all swallow my pride and start from...

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...