28 Apr 2012

Bad choices

When you choose one from two suboptimal options, you will be unhappy irrespective of what you choose.  Thinking later that the option you didn’t choose may have been a better one is not productive.  You chose what you chose; just accept it.

23 Apr 2012

Predators and scavengers

Some people are of the “predator” class.  They do big stuff, and they don’t (and can’t) care about small stuff.  And there are people of the “scavenger” class who do the small stuff that the predators didn’t do.

Apple, for example, is a predator.  They make devices like iPhone and iPad that people want to buy.  But the devices often only go 90% of the way.  The remaining 10% needs are served by accessory manufacturers.  People who make hundreds of cases and speakers and all kinds of supplements.  In the system we have, all pieces are important: the predator, the scavengers, and the rest (those who buy things).

Whether you are a scavenger or a predator is determined by several factors, but I believe culture is an important one.  Countries like China or India don’t have as many entrepreneurs as we see in some other countries.  (Being a scavenger is not necessarily a bad thing... after all, their without their contributions the predators won’t have the success they have today.)

What I am wondering about is, how hard it would be for a scavenger to start playing predator.  All my life I have been focusing on small stuff, so I know I’m a scavenger.  But I have this desire to transform into a predator... someone that creates jobs for others rather than someone who finds jobs.  Until now I haven’t found any clue how I can make the switch.  But I’m kinda thinking I’ll eventually figure it out... by copying other predators.  I have a few around me :)

14 Apr 2012

How to add infinite scrolling to Blogger blogs

One nice thing I like about Blogger’s Dynamic Views is that they remove older posts/newer posts links from your blog and load more posts as you scroll to the end of a page.  (This is commonly referred to as infinite scrolling.)  Adding infinite scrolling to your Blogger blog with a traditional template is not that hard.

If you don’t care about the details and you only want to enable the feature on your blog, click on the button below and add the code to your blog.  Infinite scrolling should just work on your blog, in most cases.  If you have a custom template, though, you may need to tweak the code a little.  (Scroll down to “Frequently asked question” section for details.)

If clicking on this button does nothing, or it doesn’t work for some reason, you can add this code manually:
  • Add a HTML/JavaScript gadget to your blog.
  • Leave the gadget’s title empty.
  • Paste the following code as the gadget’s content:
    <script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
    <script type='text/javascript' src='//m-misc.appspot.com/js/blogger-infinite-scrolling.js'></script>
  • Save the gadget, and you’re done.
The code for the widget is available on GitHub.  Feel free to copy or adapt the code.  A few points worth mentioning:
  • This code uses jQuery library, so don’t forget to include it.
  • Custom template blogs may have to change the value of postContainerSelector variable in the code.
  • I have manually added +1 buttons to my blog.  Dynamically loaded posts won’t have the +1 buttons initialised; to fix that issue, I had to call gapi.plusone.go() every time new posts are added to the page.
  • _WidgetManager is a JavaScript object present in Blogger blogs.  You can query this object to find some page metadata.  This code uses _WidgetManager to determine if the current page is showing a single post.  Infinite scrolling is not meaningful when only a single post needs to be displayed.

Frequently asked question

  • Q: My blog uses a script/widget that adds post thumbnails or related posts.  When I add infinite scrolling, only the first few posts have thumbnails/related posts.  How to fix that?
    A: Simple answer is that this script doesn’t work well with other scripts that add content to posts.  But if you are willing to change the code, you can get both scripts to work together.  Right after new posts have been added — which is the line after $(postContainerSelector).append(newPosts); in the script — add the JavaScript that will make your other widget update itself.
  • Q: The script doesn’t work on my blog.  Can you help me debug it?
    A: While I really wish I could help everyone use this script, it’s practically not possible for me to look at everyone’s blog and see what’s wrong.  If I don’t respond to your comment quickly (or at all), it’s because I am just too busy with things like my day job.  I’m sorry I couldn’t help you with your blog.
  • Q: Why can’t I post a comment?
    A: Contact me through Google+ if you need to ask me anything. I believe you can send me a message even if you don’t have a Google+ profile yourself.

