Sunday, 16 December 2012

Apple Magic Mouse with Dell Latitude E6520

Recently, I found some free time at office and my colleague's Apple magic mouse was lying on my table. It sure is a cool device. So, I thought why not connect it to linux and see how it works. So, I turned on the bluetooth daemon on my system with the following command.

systemctl start bluetooth

I use Bluedevil. So, I clicked on the tray icon and ran a scan for bluetooth devices in range. The pairing key required is 0000. Initially the mouse pointer movement was too fast and scroll was too slow. So, I changed the configuration using this blog.

It is cool, indeed. However, I found it difficult for regular use because I am not used to it and it is a touch mouse unlike other mice. When I am moving the mouse, I have to make sure my index finger is not touching the surface, else there is unwanted scrolling.

Friday, 14 December 2012

Enjoying writing

Recently while waiting for a flight at Mumbai domestic airport, I decided to write down my thoughts. Of late, I have been writing on some keyboard mostly but this time I was writing with a pen and I actually enjoyed doing it. So, I write  about writing only. This is what I wrote:

Is it possible to write with this pen?
Well not completely impossible. Also I realize the benefit of writing with a thick pen. With a thick pen, you tend to write each letter well while with a thin pen, you write a letter away [especially the letters towards the end of word]. [It] Reminds me of a friend who recently advised me to try a thick pen and I have to admit I am really loving this experience. At school, I hated writing with a thick pen because it slowed me down. However, now that its not my writing speed by my writing that I care about, I think I will use this thick pen more often.


Compared typing on a keyboard, while penning down the flow of thoughts was better. I liked it and decided to do it more often.

Friday, 16 November 2012

UTF-8 encoded Rails Console in linux

Although, initially while working on Rails project, we do not pay much attention to the character encoding, soon it bites us bad. When we try to play with a string containing Unicode characters in an ASCII encoded Rails console, it complains about it and we are stuck.

It is quite easy to get a UTF-8 encoded Rails console. All we need to do is properly set the LANG environment variable of the terminal first.

export LANG=en_US.UTF-8

Rails picks up this variable and sets its encoding. So, when we fire up Rails console now and enter the following command, it shows that we have UTF-8 encoded console.

puts __ENCODING__

Now, we can easily play with UTF-8 strings.

Sunday, 4 November 2012

Skype uses its own DNS

Skype is a really interesting software. Its text chat UI is mature and audio and video chat facility are very nice. Skype has this interesting ability of working independent of the DNS configuration of your system. Even when the DNS server your system is configured for, gets poisoned, Skype does not get affected.

In fact, I leverage this ability of Skype to detect network issues due to DNS service being down. On such an occasion, when the browsers were not working but Skype was, I pointed my DNS configuration to Google's DNS servers (listed below) and the browsers worked fine.

8.8.8.8
8.8.4.4

To take a deeper look, I tracked the connections Skype was making. I used the following to do that.

netstat -taucp | grep skype

Initially it was sending out packets from port 51395 of my localhost. After I logged in, I find the following connections:


tcp        0      0 *:42520                 *:*                     LISTEN      19207/skype      
tcp        0      1 H:47078          111.221.77.159:40016    SYN_SENT    19207/skype      
udp        0      0 *:42520                 *:*                                 19207/skype      
udp        0      0 localhost:51395 *:*                                 19207/skype

H about is the hostname of my system and the IP 111.221.77.159 is owned by Microsoft, Microsoft Singapore to be specific. Interesting sequence of connections, when I lookup a contact and open the corresponding chat window.


tcp        0      0 *:42520                 *:*                     LISTEN      19207/skype      
tcp        0    516 H:46808          193.95.154.39:33033     ESTABLISHED 19207/skype      
tcp        0      0 H:47078          111.221.77.159:40016    ESTABLISHED 19207/skype      
udp        0      0 *:33626                 *:*                                 19207/skype      
udp        0      0 *:41980                 *:*                                 19207/skype      
udp        0      0 *:42520                 *:*                                 19207/skype      
udp        0      0 localhost:51395 *:*                                 19207/skype      
udp        0      0 H:32897          *:*                                 19207/skype

The IP 193.95.154.39 maps to Skype Technologies. After sending a line of text on  the chat window, the following connections were made.


tcp        0      0 *:42520                 *:*                     LISTEN      19207/skype      
tcp        0      0 H:46808          193.95.154.39:33033     ESTABLISHED 19207/skype      
tcp        0      0 H:47078          111.221.77.159:40016    ESTABLISHED 19207/skype      
tcp        0    236 H:44172          157.56.123.82:https     ESTABLISHED 19207/skype      
tcp        0      1 H:45020          91.190.216.9:www-http   SYN_SENT    19207/skype      
tcp        0     75 H:48246          78.141.179.14:12350     ESTABLISHED 19207/skype      
udp        0      0 *:33626                 *:*                                 19207/skype      
udp        0      0 *:42520                 *:*                                 19207/skype      
udp        0      0 localhost:51395 *:*                                 19207/skype      
udp        0      0 H:32897          *:*                                 19207/skype

