Collapsible comments for Hacker News

Nov 03 2010

Here is a JavaScript bookmarklet to make the comments in Hacker News collapsible (reddit style) by clicking on the [-] icon next to each comment.

[-]

(Drag the above link to your bookmarks bar or right click and add to your bookmarks.)

Usage: When the page is loaded, click on the [-] icon in your bookmarks bar. Each comment in the page will show a small handle [-] to collapse the comment and its children. Once you click and collapse the comment, the icon changes to [+] and you can click again to expand the comment (and its children).

This fixes a few issues with the script by Alexander Kirk, like collapsed child comments expanding when the parent is expanded. In addition to these this script will work in the threads page of hacker news. Also this bookmarklet will load faster than the script by Alexander since there is no call to any external JS file from my server. The only file you have to load is the latest jQuery from the jQuery website and chances are good that the file is already present in your browser cache. (The downside is that you will not be able to get the latest version when I update the code).

If you want to play around with the code, head to github: Collapsible comments for Hacker News

You my also want to checkout the no-nonsense URL shortener bookmarklet. It is super-fast and does not redirect you anywhere. It just displays the shortened URL in the corner of your web page.

2 responses so far

3n+1 Conjecture

Aug 29 2010

The 3n+1 conjecture or the Collatz conjecture is an unsolved conjecture in mathematics. So what is 3n+1 conjecture? From wikipedia:

Take any natural number n. If n is even, divide it by 2 to get n/2, if n is odd multiply it by 3 and add 1 to obtain 3n + 1. Repeat the process indefinitely. The conjecture is that no matter what number you start with, you will always eventually reach 1.

Even though the idea of the conjecture is very easy to understand, it is suppose to be a very hard problem to solve/prove.

I was doing some learning of the 3n+1 conjecture. As naive as I am, I went right ahead trying to prove the conjecture. Now the problem with me trying to solve this hard problem is that I am not even qualified to be called an amateur mathematician. I am just a programmer with a lot of free time. Furthermore, mathematics is an advanced field and I cannot even comprehend the basic literature on the subject. Anyway, working on this was fun and so I thought I would document it here.

First let us start by the assumption that the 3n+1 conjecture is true, i.e, no matter what number you start with, you will reach the number 1 in the end. To prove this, we will use the method of contradiction. This means that we will say that certain conditions should be met if the conjecture is false. By proving that the conditions supplied or intermediate results break down or contradict with the assumptions before it, we can say that the assumption that the conjecture is false, is false.

So now assuming that the conjecture is false, there should be some number(s) that does not reach 1 when the operations are applied to it infinitely. Let us call the smallest of these numbers X.

So X is the smallest number that violates the 3n+1 conjecture.

(1) Assume that X is an even number.

If X is even, the first operation to do would be X/2.

Since X cannot reach 1, X/2 (which is in the same series) cannot reach 1. This means that X is not the smallest number violating the conjecture (X/2 is smaller).

This contradicts our initial assumption and so X cannot be an even number.

(2) Now, assuming X is an odd number.

Odd numbers can be divided into two types (for our convenience).

  1. The numbers that can be represented as 4n+1.
  2. The number that can be represented as 4n+3.

where n = 0,1,2….

(2.a) If X is an odd number of the type 4n+1:

X = 4n + 1

Since X is odd, the first operation to be done on X would be to find 3X + 1.

3X + 1 = 3 (4n +1) + 1
3X + 1 = 12n + 4

Now the resultant number is an even number and so the next operation will be to divide by 2.

(12n + 4 ) / 2 = 6n + 2

This is still an even number and so we divide by 2 again:

(6n + 2) / 2 = 3n + 1

This means that 3n + 1 is also a number that violates 3n+1 conjecture. Now as you can see, 3n + 1 is a smaller number than X (which is equal to 4n + 1).

So again by the method of contradiction we can safely say that the number X will not be of the form 4n + 1.

So finally we are left with odd numbers of the form 4n + 3.

So we know that any number that violate the 3n + 1 conjecture will be of the form 4n + 3.

Proving this last part is left to the reader as an exercise. (I mean, I did try this part for a few days, but it didn’t go anywhere.)

9 responses so far

ReImages – Reload images in web pages

Aug 28 2010

This is a bookmarklet to reload the images in any web page without reloading the web page itself.

ReImages

