Search This Blog

Saturday, May 28, 2011

Embedding Python scripts in your Open Office document.

i am posting about it on my blog even though it has been answered over the open office and python forums a number of times, because, i had a tough time understanding those replies which were very misleading and complicated. So this is one of the simple and easy version which i think would be simple to understand for all.

Share directory for Python macros is /usr/lib/openoffice/share/Scripts/python
as well as ~/.openoffice.org.2.0/user/Scripts/python
while the former allows you to add a macro that would be available to all the users of the system(since Linux is meant for multiuser environment), the latter allows you to add the macros that will be only available to 1 particular user(depending on who's home directry are you in).

Now, it may be possible that you cann't see these directories. well, in that case, you need to create the directory.
i Hope you do know that .openoffice.org would be a hidden type. also, i have seen that the Scripts folder in second case is empty. So, you can just create a directory of name "python" and place your scripts in it.
to make your scripts visible in the macros inside open office, you will have to put the .pyc file in the python folder otherwise it won't show the python script in executable format.
PS> dont forget to make the file executable.
to make the .pyc file from the py file, use the command
python -m compileall filename.py

And do look at the sample code of helloworld place under the /usr/lib/openoffice/share/Scripts/python directory. It will give you a fair Idea about how the macros work inside the open office. It is much more complex than a simple helloworld program of python, because here it is in the form of a Macros rather than a simple python program

NOTE: these fact remains the same in the higher version of open office too. Just the directory under the Home is changed to the subsequent version. eg: ~/.openoffice.org/3/ user/Scripts/python

Friday, May 27, 2011

Being an ENGINEER

The Idea of this post came to my mind when i was sitting with a few friends. A pretty YOUNG friend of mine who is aspiring to become an Army Officer got stuck with a small problem in maths. So, another friend of mine after failing to explain it, referred the problem to me for a solution with explanation. As i started to explain, the things got complicated for the New fresh mind, and Pat came a comment "They are Engineers. They can prove anything... :D". Though it was of-course in a light mood, but it is a general perception about Engineers. This forced me to ponder about what makes others think of Engineers in this manner.
I am Pretty much sure, on the Internet, we all must have read numerous feats of engineers proving the most absurd and impossible things. But did anyone ever think of the reasons which makes us so Creative?? What makes it so easy for us to prove anything and almost everything? Why don't we ever care about what the answer actually comes out to be. All we care about is, “What answer is NEEDED”.

Engineers are not for solving the Problem. But they are for getting the solution of every problem in any possible manner. By Hook or by Crook. Einstien proposed E=mc2 , but it became a headache for the engineers to build a Nuclear Reactor. Shahjahan just wished to dedicate a beautiful Tomb to her late queen, and suddenly it was a headache for the engineers to design something that is worth a wonder for the world. Newton gave us laws of motion and escape velocity, and once again, engineers were called in to make something that could somehow be thrown out of earth's atmosphere(e.g. satellites). But what makes them so? How are normal human beings casted into an entity of a Engineer?

The Answer to these question lies deep. The moment someone decides to be an engineer, it is the end of life for him right after class 10th. Atleast the Social life. He fights to be an engineer. Burning the Mid-Night Oil in the table lamps surrounded by numerous books while the other students of his age-group (who are not planning to be engineers) spend their time dating or partying. While others have to only care about their marks in Board exams, these few "soon to be Engineers" have to worry about their competitive exams in order to get into a college. This is the only stage where they Learn to Solve the questions to get the solution.


Then comes the college. Full of hopes and dreams with the sole aim of enjoying their life in college they enter the class rooms. But their happiness doesn't survive for Long. Here they are Greeted with some more books, old, awkward and unrelated subjects and numerous assignments with UNREALISTIC deadlines. They work hard in a hope to make a good repute among the fellows and the faculties. And a beautiful year comes to an end.
After a Year at college, they are sure about certain things.
a) Studying for a whole Year is a waste of time.
b) If you have to pass, mug up what's written in the book.
c) Appreciation and respect for Aryabhatta for Giving us 0. Most of the problems could be solved correctly in Maths in bottom to top approach considering 0 as an answer.


With the start of second year, they start to get serious about their career. But the Count-less assignments continue. They start to think about what they wanted from life and How they landed down here. Every passing day decreases the count of days in Hell. Their time is either spent hanging out at the cafeteria or the nearby multiplex with their gang.
Learnings:
a) Maintain the Required attendance and don't get Debarred.
b) Assignments would definitely be solved by atleast one of the class Toppers. They can always be copied on the last day.
c) Solve the question from Bottom to Top. Its the only way to solve them. (Especially in MATHS)
c) Never Forget to Buy the Photocopy of the notes at the end of the semester.
d) Once Again the Power of 0 is realized. A 0 is always better than going into -ve. It is an inevitable friend of an Engineer.


