Friday 21 June 2013

Happy Birthday Stack Overflow!!

Today is Stack Overflow's 5th birthday. You know stack overflow,  the most amazing and useful resource for programmers both noobs and experienced alike. Stack Overflow was started by Jeff Atwood and Joel Spolsky in 2008. Among the crowd of forums which more than often were filled with spam or irrelevant answers, that had no mechanism to highlight the best answers, SO came as breadth of fresh air for programmers who were looking for relevant information or lets just say Answers!!

Here you can find the post where Jeff Atwood announced Stack overflow.

Quoting Jeff Atwood:


Stackoverflow is sort of like the anti-experts-exchange (minus the nausea-inducing sleaze and quasi-legal search engine gaming) meets wikipedia meets programming reddit. It is by programmers, for programmers, with the ultimate intent of collectively increasing the sum total of good programming knowledge in the world. No matter what programming language you use, or what operating system you call home. Better programming is our goal.

Although its been only 11 months since I joined stackoverflow, it has become my hobby to check daily for questions. My rep is nothing to brag about, but its not the rep that keeps one going, is it? As a programmer we are always looking to get more information and SO offers real world solutions for real world problems and not just ways to hack code and make things work. Not only this SO and Programmers SE offers us an opportunity to do some general chit-chat also :).

Stackoverflow has more than 5.2m(illion) questions. Programmers, Superuser and Server Fault have more than 357K questions.

Another positive positive that came from stackoverflow's success is that Jeff & Joel did not stop with SO, they created Stack Exchange network, which consist of more than 100 websites, ranging from programming to cooking to lifestyle, making information on internet more accessible.

Some people argue that SO made us lazy and we have stopped reading books and going into depth of what we do, but there are many instances where people went against spoon feeding and redirected the OP to the docs and if still she/he had any doubts, they even explained what it meant.

Yes, I am a fan of SO. It has made me a better programmer, lots better.

So here is to the most amazing & useful site on the net. It has been 5 years & many more to go.

Saturday 15 June 2013

Fixed Table Headers

Persistent table headers our more notorious than one might think. A simple position:fixed on the first row won't do the trick. Now you might ask, why another tutorial on how to fix table headers, when there are many existing solutions.

What I needed to do was a bit different. It was table inside an enterprise web-application, and every column had been allotted different widths, many of the existing CSS/JS solutions required knowing the width of the table before hand to work. So I had to cook up something else.

Position Fixed on Table Header

Whenever we are faced with a situation where we have to make a fixed table header, we first think about fixed positioning. Well this is what happens when we have fixed positioning.


 So, What's the solution?

I observed that if every cell of row had a defined width, It would not collapse like above. But as I said, dynamic tables were not helping. So I created some JavaScript(it uses jQuery too) to give every cell in the first row a width of the corresponding cell in the second row. Here is the code.


Yup that's it. 16 lines of JavaScript to the rescue. The only "Magic" happening here is the 'spacer' row, which    keeps the house in order. As we know that fixed positioning takes the element out of the flow of the DOM, spacer ensures that the second row does not slip below the first.

Any advantages?

There are many advantages IMO, here they are:

  • No fixed width! it does not limit you to have a fixed width on your table, or know it before hand.
  • Runs once. There are solutions that re-position the header every time it slips out of the view.
Tested on Chrome, Firefox IE 9.
Not on mobiles
That's it. Share your views..