Archive for January, 2008

VPython-Python module for 3 Dimensional scientific programming

Friday, January 18th, 2008

Battle with VPython was pretty good. In my opinion VPython is a very powerful one. VPython is very interesting to make small applications. First of all we have to install VPython which is quite easy. Also we can mix music & such multimedia along with our applications, for that we just need to install python-gamepy package. Its not only for playing music but also we can add up many more things.

apt-get install python-visual

It will be very useful for implementing physics applications, students can visualize their experiments and study easily with the help of VPython. They can easily write a small code set of their experiment with the formulas.. Coding in python won’t be a big problem even for a newbie :) . VPython documentation is very simple with proper examples which will make our task much more easy & interesting.

hello

“HELLO” as 3D

VPython will help us to plot graphs of the equations and which can sense the mouse click, key board interactions etc. So that we can easily implement anything as we wish.For all these things we have plenty of functions in the VPython library.

Mouse clicks

We studied a lot of stuffs with sine and cosine functions , VPython made the plotting of such functions very easier.Just try the following for getting a cosine curve

from visual import * # just to import your visual python
scene.title = "Cosine Curve"
scene.center = vector(0,0,0)
xaxis = box(length= 20, height=0.2, width= 0.5, color=color.orange)
cosinecurve = curve( color = color.blue, radius=0.2)
dt = 0.2
for t in arange(0,10,dt):
dydt = vector( t,cos(t), 0 );
cosinecurve.append( pos=dydt, color=(1,0,0) )
rate( 500 )

Just run your .py program to get a cosine wave in ur window .

Cosine Wave

While our code is running, VPython runs another program (“parallel thread”) which periodically gets information about the attributes of our code segment.
For example for finding out the position of a object, need to specify velocity of the ball ,then take a small interval of time dt , we knows velocity=displacement/time ,so we have current position , so adding current position with the product of velocity and time gap will give you the periodic updates of the position of that object using a parallel thread. So which making our task simple :)

so its worth trying on VPython :) Links to get the materials on VPython

Print

Anvil: GUI development Framework in Ruby

Monday, January 14th, 2008

Recently i have done a small experimentation on Anvil – A ruby framework to create GUI based applications.The back bone of Anvil is WxRuby. At a glance i thought it will be very easy, so decided to to give a try :)

sudo apt-get install anvil

This installs anvil and all the other required gems. Then running the command

anvil my_editor

Creates a project my_editor. Anvil follows MVC architecture. Browsing through the new project’s folder structure, we can see folders and files for inserting our Models, Views and controllers.

cd my_editor
anvil

A window pops up..! Now we just need to add GUI components as we require, in the respective views and controllers.

I was very excited to see the ease with which i could build an GUI application with Anvil but i couldn’t finish by the end of the day as i had wished. I was getting some errors while using “button” method. It was saying NoMethod error :( . But couldn’t find any error that time & tried a lot then i came to know that the WxRuby that got installed was the latest version and in documentation of Anvil was with an older version. Then i tried with “evt_button” of the new version and it worked.

I found Anvil and WxRuby very useful in building GUI applications.

Print

Fun with Instant Messaging in Ruby

Monday, January 14th, 2008

While i was going through Redmine’s source code, trying to fix some email notification bugs, I felt it would be good if instant messenger notification was also available.So i decided to give it a try. I was sure it would be cool if i could write my own programs to communicate with my IM friends, even though it may not be very ‘useful’ :)

1. How to connect and communicate with IM servers.

XMPP/Jabber protocol is used for interaction with IM servers. Ruby has a xmpp4r library. I also found a xmpp4r-simple library which was built on top of xmpp4r, very easy to use and would serve my purpose. So i chose xmpp4r-simple.

sudo gem install xmpp4r
sudo gem install xmpp4r-simple

2. Connecting to GoogleTalk

Since Gtalk supports Jabber, i decided to do my experiments using Gtalk servers.

