British Telecom and Emacs

As I moved to Airbnb host in London and opened my laptop for getting some work done tonight – much to my chargin Emacs won’t start and just hang during startup.

One of the problems of constantly tweaking your editor configuration is – you blame yourself if things go south and I did promptly. Tried to revert to an earlier version of Emacs configuration, tried to undo some of recent shell config changes but no avail.

Very quickly though, I figured out – Emacs is hanging while loading tramp.el. Now that was weird – I wasn’t actually using tramp; it was just being loaded by rubocop.el which I use
when writing Ruby. Removing rubocop.el made Emacs go further but it still got hung bit later.

I enabled debug-on-quit thingy in Emacs and tried to manually load my ruby-mode settings (which included loading rubocop.el) and pressed Control-G when it got hung and I got some error from:

 (setq result "-o ControlMaster=auto")))
   (unless (zerop (length result))
            "ssh" nil t nil "-o" "ControlPath=%C" "host.does.not.exist")

Further research pointed me to bit of tramp code that defines a custom variable to select ssh-control options. The variable has
a default value which gets determined by trying to SSH to an non-existant host called host.does.not.exist. I know what you are thinking, stupid – right?

Thankfully they are trying to fix it –

So, where does BT come in all of this? If you fire your terminal and try to ping host.does.not.exist you will probably get:

hyperion? ~> ping host.does.not.exist
ping: unknown host host.does.not.exist

Not on the connection I was though. BT in its infinite wisdom has configured routes to unknown hosts to hop all over the place and as a result any attempt to ping or ssh to unknown hosts will result in ping/ssh command to wait for real long time.

This obviously made any attempts to require/load tramp.el while I am connected to BT network hang forever (or real long time). There are couple of workarounds – reduce SSH timeout or make host.does.not.exist point to etc.

Eulogy of a Singer

Jagjit Singh – my all time favorite Singer died today.

I never met him or communicated with him beyond listening to music he put out and yet I feel deep sense of loss today. As popular Hindi Music degenerates itself, I know a era has gone by – that will not come back and will not be felt ever again.

He himself did not write most of his songs but his greatest achievements perhaps was – he made works of great Urdu poets accessible to people. I wouldn’t know or appreciate work of, Mirza Ghalib or Mir – if not for Jagjit Singh.

I should perhaps link to one of his songs in this post, but the truth is – I can’t. There is just too much out there, which is outstanding and I can’t pick one. But as Mirza Ghalib said:

Woh Firaq aur woh Wisal Kahan ?
woh shab-o-roz-o-maah-o-saal kahaaN ?
fursat-e-kaarobaar-e-shauq kise ?
zauq-e-nazzaraa-e-jamaal kahaaN ?
thee woh ik shaKHs ke tasavvur se
ab woh raanaai-e-KHayaal kahaaN ?
‘eisa aasaaN naheeN lahoo rona
dil meiN taaqat jigar meiN haal kahaaN ?

Using Emacs for editing and properly formatting commit messages

As long as I remember, I have always been committing code to git from Command Line. Haven’t really used emacs and git integration. Unfortunately, that also meant – I was using vim from Command Line, for editing commit messages and doing interactive rebasing and stuff like that.

