code formating

Wednesday, June 23, 2010

Nokia SMS to flat files

I have a Nokia phone. It's quite a simple phone compare to the androids and iPhones we have on the market but nevertheless it makes calls and sends messages. From time to time though, it gets full of sms messages and I tend to archive them to have them all in secure places.

Using Nokia suite, on a Windows PC I have access to (the machine is not mine), I can download all the messages however they are in vmg format.

I have written a small Erlang module to convert this files to plain text. I might extend this module in the future, for now, it's so small that I'll post it here. The only parameter we need to pass to the exported function, is the path to the folder the vmgs are on. It will loop through every file and create an equivalent txt with the same name in the same place.
-module(nsc_to_ascii).
-export([convert_vmg_to_txt/1]).


convert_vmg_to_txt(PathToFolder)->
%%get all the svg files in the folder
L=get_list_of_full_path(PathToFolder),
lists:map(fun(FullPath)->
B=read_file_to_binary(FullPath),
write_file(filter_file(B),get_new_extension(FullPath))
end,L).


write_file(Binary,Path)->
file:write_file(Path,Binary).

filter_file(Binary)->
filter_file(Binary,<<>>).
filter_file(<<>>,Acc)->
Acc;
filter_file(<<0,Rest/binary>>,Acc)->
filter_file(Rest,Acc);
filter_file(<<B:1/binary,Rest/binary>>,Acc)->
filter_file(Rest,<<Acc/binary,B/binary>>).

read_file_to_binary(Path)->
{ok,Binary}=file:read_file(Path),
Binary.

get_list_of_full_path(DirectoryPath)->
{ok,L}=file:list_dir(DirectoryPath),
lists:map(fun(FilePath)->
DirectoryPath++"/"++FilePath
end,L).

get_new_extension(FullPath)->
Length=length(FullPath),
case lists:sublist(FullPath,Length-2,Length) of
"vmg" -> lists:sublist(FullPath,1,Length-3)++"txt";
_ -> ""
end.

Friday, June 18, 2010

Ledger the ledger

Ones upon a time, there was a consultant. He only had one client nevertheless he had to pay his taxes. He had to pay insurance and phone expenses. He also had to pay car expenses and he wanted to buy a house. All these numbers started getting messed up in his head and he needed a way out.

After checking out few finance management software he decided stick with ledger. Hell! that ones a right choice. He never had to look back.

Stories aside, life it's never a flat walk but if you are keen on learning, ledger is really a strong alternative. You keep all the transactions in a flat file which you can edit with you favorite editor. An example of a transaction follows:

2010/06/11 cash
Expenses:Other 140 EUR
Assets:Bank:HSBC
On the 11nth of June a transaction with a concept of "cash" was made. 140 Euro where transferred from HSBC to an Expenses:Other account.

The most important capability, is however, the ability to query this ledger. Summon the command "ledger" on the command line and a big universe opens before us. With -f "theledgerfile.dat", we choose a file that contains our ledger. Note that we can keep separated ledgers if we wish. The bal tag displays balance and the reg tag displays more detail. Finishing the command with any string, will filter the results to match the string entered.

ledger -f "ourledgerfile.dat" bal HSBC
This command will display the balance of the HSBC account.

There are many tags and possibilities I'm not going to get into now but they are very well explained on the documentation. The documentation can either be found on the source
code or on the downloads page.

Programatically walk a CATIA tree in .NET

One of the most basic tasks when automating anything in CATIA, it's usually to walk the whole tree and apply some changes to objects in ...