Friday, March 11, 2011

Convert .vmg nokia messages (SMS) to text using Python

I had saved a bunch of messages from my Nokia N73. I wanted to get a quick summary of the content in all those messages. So I just wrote a python script to read all the messages and print the output to a file.

import sys
import re
import os

path = "msgs"
filesList = os.listdir(path)
regexPattern = 'Date:(.*)END:VBODY'
searchPattern = re.compile(regexPattern, re.DOTALL|re.I)

compileOutFile = open("Summary.txt", 'w')

for fname in filesList:
    fullFname = path+"/"+fname
    fileLine = open(fullFname, 'r').read().decode('utf-16')
    matchObj = searchPattern.search(fileLine)
    compileOutFile.write(matchObj.group(1))
    compileOutFile.write("\n")
compileOutFile.close()


Thanks to this guy: http://www.xiirus.net/articles/article-decode-or-convert-_vmg-files-to-_txt-using-c-980ut.aspx

Without which it would have been difficult to figure out that the file is Unicode encoded. I was breaking my head for hours trying to figure out why my regex was not working. It was not the regex, but the string was read wrongly and hence the regex was failing.

Hope this helps someone.

Wednesday, November 17, 2010

Changing Directory Listing (ls) Color in Linux and Mac OS X

Saving it for future purposes in case the original article gets lost.

Original Post: http://wuhrr.wordpress.com/2009/04/25/changing-directory-listing-ls-color-in-linux-and-mac-os-x/#comment-3413
 

Problem
I practically “live” on the Linux command line and one thing that has been bugging me for so long that now I decided to do something about it. On my company’s Linux systems the ls command produces color output, which makes it easy to distinguish different file types. However, the directories are dark blue which makes it nearly impossible to see against the black background.
My Solution
To fix the problem, my research took me to the LS_COLORS environment variable and a command named dircolors. The solution is to set the LS_COLORS environment variable to control how the ls command chooses its color. I can set the LS_COLORS variable manually, but there is a better way which employes the dircolors command.
The dircolors command output commands to set the LS_COLORS environment. It also output the colors in human-readable format, allowing easy modifications.
To use the dircolors, the first step is to save the current settings into a file. From the terminal, I issued one of the following commands:
dircolors -p > ~/dircolors.txt
The next step is to edit the file ~/dircolors.txt. This file’s format is easy to understand and self-documented; I had no problem finding the file that begins with “DIR” and change the color to my taste.
Next, I try out the new color scheme:
eval $( dircolors -b ~/dircolors.txt ); ls # bash shell syntax
    eval `dircolors -c ~/dircolors.txt`; ls # C shell syntax
After finding the color scheme I liked, I saved it to my start up file:
dircolors -b ~/dircolors.txt >> ~/.profile # bash shell
    dircolors -c ~/dircolors.txt >> ~/.cshrc   # C shell
From this point on, I no longer have to put up with hard-to-see colors.
Solution for BSD Systems
On BSD systems, which includes the Mac OS X, the variable in question is LSCOLOR (note the lack of the underscore character). The format of this variable is different from the Linux’s LS_COLORS. The default is exfxcxdxbxegedabagacad. The value of this variable consists of pairs of characters; the first character is the code for foreground color, and the second is for background. Please consult the man page for ls on BSD for more information.
The Interactive Solution
While I like to do things the hard way to learn more about the inner-working of the OS, there is a more interactive way: point your browser here to an interactive online web application which assist you in setting the colors. After finding your desired color scheme, you still have to cut and paste it to your start up file.
Additional References
Google is your friend: do a search for LSCOLORS or LS_COLORS will result in more information that you ever care to read.

Thursday, August 12, 2010

Number of distinct users on linux/unix server

Today I was wondering if there was a way to figure out how many users were using a particular linux server. A simple thought that first came to my mind was couting the number of users in the output of 'ps -ef' command.

A simple 'wc -l' would give the number of lines in the output of 'ps -ef'.

The next step would be to just get the first column to get rid of the duplicate usernames.
'ps -ef | cut -d' ' f1' gave me the required output. Now the next step was to get only the unique entries. And the 'uniq' built in utility came to rescue.


The final command : 'ps -ef | cut -d' ' -f1 | sort | uniq | wc -l'

08/14/2010: I just realised that sort has an inbuilt option of unique
Instead of redirecting the out of sort to unique, one can use 'sort -u'

08/14/2010: Also instead of using 'ps -ef' command, one can use 'w'
Note: This command takes into account of the header row too. So the count would be count-- :)
08/14/2010: grep has an inbuilt option of '-v'which allows for invert matching. So the previous problem noted can be removed by adding 'grep -v UID'



The revised final command : 'w| cut -d' ' -f1 | sort -u | grep -v USER | wc -l'

08/14/2010: One final issue that I still see is the first line is taken into account here apart from the header.
 17:54:01 up 39 days, 10:20, 359 users,  load average: 0.59, 0.28, 0.15
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

Monday, November 30, 2009

Need for an OP AMP circuit

Today I was working with an optical encoder (Agilent QEDS) that's found in one of the old printers. The encoder has two channels which gives two signals with a phase shift of 90 degrees. I was trying to read the signal in LabVIEW using PCI 6035E Data Acquisition Card (DAQ). But the moment I connect the pin of labview, the signal was getting lost. Then after doing some research I found out that I need to isolate/condition the signal since the DAQ needs more current than the encoder can provide.

So there was a need for buffer. I first used 74367 IC but it didn't work out. The next thing I came across was to use a voltage follower circuit using an op amp. Picked up a LM324 IC and quickly hooked up the voltage follower and BOOM ... the signal was ready to be used in LabVIEW.

You can look at this link for detailed information: http://en.wikipedia.org/wiki/Operational_amplifier_applications

Conclusion: If there is any sensor which generates a signal with a very small current and you need to maintain the same voltage, use an op amp voltage follower to condition the signal to get a higher output current.

------
Note: Once my project is complete I will surely post the complete details.

First POST !!!

Hi,

Thanks for visiting my blog. I have been using various resources on the internet for my personal use, be it for my projects or assignments etc. I feel it's time for me to share some of the things that I have learned. So here is my blog which has various useful stuff for FREE.

You are free to use the information in this blog for any kind of purpose.

Thanks,
Silver Hawk.