Today, I sat down and figured – how to do this properly from Emacs.

  1. Setup a emacsclient to open in terminal. I have following shell script, in $HOME/bin as fast_emacs:
    /Applications/ "$@" -t -a /Applications/ -nw

    If you are using Linux, the script can be simply changed into:

    emacsclient "$@" -t -a emacs -nw
  2. We also need to ensure that, when you are done with window (by pressing Control-X #), the buffers are cleaned up and stuff.
    (add-hook 'server-switch-hook
    	  (lambda ()
    	    (menu-bar-mode -1)))
    (add-hook 'server-done-hook (lambda nil (kill-buffer nil)))
  3. Next thing is to configure and load git-commit mode, which checks if your commit message is properly formatted or not:
    (require 'git-commit)
    (add-hook 'git-commit-mode-hook 'turn-on-flyspell)
    (add-hook 'git-commit-mode-hook (lambda () (toggle-save-place 0)))
  4. Last thing is to specify fast_emacs as GIT_EDITOR and you should be good to go.

The AppleCare story

We love Apple products, they usually have  excellent products with good hardware. But this post isn’t about, how great they are. This post is about, what happens when in a Country like India, your Apple gizmo falls apart.

Diving in.

I purchased my 15′ Macbook Pro on 18th June 2011 from Reliance iStore on M.G Road Bangalore. On, 1st of July – the machine broke down. After waking up from sleep, the Operating system wasn’t responsive and  I had to hard boot the machine and during the reboot, it got stuck at Gray Screen with Apple logo. Even leaving it like that for hours, did not result in any progress.

I called AppleCare on 2nd of July and they said usually this happens because of  “Software Problems” and we proceeded to reinstall the OS. But the problem was back again 2 days later. This time AppleCare guy told me to erase and install, which I did. At no point, I was asked to run any hardware diagnosis or any kind of tests. The AppleCare apparently operates by gut instinct.

Anyways, coming back – The machine again broke down in same fashion after 3 or 4 days and I called Reliance iStore this time. They asked me to bring the machine. I left the machine with them and after 2 or 3 days, I had to callback and ask whats up with my MBP. They said, they have reinstalled the OS and did not find any problems with the machine (hardware or software).

I was somewhat mad at this point, I told them – The OS has been reinstalled 3 times already, if there is a problem that reinstalling the OS can fix, it should have been fixed first time.  They asked me to contact AppleCare. I called up AppleCare and this is where first thing I learnt is – Call Center Executives in India aren’t authorized to take, how do I put it – any effective decisions. They routed my call, outside India. I waited for nearly 35 minutes and then some guy from Europe picked the call.

This senior executive asked me where I purchased my Macbook from and where I have given it for repair. I gave him the answers and also asked him, if I qualify for “Not-Fit-For-Purpose” program, since machine broke down within 14 days of purchase.  He in turn asked me, Why haven’t I purchased my MBP from an Apple Store? Why didn’t I take it back to Apple Store? He was somewhat clueless about how Apple sells hardware in India. It took me a while to give a picture of; how things stand in India. But the conclusion was, No I can’t get replacement since iStore people haven’t found any hardware problem and I was asked to take my Macbook, back from Reliance iStore.

I took back my MBP from iStore and used it for nearly 5 days. I also did my own bit of investigation in the meanwhile and found that “/var/log/kernel.log” was filled with “I/O errors”. I ran smart-utility and it reported SMART status as FAILING. After 5th day the machine, stopped working again in identical manner.  This time I took the machine to another Service Provider (Ample Technologies) and also purchased Mac Mini 2011 on same day since my work was getting affected.

They took nearly 4 days and asked my permission to erase and reinstall the OS. When I gave the machine to them, the machine was booting, but everything was dead slow and disk was reporting countless errors. After erase and install, they ran some tests and they came back to me, saying machine is fine and I can take back the machine.

To be honest, I was pissed at this point. The OS has been reinstalled 4 times and I showed them “kernel.log” errors, I had screenshot of Smart Utility reporting disk as failing. I started contemplating legal action via consumer courts at this point.

I asked them to use Smart Utility and Smart Monitor. To my surprise, they called in the evening saying – They couldn’t download the programs and if I can send those screenshots via Email.  I sent them the ScreenShot and I also sent them, downloaded version of Smart Utility with Email.

They ran those tests and finally concluded that Hard Disk is faulty. Finally, *win*.

I called Apple Customer relations (Thanks Sidu!) and asked for a replacement. A customer relation executive from Singapore picked my call and after 2 days of back and forth, they agreed to give me a new machine.  I was sent another Email by a lady from Singapore that, my machine has been dispatched and she gave me contact number of Apple local representatives.  It was 6th day  since that Email and in total more than 3 weeks of this sorry episode and I had to leave for Chennai day after tomorrow, so I called the local representative, Schenker India and the they told me, they no longer deal with Apple. *gasp*.

You see the classic disconnect, Apple gives me a number and the dude tells me – his company no longer handles Apple stuff. Fun. I had another number though. And I made few calls to this another number , left a voice message but couldn’t reach him. Fortunately, replacement macbook arrived, as I was packing my stuff for Chennai trip.

The bottom line I think is, Apple India customer support is massively fucked up.

  • Apple India executives have no authority to take any effective decisions.
  • Customers are left to the mercy of resellers and their crappy service. These guy have no incentive to give good customer service.
  • Whatever technical support executives these resellers have are crappy and in my opinion aren’t qualified to troubleshoot problems.
  • Since all decision making happens from Singapore, Brisbane or Europe, there is big disconnect between how things are with Apple India and what these executives sitting in Singapore, Brisbane have been told. It is big pain.


Getting prepped up for Rails hackfest

Listing down things, that you should do – to make best use of Rails Hackfest.

1. Install RVM. The instructions can be obtained from,

2. Install multiple versions of Ruby. Preferably, Ruby 1.9.2-p290, Ruby-1.8.7, REE and JRuby. All of this is, one command away via:

    rvm install ree && rvm install 1.9.2 && rvm install jruby && rvm install 1.8.7

3. Install a decent IRC Client. Mac users can use Colloquy, Linux users can use XChat2. Learn few simple commands. The canonical IRC server which we will be using is, Try connecting to it and see, if you are able to connect to #ruby-lang.

4. Keep Rails code cloned in your local hard disk. It takes time to clone Rails code base and many people cloning at the same time, may slow down things.

5. Install PostgreSQL and MySQL both. Mac users can use homebrew to install via, “brew install postgresql”, Linux users can use apt-get or whatever their distro supports. Also, make sure that, ‘pg’, ‘mysql’ and ‘mysql2’ drivers are working on your machine.

6. If your corporate policy allows, bring your proprietary code. Don’t worry, no one is going to steal it, might be useful in removing the warts and all.

We are all crappy superheros

In the past I’ve tried to say, ‘Look, we are all crappy superheroes,’ because personal computers and mobile phone devices are things that only Bat Man and Mr Fantastic would have owned back in the sixties. We’ve all got this immense power and we’re still sat at home watching pornography and buying scratch cards. We’re rubbish, even though we are as gods. I think the idea that we can all be superheroes if we want might still be contagious, like in V For Vendetta.

Alan Moore

Invisible mode considered harmful

Invisible people are bad. They start with good intentions and all that but eventually turn bad. You just have to read H.G Wells.

I have always hated invisible mode feature of IM clients. I understand why people use it but I hate their reasoning nonetheless. So here is my advice, friends don’t stay invisible to friends.

When you stay invisible and ping a person and start a conversation with him/her, you are being rude. The other person had fucking no way of saying something to you, if he had something urgent about which he wanted to talk. If you are actively using the IM client, turn off invisible mode. People aren’t really dying to talk to you, trust me you are not that important, but someone who is important to you – won’t be able to get his/her message across.

If you are busy and rather do not want to be disturbed, just disable notifications. That way, people can still reach you and you will not be bothered. If you can’t help yourself from checking IM window every 2 minutes, just logout. You can also use ‘status’ icon/message  for letting people know that, you do not want to be disturbed.

When all else fails, you can block people who are excessively chatty. If he is a friend/colleague you can talk them frankly and set some boundaries.

Parallel threads are still a myth in Ruby

Giant Padlock

In the beginning there was a giant lock. It wrapped all your requests and let only one run at  a time. Then it was removed in Rails 2.2, there was much to rejoice and some nay-sayers too. The world moved on, no one knew how many are actually using this new feature. Passenger app instance kept processing only one request a time, anyways. We did our bit of chest thumping and forgot about what good old m.on.key said.

But the debate seems to have been revived with Rubinius planning to remove GIL, JRuby already running threads parallely and finally MRI running native threads. On more serious note, I have been working with Ruby professionally for more than 4 years and I am astonished at anyone who is planning to run Ruby in a parallel environment. Igvita brought up that issue in his post (, but yehuda disagrees.

The problem isn’t whether underlying platform supports parallel native threads or not, but the problem is, does Ruby eco-system supports that?

require "thread"
class Foo
  def hello
    puts "Original hello"
threads = []
threads << do
  Foo.class_eval do
    def hello
      puts "Hello from modified thread #1 "
threads << do
  a =
  puts "After sleeping"
  b =
threads.each { |t| t.join }

Above code runs as expected, but ruby runtime offers no guarantees AFAIK about visibility of modifications in class objects. Lets take another example:

def synchronize(*methods)
    options = methods.extract_options!
    unless options.is_a?(Hash) && with = options[:with]
      raise ArgumentError, "Synchronization needs a mutex. Supply an options hash with a :with key as the last argument (e.g. synchronize :hello, :with => :@mutex)."
    methods.each do |method|
      aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
      if method_defined?("#{aliased_method}_without_synchronization#{punctuation}")
        raise ArgumentError, "#{method} is already synchronized. Double synchronization is not currently supported."
      module_eval(<<-EOS, __FILE__, __LINE__ + 1)
        def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)   
          #{with}.synchronize do 
            #{aliased_method}_without_synchronization#{punctuation}(*args, &block)
      alias_method_chain method, :synchronization

The idea is, you don’t need to start a synchronize block in your method, if you want entire method body to be wrapped inside synchronized block, rather than that you can specify entire contract at class level. Neat!
Except not, how does it work when classes are getting reloaded in development mode? Will this metaprogrammtically created synchronize hold? The answer will vary from Ruby to Ruby to implementation. In parallel environment, it will not.

The problem I am trying to drive at is, Ruby’s memory model makes no guarantees about class state. It’s a problem, no one talks about.

Lets take another example of “thread safe” code, from ActiveRecord connection pool (
Anyone closely reading the code can find few thread problems with the code. For example, “@reserved_connections” seems be read and written by multiple threads without bother. It may work fine in Ruby 1.8 and 1.9, but the code is definitely not thread safe, if multiple threads are allowed to run parallel. A solution would be perhaps to use, concurrent hash (

Where are we getting with this? In my opinion, until Ruby runtime makes guarantees about class state, module state , core threading primitives (Queue, Monitors, MonitorMixin, ConditionVariable) get exhaustively tested, concurrent collections are added; Ruby isn’t ready for parallel threads. In my professional experience, I had several problems with ruby’s default primitives. I was listening to a talk by ThoughWorks folks, who were using JRuby, single VM multiple threads for running rails for Mingle, their problems were simply too hard to catch and hard to debug.

In the meanwhile, Ruby community should focus on getting evented and co-operative threading proper. Fiber is a good start.

Thanks to folks in #ruby-pro for reviewing the post. Specially to James Tucker(raggi)

Debug RESTful calls for fun and profit

When using ActiveResource it can be quite useful to print Webservice calls going out and XML responses coming in. It allows me to debug things, it allows me to create useful Httpmocks for testing code that uses the resource.

Somewhat unobtrusive way of doing this is, stick following code to some library file:

module ActiveResource
  class Connection
    alias_method :old_request, :request
    def request(method, path, * arguments)
      response = old_request(method, path, * arguments)
      if (response && response.code.to_i == 200 && APP_CONFIG['debug_resource_call'])
        puts("********** method is #{method} and path is #{path} ********** ")
        puts response.body

And off I can go with Httpmock

Faster zsh and git integration

There are quite a few zsh init scripts available out there which implement git integration. Unfortunately, they also slow down the shell workflow. I have found myself continuously frustrated by the fact, how much they make switching between directories slower. In the end, I have tried implementing something on my own and result is reasonably faster than `oh-my-zsh` or other solutions.

You can get the code from:

git clone git://

Be warned that, it may or may not work with old version of zsh or git.