The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for the ‘python’ Category

Ruby versus Python versus …

with one comment

It’s been some years since I got off the Java bandwagon. I spent many years on it. and after getting off, it feels like I was in a concentration camp for many years. Strangely, I loved it then. But the freedom from drudgery, great to begin wit,h has left me hanging in mid-air for these four years.

Four years after being seduced by Ruby, I find it is still “getting there”. Many many things are still not present in Ruby, and the status is still the same. I tried Python back then and left it since the syntax seemed awful – all the “self” stuff, no private members — I had had enough of ugly code in Java to like the double underscores, and then the indentation is the block thing.

However, even in 2004. python already implemented a whole lotta stuff. Ruby is fine but not for corporate use, or if you have work to get done with deadlines. I cannot discover in the middle of a program that something has not been implemented in Ruby although there are clearly some classes and methods in the API. I can;t suddenly find that SMTP auth or Unicode etc is not there, or async io, and 4 years later the position on most things is the same. I goto ncurses and I am not so sure – python gives me more confidence. I look at GUI toolkits, wxRuby is almost there, but the developer doesn’t have time yet. Use FxRuby for the moment, and WHEN wxRuby is ready, migrate to that.

That was the great thing about Java. Vendor adoption (due to overhype) was great. There was just Swing, just jdbc, and all efforts were put into one thing to get it to work. No scratching your head to figure out what to use. So today, once again I am wondering whether I should just cut the Ruby hype crap and go to Python. Everything works. Everything is there.

I did find some funny things, though. Lists dont have a join method! You would say “,”.join(list) rather than list.join(“,”). There are many things that are strange in python and ruby coming from Java. I love many ruby features (block_given?) — wow !!! I hope python has all that.

Or maybe I will work on both, and keep getting confused while mangling data structures.

For web, I am thinking it is best to just do something called php. Dump your code on any server and it will work. Add to that most of the apps in high usage including wordpress, wikipedia, phpBB and many many bloggers, CMS’s etc are all in PHP. I can pick some open source software and build over that. Or use some framework.

Youtube and google seem to use python. Python never got the huge hype that ROR got, but still everything already works there. I just wrote an interesting command line app in ruby. I would like to put that up on some site. The only choices I can think of are javascript and php. Both of them I don’t know. Perhaps, i will rewrite it in php and put it up for the public to use. More on that later. I need to see how to upload files onto this blog along with a post, preferably. I hate posting them elsewhere and then linking back here.

Advertisements

Written by totalrecall

August 22, 2008 at 11:20 am

Posted in being_geeky, life, php, python, ruby

Tagged with

sending smtp mails from command line (python)

leave a comment »

First of all, ruby 1.8.x does not have SSL working in SMTP, so forget connecting to smtp.gmail.com. Python and perl have it working beautifully. Here’s a quick example, modified slightly from what I found on the net.

#!/usr/bin/env python
# 2008-07-07 17:33
# use this to send a simple mail from your gmail account
import smtplib
import getpass

def prompt(prompt):
    return raw_input(prompt).strip()

fromaddr = prompt("Login Email Id: ")
name = prompt("My Display Name: ")
subject = prompt("Subject: ")
toaddrs  = prompt("To: ").split()
password = getpass.getpass("password: ")
print "Enter message, end with ^D (Unix) or ^Z (Windows):"

# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
       % (name + "", ", ".join(toaddrs), subject))
while 1:
    try:
        line = raw_input()
    except EOFError:
        break
#    if not line:
#        break
    msg = msg + line + "\n"

print "Message length is " + repr(len(msg))

#server = smtplib.SMTP('smtp.gmail.com', 587)
server = smtplib.SMTP('smtp.gmail.com')
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

If you have only one gmail account, you can hardcode it here. I use this to send an email using an account I use (occasionally) for some fora, this avoids logging in and out of gmail on Firefox. It’s a basic version, no attachments etc.

[Edited in Vim using HTML.vim]

~~~
Beauty is truth, truth beauty, that is all
Ye know on earth, and all ye need to know.
— John Keats

Written by totalrecall

July 10, 2008 at 4:41 pm

Posted in python

Tagged with ,