I started off with a program that connects to google talk, authenticates and sends “Hello” to a predefined user.

chat0.rb

(Replace the username, password and destination_username in the code with with actual ones. Login to destination_username’ in an IM to see our code running)

3. My first chat program – autoreply

A program that will simply send a predefined message in reply to every message it receives from any user. May be when you are busy, instead of setting status as “busy”, you can simply run this program, so that it sends some appropriate reply automatically.

auto_reply.rb

4. Echo Chat

Program that will simply send back whatever message it receives. Sure this will baffle your IM buddies :)

echo_chat.rb

5. Normal Chat

normal_chat.rb

User1 sends a message,user2 responds, again user1, then user2 and so on. But if user1 wants to send a message before user2 responds, its not possible here since its a single threaded program, which will block,waiting for user2′s response.

Using 2 separate threads for listening and sending solves this issue.

chat_final.rb

6. A remote shell

Well, my next idea was to simulate a remote shell over IM. ie To run commands on a remote machine and get the results through IM.

remote_shell.rb

How good it be, if you could say “geyser ON” on your IM, on your way home, which turns on the geyser at your home, so that you have warm water ready by the time you reach home? :)

Theoretically, we can do it like this:

i. Connect the geyser to your parallel port (ofcourse not directly, there should be some relay/switching device in between), so that a TTL HIGH on one of the parallel port pins, turns on the Geyser.

ii. Write a simple C program named “geyser”(or might be in Ruby itself, i am not sure if we can do it in Ruby), which talks to the parallel port. On running this program with argument ON, it should produce HIGH on one of the parallel port pins, and OFF should make that pin LOW, so that we can use this program to turn the geyser ON and OFF.

iii. Now we can run this “geyser” program through our “IM remote shell”. So you say “geyser ON” in your IM, it turns the geyser ON.

7. IM based dictionary service

You wanted to know the French equivalent for the word ‘yesterday’. You have an IM called ‘french-bot’ , you just send him the word “yesteday” through your IM and he (or she – as you wish) immediately sends you back the French word for “yesterday”. Wont it be cool?

Here is your French-Bot :)

french_bot

Thats all for now. Playing with IM was really fun.

Print

Why Zed’s post is good for Rails

Saturday, January 5th, 2008

Unless you’re living in a cave or have been celebrating the new year a little too enthusiastically, it is hard to miss Zed Shaw’s rant about Rails. Honestly, I am not in a position to comment about most of the stuff that is in there. I don’t know any of the core Rails members, neither the assorted celebrities of the Rails world. But one thing is true: Zed has made valuable contributions to the Rails community, he does make a few points which are worth noting.

His performance bugbear did a lot of good in making Rails deployment easier. I still remember what a pain it was to get Rails working with Apache2. Until mongrel came along. Briefly, fastcgi with Lighttpd worked, but it was never a complete solution because we lost some of the great Apache modules like mod_svn and mod_dav_svn. When mongrel came along, everybody enthusiastically embraced it, as it fixed a big painpoint.

So if somebody who did so much for the Rails community says it is a ghetto, probably we have to sit up and listen. His emphasis on empirical evidence behind the slowness of Ruby/Rails stack is correct. We cannot fix something unless we measure the extent of the problem clearly. And we should rise above our personal opinions of others to evaluate the solution in a community. I would say, this is the time to be gentle with Zed, fix the problems, and invite him back into the community.

That is not to say I completely agree with the article. It could have been much better if names were not taken, not because it destroys reputations, but because it makes the writer look bad. Sometimes, you have to let the problem correct itself. As long as the markets and community are involved, it normally does. I would say the article would have been as effective, if not more, if Zed explained the problems in an even handed manner. The community has enough goodwill for Zed to believe what he says even without taking names.

We love you, Zed. Please come back. Even if you choose to stay away, you will continue to inspire a lot of Ruby folks, and your parting shot will be remembered not for its’ vehemence, but as a wake-up call. Thank you.

Print