• Home
  • About Me
  • Musings
  • Programming
  • Computers
  • Open Source
  • Society
  • Books
  • Design
  • Movies
  • Logi XML BI Tool

    For the current project that I am working on, we were looking for alternatives to the SQL Server Reporting Services. We ended up with a really good BI solution, LogiXML.

    LogiXML is a XML based reporting solution available for .net and Java platforms. More information can be found in their website, www.logixml.com

    To us, it really simplified the way we used to work on reports. It was something similar to the Sagitec Studio, that we use in our work everyday (Sagitec Studio is for Web Development, developed and used as a product by my current employers), which meant lesser learning curve. The AdHoc Reporting capabilities is what caught our attention. It is neat, the LogiXML team has thought through most of the aspects of Reporting.

    All common reporting functions, with an excellent support team. They have always responded quicker. The product is well documented and supported. If I like one reporting tool, it must be LogiXML. Will definitely recommend it to anyone.

    .Net 4.0 Client Profile

    .Net 4.0 introduces the concept of Client Profile. I came to know about it when I was adding references to my project file. Even though, I had added a few assemblies in the project reference, the compiler was complaining of not finding the namespaces in the references that I have added during compilation.

    The project was a Windows Form Application. I opened up the Project Settings Page to see that the

    Target Framework was .Net 4.0 Client Profile.

    I changed it to .Net 4.0 Framework. Everything worked fine.

    So to get past the error of missing namespaces, even though the assemblies having been added, check to make sure that the Target Framework is not in the Client Profile.

    Converting Rows to Columns in SQL

    There was this table,

    ORG_ID     LEGACY_ORG_CODE
    ------      ------------------
    1001         8909
    1001         12323
    1002         80909
    1002         78798
    1002         09009

    and the requirement was to get the concatenated legacy_org_code like

    ORG_ID     LEGACY_ORG_CODE
    ------      ------------------
    1001         8909, 12323
    1002         80909, 78798, 09009

    The solution to this is:

    SELECT PL.ORG_ID,
    	(SELECT LEGACY_ORG_CODE + ','
    		FROM SGT_ORG_PLAN ORGPL
    		WHERE ORGPL.ORG_ID = PL.ORG_ID
    		ORDER BY LEGACY_ORG_CODE
    		FOR XML PATH(''))
    	 AS ORG_CODE
    FROM SGT_ORG_PLAN PL
    GROUP BY PL.ORG_ID

    I was looking for simple answers on the web I came across this link, that helped me to get it done in a simple SQL statement. Recording it here for future reference. This technique is called Blackbox XML.

    New Look : Arjuna Theme

    One among the new year resolution is done. And on the same new year’s day. My site now has a new look. I have been wanting to do this for more than a year now, and I never pushed myself to sit and do it. What better time to do it, than in the vacation. And so, here is the new look for the site. I have decided to call the new theme “Arjuna”.

    Arjuna: means ‘white’, ‘clear’. It is a Sanskrit word, and the name of one of the Pandavas, in the Mahabharata.

    This theme is a white theme, minimal, and subtle in expression. Being my first side project, I was a bit confused in choosing a name. I chose this because, it was somehow connected to the ancient literature of my own country.

    Feel free to download, test and report any bugs that you encounter.

    Happy New Year 2010

    Wish you all a very Happy New Year 2010. Let this year bring prosperity and joy to all.

    This is the time to reflect back on what happened the previous year, and plan for the coming year.

    What happened in 2009?

    • Completed my one year in Sagitec.
    • Had been continuously writing on this blog.
    • Got my first ever proposal.
    • Accepted her as my better half.
    • Got my first onsite offer, to work in America.
    • Came to USA on a H1B permit and currently working.

    Wishes for 2010:

    • Get happily settled in life.
    • Get a new look for this site.
    • Get CowsNBulls game to the next level.
    • Learn a new language apart from C#, looking at python and ruby.
    • Live happily ever after.

    Once again, wish you all a very happy and a prosperous new year.

      C#: Calculate Age in Years, Month and Days

      Today I was given the task of finding the age of a person, provided the birth date. When I was given the task, I just said, just use the DateDiff function. But it is not that simple.

      One thing I wanted was to keep the code simple and in a few lines of code. Here goes my first iteration.

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      
               static void CalculateAge()
              {
                  DateTime dateOfBirth;
                  DateTime.TryParse("02/18/2008", out dateOfBirth);
                  DateTime currentDate = DateTime.Now;
       
                  TimeSpan difference = currentDate.Subtract(dateOfBirth);            
       
                  // This is to convert the timespan to datetime object
                  DateTime age = DateTime.MinValue + difference;
       
                  // Min value is 01/01/0001
                  // Actual age is say 24 yrs, 9 months and 3 days represented as timespan
                  // Min Valye + actual age = 25 yrs , 10 months and 4 days.
                  // subtract our addition or 1 on all components to get the actual date.
       
                  int ageInYears = age.Year - 1;
                  int ageInMonths = age.Month - 1;
                  int ageInDays = age.Day - 1;
       
                  Console.WriteLine("{0}, {1}, {2}", ageInYears, ageInMonths, ageInDays);
              }

      But then, there were problems with this method. If the current date is ’06/18/2009′ and the birth date was ’04/18/2000′, it returns, 9 yrs, 2 months and 2 days. The 2 days part is wrong. I didn’t have any clue as to why it appears.

      Then I went down to the basics, using elementary mathematics of subtraction. Here goes the second iteration of the code.

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      
              static void CalculateAge2()
              {
                  DateTime dateOfBirth = new DateTime(2000, 6, 18);
       
                  int ageInYears = 0;
                  int ageInMonths = 0;
                  int ageInDays = 0;
       
                  CalculateAge(dateOfBirth, out ageInYears, out ageInMonths, out ageInDays);
       
                  Console.WriteLine("{0}, {1}, {2}", ageInYears, ageInMonths, ageInDays);
              }
       
              ///
              /// Calculate the Age of a person given the birthdate.
              ///
              static void CalculateAge(DateTime adtDateOfBirth, out int aintNoOfYears, out int aintNoOfMonths, out int aintNoOfDays)
              {
                  // get current date.
                  DateTime adtCurrentDate = DateTime.Now;
       
                  // find the literal difference
                  aintNoOfDays = adtCurrentDate.Day - adtDateOfBirth.Day;
                  aintNoOfMonths = adtCurrentDate.Month - adtDateOfBirth.Month;
                  aintNoOfYears = adtCurrentDate.Year - adtDateOfBirth.Year;
       
                  if (aintNoOfDays < 0)
                  {
                      aintNoOfDays += DateTime.DaysInMonth(adtCurrentDate.Year, adtCurrentDate.Month);
                      aintNoOfMonths--;
                  }
       
                  if (aintNoOfMonths < 0)
                  {
                      aintNoOfMonths += 12;
                      aintNoOfYears--;
                  }
              }

      And it works like a charm for all scenarios I throw upon it.

      Scenario 1:
      Current Date : 15 – 09 – 2009
      Birth Date : 09 – 03 – 2000

      Just a difference gives the result
      Age : 6 – 6 – 9 Result is 9 yrs, 6 months, 6 days.

      Scenario 2:
      Current Date : 15 – 09 – 2009
      Birth Date : 28 – 07 – 2000

      Here since 15 – 28 < 0: we borrow one from the month and then add the no of days in the month to the current date. 15 + 30 = 45: 45 – 28 = 17 days
      Then since one month is borrowed: 08 – 07 = 01 months
      Remaining is normal difference
      Age : 17 – 1 – 9 Result is 9 yrs, 1 months, 17 days.

      Scenario 3:
      Current Date : 15 – 09 – 2009
      Birth Date : 28 – 12 – 2000
      Here since 15 – 28 < 0: we borrow one from the month and then add the no of days in the current month to the current date. 15 + 30 = 45: 45 – 28 = 17 days
      Then since one month is borrowed: 08 – 12: So we are supposed to borrow a year and add no of months in current year to current month. 08 + 12 = 20: 20 – 12 = 8 months
      Since a year was borrowed: 2008 – 2000: 8 yrs
      Remaining is normal difference
      Age : 17 – 8 – 8 Result is 8 yrs, 8 months, 17 days.

      But I know there must be better ways to do it. Feel free to drop in code snippets. Comments too are most welcome.

      Programming Fonts

      Little lately, I am obsessed in finding the best font to use, when I do the coding. I try to keep the same font across all editors and IDE’s that I use. The first font that I loved was ‘Courier New’ set at 10pt.

      Then with VS2008 came in a new attraction for Consolas a true type font from Microsoft. Consolas is really good. And it appears even better on TextPad, jEdit and VS2008 IDE.

      Last month, I began using Anonymous font. I would have sworn by it, if not for Monaco.

      Now I use only Monaco. Smooth and pleasing! So what fonts do you use.

      Fixing libmysql.dll issue in Rails

      To fix the error, “This application has failed to start because LIBMYSQL.DLL was not found. Re-installing the application may fix this problem.”  while working on rails using mysql as the database, 

      Copy the libmysql.dll found in the mysql installation directory (mysql\bin) and paste it in your ruby installation directory (ruby\bin)

      Restart the server and viola, the error is fixed.

      Permalink Structure Changed

      The permalink structure of this blog has been changed following advice from Sudar. Originally the permalink structure was /archives/%post_id%. Now I have changed to /%category%/%postname%.

      I was quiet apprehensive to change at first, coz, I didn’t want the links to be broken and an ugly 404 – Page not found error to be displayed. There is a plugin from Dean Lee site.

      It makes the migration hazzle free. In the PermalinksMigration plugin setttings page set the old permalink structure. In the Permalinks settings page, set the new permalink structure and it is done.

      There is one thing I’m still concerned about. On the Codex page, it is instructed to avoid using /%category%/%postname%/, stating performance reasons. But this structure looks more elegant. Can anyone give me more insight into this?

      Being a Code Monkey!

      Code Monkey: n, a person who writes computer code for a living.

      The term code monkey generally refers to a computer programmer or other person who writes computer code for a living. More specifically, it refers to a person only capable of grinding out code, but unable to perform the more intellectually complex tasks of software architecture, analysis, and design. The term is thus considered mildly insulting, and is often applied to the most junior people on a programming team.

      That is how wikipedia defines the term. I keep asking my self this question, Am I being a code monkey? I know I am better in converting a business requirement into code, than bother about what it implies to the business. I generally suck at testing. Testing is not my job, I can’t possibly find fault in my code. I write a piece, test it, if it succeeds in the first attempt, rather than delving to fix negative scenarios, I move on to the next requirement. Ipso facto, I am a code monkey.

      I, like most of my friends who work in software companies, just write half baked code for a living. We don’t create; we just fix code, if I have to properly call it. Most of us (software or IT professionals) in India, never realize that we are bad programmers. We have full blown IDE in our office, and we just churn out thousands of lines every day, without ever looking for alternative ways. If something bothers us, there is the ultimate destination, Google; just search, find and then Ctrl + C and Ctrl + V code, never understanding it. I am not blaming those who put effort to understand it before using it. I am just speaking about the mass of the programmers.

      Why don’t we realize? That’s because, we get the job done in time. At the end of the day, what matters is the output. We all try to make the management happy. What they need is delivery on time, and we are very good at it and also in times of crisis. Stay late, complete the work and you end up getting an ‘Exceeded All Expectations’ in your annual appraisal. With that comes a salary hike. What more do we need?

      So why am I complaining? I have a job, I get a decent pay, everyone is happy out there, being a code monkey is not a big thing to worry about, many (I didn’t want to use a most here, and hurt the reader’s ego) of my friends are also code monkeys. Why is there a need for this post then?

      I would have lived in the glory of my ego, if not for reading through the posts of Jeff Atwood and Steve. They are two people whom I admire for their writing on programming and programmers. Jeff admires Eric Lippert and Steve admires Knuth. So to me what are Eric and Knuth, programming Gods!!!

      Steve says in one of his posts

      Almost everyone thinks of their programming ability as being just fine, plenty good enough. They can get by, get the job done, do pretty much anything they’d need to do, given time and patience.

      It’s quite a nasty shock for many of our interview candidates when they find they’re unable to do something as simple as reverse a linked list, or open and write to a text file. They’re not shocked that they can’t do it; they’re shocked that we’d ask. Those are specialty skills, and not their specialty. They haven’t been doing much “low level” stuff like that lately.

      Not all interview candidates are shocked when they can’t do it, because many of them don’t realize they’ve written something that could never work: broken code that’s not even remotely close to a correct solution. These programmers are particularly cheerful, being so clueless that they don’t even know they’re clueless.

      Jeff says in his post,

      There are two “classes” of programmers in the world of software development: I’m going to call them the 20% and the 80%.

      The 20% folks are what many would call “alpha” programmers — the leaders, trailblazers, trendsetters, the kind of folks that places like Google and Fog Creek software are obsessed with hiring. These folks were the first ones to install Linux at home in the 90′s; the people who write lisp compilers and learn Haskell on weekends “just for fun”; they actively participate in open source projects; they’re always aware of the latest, coolest new trends in programming and tools.

      The 80% folks make up the bulk of the software development industry. They’re not stupid; they’re merely vocational. They went to school, learned just enough Java/C#/C++, then got a job writing internal apps for banks, governments, travel firms, law firms, etc. The world usually never sees their software. They use whatever tools Microsoft hands down to them — usally VS.NET if they’re doing C++, or maybe a GUI IDE like Eclipse or IntelliJ for Java development. They’ve never used Linux, and aren’t very interested in it anyway. Many have never even used version control. If they have, it’s only whatever tool shipped in the Microsoft box (like SourceSafe), or some ancient thing handed down to them. They know exactly enough to get their job done, then go home on the weekend and forget about computers. 

      It hit the nail. Once in an interview I was asked to write a program for a linked list, I was dumb struck. The interviewer was a ex-employee of Microsoft. He just posed this question as the first one in the interview. I just drew the Linked List representation and told him this is the algorithm. He wanted me to write the program on paper. I just couldn’t get it done. (It is a different story that I came back home furious about myself and settled down to complete writing the program in one sitting. I could not get it when it mattered.) That is when I knew, I am a terribly bad programmer. 

      I have been living in a Matrix(Movie), like Neo, oblivious of the fact that real programming is not what I do. Real programming is a lot more than what I do. Reading through the writings of Steve and Jeff, I realized I am being presented the red pill. I could either take the red pill and delve deep into the Truth, or just ignore it, and continue my living.

      I am taking the red pill!!!

      There are a few of posts that I would recommend to the curious reader.

      Being the averagest

      Practice Programming

      Skill Disparities in Programmers

      Separating Programming Sheep from Non-Programming Goats

      Mort, Elvis and You

      Two types of programmers