And before they could ever know, Half of their college life is over. Now the faculties are cool. But you are not spared of assignments. Faculties get more strict about the snapshots pasted in your Lab file. Total of Internals Depend only on how you perform in your written internal Irrespective of your attendance or the class Performance. And This is Time when they again start to worry about their Future. Some Great Minds choose for an MBA, which they could have anyways done after a simple college(I wonder why they wasted their 4 years). Then there are others who have started to love their life as a GEEK opt for M.S. or M.Tech. And the rest start to worry even more about how are they going to get a Job.
Learnings:
a) How to Use GOOGLE to copy codes/Procedures.
b) How to Copy assignments more efficiently. i.e Copying 2 assignments at a time, Copying an assignment while taking dummy class notes.
c) Facebook could also be used as a very efficient medium for collaboration. And By that i mean, organizing mass bunks and sharing some of the numerous assignments.
d) Doesn't matter how much to study, there is no way you could attempt the full Question Paper.
e) Faculties will still treat you the way they were treated. Use of modern Equipments for demonstrating your project is not allowed as they didnt have them in their time. Your Project marks are ONLY dependent on that particular thing that your examiners used while they were in college, and not on what you have made.


The Fourth year is all About Projects. Making something that is Unbelievable but still achievable. More than making something awesome, it is about making something that SOUNDs awesome. While you still have to attend the college, you have to come up with something NEW, INNOVATIVE and TECHNICALLY NEW with the time left with you when you are at home. And not to forget about the Numerous exams of companies and institutes of higher education.



After Going though all this, in 4 years, i think the only thing that anyone could learn for sure is:
a) You dont have a life because you are an Engineer.
b) Its the Easiest way to make others happy and save your life is to Give them what they want.
c) Methods Don't matter. Only FINAL ANSWER/SOLUTION DOES. Just get the damn answer.
d) You Would never need a Book. They only need 1 month Before the exams. Photocopy of notes is an easy and efficient alternate. Investing your money in a Nice CELL-Phone With wi-fi and 3G/GPRS services is the best option.

Sunday, May 8, 2011

Tata Photon 201e:2009 Not working in Linux.

Got a new data card that is not working on your Linux machine. Well, its not your Linux machine's fault but the manufacturer who thought that its users wouldnt use anything but Windows. this is a very common problem faced by the Linux users. This problem was faced by me recently when one of my frind bought a Brand new Data Card.

It was Tata Photon+ model 201e:2009
From my past experience, i have seen that Linux used to identify such device as a modem and it was a easy task to configure it using the New Network Connection, by simply clicking "Next" button a few times. But the case wasn't the same this time. This modem's hardware turned out to be incompatible and hence there was no support for it by default in Linux. this was Quite surprising for me.
After calling up friends for help who have done it in the past and going through numerous blogs and forums, which asked us to do hoards of changes to a numerous files and execute commands, we all agreed to one solution... "GET RID OF THIS TATA PHOTON AND BUY A NEW DEVICE".

But some things are just meant to happen. A small comment in som blog caught the eye.
It had suggested of making a small change to 1 file and i got my device working.

You are all set to run your device. Make sure you have no other USB device connected on your PC. Incase you have, just remove them and connect them after your Data Card is connected to internet.

To get your device working, First install programs called as
wvdial and usb-modprobe
These programs help to identify your USB device at Modem and then dial through the Modem to connect to internet.
Since i have used Ubuntu this time, hence the following commands. i am sure, this solution would also work with other flavours of Linux too. therefore..

$sudo apt-get install usb-modprobe
$sudo apt-get install wvdial

once you have installed them, you need to add the following two lines in the file wvdial.conf

$sudo gedit /etc/wvdial.conf

add these lines....

Init3 = AT+CRM=1
Stupid Mode = 1

Stupid mode allows the connection to dial through a firewall and Init3 = AT+CRM=1 prevents frequent disconnections.
Also, dont forget to check your Modem type to be Analog. just match each line of your file with the sample shown below. Remove the comments i have written.
Now your file would look like this.


[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CRM=1
Stupid Mode = 1
Modem Type = Analog Modem
Phone = #777
ISDN = 0
Password = internet
New PPPD = yes
Username = internet
Modem = /dev/ttyUSB0
Baud = 9600


and save this file.

To connect to the internet using your Data Card, On terminal, type:

$sudo eject /dev/sr1
$sudo wvdial



and you are done... enjoy. :)