Sunday, August 31, 2014

Avoiding automatic indentation when pasting code into vim

I am a vi user and use vim almost daily. One issue that has troubled me is that vim automatically inserts indentations to already well-indented text when I paste the text, e.g., bibtex entry, program segments, into vim because I enabled "autoindent". A solution to address the problem is to inform vim that you are about to paste and then vim will simply paste the text as is,

  1. In vim command mode, type
    :set paste

  2. Then, in vim edit mode, paste the text
  3. Finally, in vim command mode, type
    :set nopaste

The credit goes to this Stackoverflow post.

To make switch the paste option on or off easier, we may map the commands to a key or a key sequence. For instance, we can define a mapping ",p" to switch the paste option on or off in the vim command mode by adding the following code snippet into the .vimrc file (located at the $HOME directory),


let mapleader = ","
nmap <silent> <leader>p :set paste!<CR>
 \ <Bar>:echo "Paste: " . strpart("OffOn", 3 * &paste, 3)<CR>
set nopaste

The "echo" part above displays an indicator to show whether the paste option is on or off.

Saturday, August 30, 2014

Firefox 64-bit Nightly, Google Account, and FireFtp Addon ...

I have been a long-time Firefox browser user. Recently I have started using Firefox 64-bit Nightly, the 64-bit Firefox browser that is still in testing.

My experience suggests that the 64-bit version appears to have a better performance when compared with its 32-bit counter part -- well, this is just my feeling and I don't have objective data to back it up; it could have been the result that I restarted the 64-bit version more often than I did with the 32-bit version that eventually became almost frozen and had to be restarted.

A definite beneift, perhaps, just a short-term benefit, is that I can continue to use my beloved FireFtp addon.  FireFtp addon somehow did not catch up with version updates of the 32-bit Firefox and is now disabled by the lastest version of the 32-bit Firefox. However, I found that the 64-bit Firefox does not have the problem.

Besides, my own experience is that the 64-bit Firefox is quite stable and it only crashed a few times in more than a month.

The only problem that I really need to deal with when I use the 64-bit Firefox is the problem with signing into any Google account, e-mail, blogger (this blogger), voice ... The problem is that  from time to time, when I tried to sign in a Google account after a restart of the 64-bit Firefox, the Google sites report an error,

Oops! Your browser seems to have cookies disabled. Make sure cookies are enabled or try opening a new browser window.

The error message puts the blames on "cookies". In fact, regardless, following the steps from Google Support, such as this one, how I enable cookies on the browser, remove any history, and cached items, the problem remains. Finally, I realize that it is not a probem  is not with the cookies at all.

The solution is quite simple -- it is the 32-bit Firefox. Whenver the problem occurs, I follow the steps below,

  1. Close the 64-bit Firefox immedialy, no need to meddle with cookies, web histories, and caches;
  2. fire up the 32-bit Firefox;
  3. log onto any Google account once using the 32-bit Firefox;
  4. and then close the 32-bit Firefox;
  5. finally restart the 64-bit Firefox.

Eureka! Wahla! I can now sign in any Google accounts.

So what's wrong with Firefox 64-bit Nightly? The problem may not be with Firefox; instead it may be a problem with Google, as indicated in this bug report -- I guess in this case the 32-bit Firefox sets the values of the relevant attributes to those that Google expects.


Problem Adding Google Account to Android Devices

I was trying to add the required Google Account to an Motorola Android phone and encountered a problem. The error message states,

Can’t establish a reliable data connection to the server.  This could be a temporary problem or your SIM card may not be provisioned  for data services. If it continues, call Customer Care.
Google searches produced numerous hits. I tried a few and they did not work for me.

After a little bit careful investigation, I noticed that the time displayed was far off. Although I checked the "Automatic Update Time" option, the device did not appear to update the time to a correct one. My understanding is that when the time is far off, any security protocol using SSL will not work as it requires the messages are time stamped recently, well, to prevent varous forms of the message replay attacks. Then, I used the following solution and it worked.

  1. Uncheck the "Automatic Update Time" option
  2. Manually set time to a correct one. I  used the clock on my computer as a reference. It does not have to be very precise. But, do note that the time zone on the Android device may not be the one your computer is in. If it is the case, you may use a time reference that is in the same time zone of the Android device (e.g., The Official NIST US Time); or simply set the time zone on the Android device to the time zone of your reference time. 
  3. Now add your Google account. It should work now.