(Drag the above link to your bookmarks bar or right click and add to your bookmarks.)

You can click the link whenever you want to reload pages in any web page without reloading the page itself. This bookmarklet reloads images in <img> tag as well as background images for any element in the page.

This can be very useful in many cases:

  1. During web development (especially when you are working on an image that appears only after you do some action in the page, like on a pop-up).
  2. When some server (or a stupid firewall or some other device)  serves you old cached version of the images.
  3. When a large image in a page did not load completely and when you try to refresh the page it is still loading the broken version because it gets the image from the browser cache

etc.

This is the initial version. Let us call it v0.9.

I have been using it for a while without any issues, but let me know of any bugs you come across.

If you are a web developer, take a look at the wonderful ReCSS too.

2 responses so far

Books and Blogs

Aug 04 2010

Rant follows.

Reading is taking up much of my free time these days. Of course I am not talking about the reading online. Spending time online has been a huge time sink for me (and as I can imagine, for millions of other people like me) over the years. I have turned to reading books with more enthusiasm ever since I realized that the stuff that I read online does not stay with me for a long while, while the books I read have a profound way of changing the way I think.

Now don’t get me wrong; I am not blindly implying that all the information out there in the web is a waste of time. I am just saying that for me personally, books give more satisfaction when I finish one compared to hundreds of blog entries I used to devour on a constant basis. Even though I have cut short on the number of blogs I visit and the number of articles I actually read, there are communities like Hacker News where I tend to hang out. Hacker News is a great source of news, information and inspiration for the curious type, but it may also have the effect of wasting a whole lot of your time if you start believing that all of the time you spend on Hacker News is productive.

Reading itself is not a productive activity in the absolute sense of the word (or in any other sense of the word I can imagine), but it is a really fulfilling and satisfying experience (not to mention that it strokes your ego when the height of the books you stacked up in your cupboard grows more than that in your close friends’ room). Even though reading books involves seemingly similar activities as to reading a blog, there are some real differences that make them worlds apart in actual utility.

The first is that your mouse is a constant stream of distraction at your fingertips. Every time I read an article, I try (in vain) not to click on the other tabs to check my email or the traffic stats of my blog; not to mention the advertisements and other outbounds links in the same page itself. Even the hyper-links in the article you read are very distracting, according to some [1]. Now that you have noticed it, that is the reason I am not using any hyper-links in the middle of this article. Many of the links in a typical blog post point to the definition of terms in the Wikipedia anyway, and they are not very useful; but I digress.

The point is that just the act of sitting in front of the computer with the goal of consuming the internet translates into thousands of interesting (or irrelevant) articles, news, stories, pictures and videos fighting for your attention. The problem is that you have only a finite amount of attention. You have only a finite amount of stuff you can process per day.Yes, there is a limit to your cognitive ability. This means that there is a limit to what you can read and assimilate in a given time. And this in turn means that all those distractions are getting the way of you learning something useful. Now I am not advocating that you abandon your fair share of lolcats, but rather wondering whether you are spending a lot more time on them than what can be deemed excusable.

The second difference between books and blogs is that a book is a lot more harder to write than a blog post. You can be sloppy while writing a blog post, knowing that you can later change your words as necessary. Books are very difficult to get published compared to blog posts. Getting a decent publisher to publish your book is not going to be easy for you.  This means that only very few books which are written are actually published and whatever is published goes through a good deal of scrutiny and editing which enhances the quality of the material you get to consume. This does not mean that there are no well-written and well-edited articles out there in the web. I am talking about the typical blog post (By the way, referring to the typical stuff is a great way to say anything you want in an argument). Even given these facts, you can find great articles worth reading in the web by following news aggregators like Reddit or Hacker News, but then again there comes the problem of loads of wasted time with these websites. Even though news aggregators are good at finding the best articles in the web, there is one other fundamental difference between books and essays that makes me go back to good books.

The third difference between a book and essays is that a book has got all the time in the world to convince you of the idea that it is trying to sell. Books are usually hundreds of times longer than your typical blog post and this means that a book author can take his time to establish the basics and build on them and the take the reader through the innards of the subject he wants to write about. The fact that a book takes hundreds of pages to present its plot means that the idea the book tries to sell will stay in the back of my mind for many years, compared to an essay whose central thesis will be forgotten in a matter of minutes when other distractions occupy my brain.