The IPs 157.56.123.82, 91.190.216.9, 78.141.179.14 map to Microsoft Corp Redmond, Skype and Entreprise des Postes et Telecommunications respectively. After that, when I was not doing any more activity on Skype, the following network activity was seen.


tcp        0      0 *:42520                 *:*                     LISTEN      19207/skype      
tcp        0      0 H:47078          111.221.77.159:40016    ESTABLISHED 19207/skype      
tcp        0      0 H:47362          db3msgr6011307.ga:https ESTABLISHED 19207/skype      
tcp        0      0 H:48246          78.141.179.14:12350     ESTABLISHED 19207/skype      
udp        0      0 *:42520                 *:*                                 19207/skype      
udp        0      0 localhost.localdo:51395 *:*                                 19207/skype

db3msgr6011307.ga does not have any DNS entries. Suggestions for digging further are welcome.

Saturday, 6 October 2012

Formatting column entries for IN query

Extracting entries of a column in a spreadsheet and using them in an IN query is not a rare scenario [at least for me] at work. Now, copying and pasting the entries in a comma separated and sometimes quote-enclosed format is tedious and when there are 100 entries, doing that by hand is unacceptable for me. On top of that when each entry has to be modified a bit before passing in the IN query, then the whole process becomes drudgery. Today, when faced with such a situation, I used emacs and sed to save myself a lot of time and boredom.

Let us consider that the spreadsheet has a column that has the following entries:

12345-1
23456-2
34567-1
45678-1
56789-1

Now, lets consider that I have to strip the first suffix, enclose the values in quotes and pass them in the IN query. So, I copy the column and paste in a text file and run the following commands on the file.


sed -i 's/-1//' ./myfile.txt
sed -i 's/-2//' ./myfile.txt

Now the file had the following contents.

12345
23456
34567
45678
56789

Now, I opened the file in emacs and ran a keyboard macro to get the following string.

'12345', '23456', '34567', '45678', '56789',

Now, I could easily use it in my query. Now, the macro I used was simple. I started recording the macro using `C-x ('. The macro consisted of the following keys in sequence [try it yourself to be clear]:

' -> End -> ' -> , -> Delete -> Space

I ended recording the macro using `C-x )'. Now, I had one line edited so I let emacs run the macro 4 times using the following command:

C-u 4 C-x e

I got the inspiration for using macros in the following video.


Thursday, 13 September 2012

JVM crash: an eye opener

I had done some programming but I guess I had not hit many walls. In C, my programs had segfaulted; but every time that happened I knew that my program broke; but there was never a notion of the programming environment breaking down. I, of course, know that when one is coding specifically to break the environment, it is not impossible; but I am talking about cases when the break is not intended. I could never imagine the shell, in which I am running a program for connecting to some website and getting some data, breaking down in between the running of the program.

However, recently I was using Rubymine to test some XML parsers I had written and suddenly it crashed. Initially, I thought may be Rubymine crashed, so I went back to shell where I had started it. To my utter surprise, it was the JVM that had crashed. That is when it hit me that programming environments can also crash. I have reported the bug; but there is not much done from Oracle's side about it.

Well, I do not expect much from them either; but the lesson I learnt is valuable: it is not only the program; but also the program's environment that can crash. Its not that I did not know it but it is not something I regularly expected. From now on, I will though. It did change the way I looked at errors. I guess this is what counts as experience.

Thursday, 30 August 2012

Showing tmp folder in Rubymine

I have been using RubyMine for a few months now. I must say it has served me well. Recently, I was writing and reading files in the /tmp folder of root directory of my Rails project. However, in my project pane, it was not showing the /tmp folder. So, I had to go to the folder using my file manager and check the files. When I was through with my task, I wanted to figure out why that folder was not shown in the project pane. Getting the folder to show up was easy. In the project settings, in "Project Structure" section, there is a list of excluded folders. We just have to remove the entry for the /tmp folder.

Monday, 6 August 2012

Using sed to remove unwanted lines

I have written about sed's utility before as well and it has impressed me time and again by the amount of time it saves. Recently while testing E17, I generated backtraces using GNU debugger. However, the file to which I redirected the backtrace contained a large number of lines about reading and loading symbols. I wanted to quickly get rid of those lines so that the developers can directly view the backtrace instead of scrolling down pages before the actual backtrace. So I decided to use sed for the purpose. The approach I took to achieve my desired result was as follows:

  1. I wanted to deletes lines that mentioned about loading or reading symbols. So, the sed operation I required was delete matching lines.
  2. I wanted to edit the files. So, I turned the edit in-place option on.
With this approach in mind, I ran the following two lines and the file was formatted properly.

sed -i '/Reading symbols/d' my_file
sed -i '/Loaded symbols/d' my_file

N.B.: If you want to test the output, remove the -i option.

Thursday, 2 August 2012

Audio settings for Skype on Archlinux

By default Skype on Arch linux does not take input from the microphone. It is usually because the channel to capture audio input is set to zero. It can be easily changed in alsamixer. Start by running the command alsamixer in console.
The default view above does not show all channels. Hit F5 to view all channels and increase the values of the channels 'LR Capture' and 'Digital' as shown below.