Change log

  • Mar 9, 2013: Moved the script to m-misc.appspot.com because Google Code is not setting the right content type.  This disabled the script completely in Google Chrome.
  • Nov 19, 2012: Version 1.6 was released with support for Automatic Thumbnail and Read More.
  • Oct 17, 2012: Version 1.5 was released with support for Facebook buttons and a fix for Disqus integration bug.  Thanks to Alex for sharing Facebook support code in a comment.
  • Oct 11, 2012: Version 1.4 was released with support for Disqus comments.  Do not use this version; Disqus integration is broken in this version.
  • Sep 20, 2012: Version 1.3 was released with support for Google Analytics.  If a blog uses Google Analytics, the script will register all automatic post loading as pageviews.  To Google Analytics, it will look like the reader clicked on the Older Posts link every time the script autoloads posts.
  • May 30, 2012: Version 1.2 was released with fixes for all known bugs.
  • Versions up to (and including) 1.1 have known bugs.

12 Apr 2012

Unfathomable decisions

This has happened to me several times.  I’d disagree with certain decisions other people make and complain about it.  Often I’d get to speak to the people involved in the decisions and they’ve been usually kind enough to explain the reasoning behind it.  When I see the broader picture, those decisions don’t look all that bad.  Once I know the reasons, I cannot be agitated about the current state of things.  With this context, I can make a better sense of what people mean by achieving world peace by making information freely available.

My experiences have mostly been with decisions about computer programs, because that’s what I do pretty much all the time.  I wonder, how different our lives would be if we could somehow know the reasoning behind all decisions our society has made over centuries.  And all the decisions our governments make.  And the reasoning behind every law we need to obey (including state laws, religious laws, etc).  Would Google or some other organisation or movement ever make this a reality?

10 Apr 2012

Why we like (or dislike) things?

One of the things I keep thinking about is what makes us like or dislike something.  We like certain things one day... and the next day we don’t like them.  Or vice versa.  One possible explanation is your current state of mind decides what you think about the things you’re currently thinking about.  When you’re frustrated, you tend to dislike most things you see, for example.  This is succinctly (and beautifully) expressed as உள்ளத்திலே உள்ளதுதான் உலகம் கண்ணா.  This line was very thought-provoking and I have been thinking it to be true ever since I heard that song.

I was on a road trip recently, and I thought all the pictures I took were sloppy.  That’s what I really thought.  Then a friend commented on one picture... and I looked at that picture again with fresh eyes.  This time somehow I liked it a lot.  Something similar happened during my Himalayas trip too.  I thought most of the pictures I took were mediocre... until I incidentally “re-saw” them months later.

For the reason behind liking or disliking things, there’s probably something more going on than just your “current mood”.  While I am tempted to come up with a theory to explain it, I guess I should be patient and observe a little more to see patterns.

9 Apr 2012

Random thoughts from a road trip to north NSW

I travel primarily for one reason: travelling lets me look into myself.  Some random thoughts from a recent 3 days long road trip:
  • I have always wanted to die in a road accident.  During this trip I could think of a (possibly stupid) reason.  Wide open roads are like gods: admirable, having a character, and fear-inspiring.  Dying in a road accident is, in a way, like surrendering to the roads.
  • Travelling in a car is a lot more tiring than travelling on a bike.
  • Being on the road alone makes me happy.  Third day of the trip was the happiest because I drove for about 750km.  Time spent on “touristy things” don’t add up to so much.
  • I really, really, really want to do a 6 to 8 weeks trip covering the full length of Australia Highway 1.
  • During the trip, I easily slept for 8 hours every night.  That’s the “normal” amount of sleep I used to get.  But increased computer time has shrunk it to 6 hours on average, which makes me :(
PS: I took some sloppy pictures too.

1 Apr 2012

Rolling back git commits without losing history

I sometimes introduce a buggy feature to a program and I want to roll it back.  If I had already committed the buggy feature into my git repository, I prefer to keep the buggy commit in revision history... just for posterity ;-)

Finding how to do this was a bit hard, so I’ll document it here.  I know I’ll need to look this up another time; it’s easier if it’s on my own blog :)  The command to roll back to a previous commit is:
git checkout <commit> <repository root>
For example, running git checkout ea2ff0a50 ~/d/prog would restore all files under ~/d/prog directory to the state they were at ea2ff0a50 commit.  Now I can commit the “new” rolled back state with a different commit message, for example “Roll back free penguins feature.  Penguins are too cute to be given away.”

The other approach for rolling back, where you lose the buggy commit for good is to use git reset.