So my request to the dear reader will be to complement what you read in the web with some very good offline reading. Good books can change you life, while blog posts usually are not that powerful. And while we are at it, just keep in mind that producing something useful and making something people wantTM is way more better than reading books 24 hours a day.

That’s it. We are done here. Go away.

[1] Experiments in delinkification

[2] Photo credit: somegeekintn

11 responses so far

On Internet Explorer

Jun 05 2010

Web developers always complain about the amazing ways in which different versions of the infamous Internet Explorer break their websites. Currently there are three versions of IE found in the wild to give nightmares for any decent web developer – versions 6, 7 and 8. I think the problem with IE is not just about the IE team’s reluctance to conform to the latest web standards.

The biggest problem with IE is that its release cycle is a total failure. It is obvious to everyone but Microsoft. Below listed are the years in which three different versions of IE were released:

  • IE6 – 2001
  • IE7 – 2006
  • IE 8 – 2009

Compare this to the recent major point releases of Google Chrome:

  • Chrome 3 – 2009
  • Chrome 4 – 2010
  • Chrome 5 – 2010
  • Chrome 6 – 2010 (expected)

Some might argue that it is not fair to compare just these dates without knowing the details of the version-ing system the browser teams use, but let me tell you that this argument would still not help turn the blame away from the IE team. Google Chrome released many small updates even between these major releases and sometimes even in a weekly basis.

The web browser should not be considered as just another desktop application. It is something that billions of people use every single day. It is the most important application in your computer. It is something that should be updated at least every month or so rather than every 5 years. Currently the patches from Microsoft for IE are related only to security issues. Meanwhile Firefox too is thinking about making their update mechanism silent and automatic (ie without user intervention) similar to what Google Chrome does. If the IE team is not going to release updates for their browser frequently enough why bother releasing it at all?

Now think about it in clear terms – A lion’s share of users are not diligent enough to care about the version of the browser they are using. Outside the tech world, many do not know about the availability of better browser versions. You have to update the software without the user taking the initiative. How hard is it to figure out this?

If you go to the IE9 site, you will see the following score for IE9 preview version in the Acid3 test:

Impressive? Barely so. The current version of Google Chrome (5.0) already passes the Acid3 test with a score of 100! On top of that there are still no reliable reports on when this priceless edition of IE9 will finally ship after all these months of working on polishing the CSS rounded corners. Yes, there are lengthy posts in the IE team blog about how closely they follow the specs of CSS rounded corners, while they don’t dare to open their mouth about the <canvas> tag!

IE9 boasts hardware accelerated graphics rendering for faster performance, but what that means is that IE9 will not be available for windows XP users. Keep in mind that Windows XP is the most used operating system in the world. This in turn means that when IE9 is released, web developers will have to support four different versions of IE.

One part of me prays that they ship a better version of IE soon, while the other paranoid part of me prays that they stop shipping IE altogether. Keeping the history of IE in mind, I do have reasons to be paranoid.

Links:

  1. IE team blog
  2. The CSS Corner: About CSS corners – IEBlog
  3. IE9 Acid3 Test

5 responses so far

What programming language should I learn?

Mar 02 2010

Sameer asks what programming language he should learn. Below is an edited version of my reply.

The plumber comes to your home and asks: “What tool do you want me to use?”.

What will be your reply? “I don’t care! Fix the damn problem”.

That’s right. Everybody wants to get their work done, and get their problems fixed. They don’t care what tools you use. As a developer your job is to solve problems your costumers have in the most effective manner. This in turn means that you cannot use the same tool for every type of problem. Can you use an electric driller to fix a small leak in the pipes? No. You may want to use the duct tape for that.

Which language should I learn is a wrong question to begin with. Languages are tools in the bag of a software engineer. Before deciding upon the programing languages you want to learn, you should decide what type of problems you would like to work on. Would you like to work on web technologies? Would you like to work in the Linux ecosystem? Would you like to work in the mobile platforms? There are a million different niches in programming world and you have to ask yourself all those rhetorical questions that comes to your mind and then decide which language suites your choice.

This does not matter that the tools are not important. They are; but they are not more important than the problem at hand.

How many programming languages should you learn?

There is no point in trying to learn as many languages as you can. What you should do is to try and learn about as many languages as you can, and then decide which languages you should gain expertise in.

Going back to our analogy, what tools do you think a plumber should carry in his bag? “Enough tools to get his work done.”

Exactly. If you know to use just one tool, you may be forced to work with other people who can use some other tools. This happens in most corporate IT companies. In large companies you will be working with other people who have expertise in programming languages and tools which you don’t know how to use. This has the advantage that these people will be real rock-stars in their own narrow fields. Instead if you want to work in places like startups (or if you want to work as a freelance developer), you may want to know a little bit of every type of tool out there.

Of course you don’t have to know to use every type of screwdriver. You just have to be expert in using one good screwdriver model. Similarly you don’t have to be an expert in every web development language. Just learn a pretty decent one and you should be fine.

Every programming domain has its set of tools to help you develop softwares. If you are developing an enterprise website, you may be working with technologies like Core Java, Servlets, EJBs, XML, Unix Shell Scripts, Log parsers, Databases, Various web-servers etc. This means that in addition to programming languages there are many other technologies related to programming that you should master in order to be a good programmer.

One more thing you should know – all the programming languages are inherently different from each other. Some languages are easy to program in (eg Python) while some others are difficult (C/C++). I am not referring to the expertise needed in learning the language. I am referring to the effort required in writing a program after you learned the language. If you work as a programmer in an IT company, you will probably learn a new language (may be as per business requirements) in a very short time span. You will start writing decent code in about 1 week to 3 months time. Then the only thing that will matter is which language you really prefer to work with. So don’t worry much about which langauge is easier to learn; worry about which language is easier to use. (There is a correlation here though. You will find that in most cases the languages that are easier to learn are the easier to program in too)

You can learn a lot about programming from forums were smart programmers hang out (eg Proggit and Hacker News), read the top articles and ask your questions there; you will get in-depth answers.

The biggest secret:

You will become a good programmer only by – programming a lot. Many students don’t program outside their labs and college projects, and they never become good programmers. Try to do some coding in your free time. Try to solve Project Euler problems in your favorite programming language, or try to build a website of your own.

Having said all these here are some specific tips. These may or may not work in your case:

  • Enterprise development: Learning Java is a good. Java is used in many software shops as the primary language. It will take you a long way in most situations. At the same time, I have some objections with using the language from a startup programmer point of view. Read the discussions here too.
  • Web development: Stay away from PHP. It is a badly designed language. Instead, learn Django or Ruby on Rails. If you prefer Microsoft technologies use ASP.Net MVC.
  • Windows development: Learn C# (and probably not Visual Basic). For running C# applications in Linux, check out the Mono project.
  • There are many excellent programming tools or IDEs you should try to master. Eclipse is a popular IDE. Notepad++ is a popular code editor.
  • You should be learn about stuff like Regular Expressions, Unicode, Information Security etc. (I cannot even attempt to list all the topics)
  • Try to keep up with new technologies. You don’t have to learn all the latest languages, but try to have an awareness of the latest trends in programming. For example, web development, mobile phone development etc are areas where lots of innovations are happening. You don’t want to miss any of those if you are intersted in those fields. Then again, the forums I mentioned above will come handy.
  • Learning just one language is not very good idea. Learning a lot of languages is also not a good idea. Strike a balance between the two extremes and try to be good in at least 2-3 different programming languages in different fields. (As explained earlier, different languages are used to solve different types of problems)

Good luck!

63 responses so far

Wanted: Superman

Feb 08 2010

Some time back, I could not resist sending the following reply to this person at the recruitment agency:

Dear Sandhya,

Is this a joke? Did anyone really go through the so called assignments before forwarding them to me? Are they asking me to build two full-fledged websites in 12 hours? Best of luck finding candidates who can do that.

BTW, if you can get candidates to build these sites for you, why do you have to recruit them? I have to admit, this is an excellent way to get your works done for free.

I am sorry. I genuinely not interested in working for such a stupid company.

(Thanks for contacting me with the offer though. Really appreciate that. Let me know if there are openings in companies which are not looking for superman as their programmer.)

- Niyaz

I am refraining from attaching the two assignments they asked me to complete before the interview. Not because I don’t want to expose the actual company that tried to trick me into building the websites for free, but because when you see the requirements which will make Facebook ashamed of themselves, it will make you sick for the rest of the day.

4 responses so far

« Newer posts Older posts »