MailAlert

I never liked the idea of logging into my mail account every now and then to check mails. Though, i use Thunder bird but that seems to be not enough for me. I wanted someone to notify me when there is a new mail on my gmail account. So, for notification i considered twitter because i always keep track of my twitter time line. Here is the idea: When there is a new mail tweet me.

For that i wrote a python script which is constantly running on my machine which notifies me by sending a tweet when there is a new email.

ChatterBot

I have been thinking of integrating a jabber client with ELIZA. Fortunately, i got the eliza implementation in python by Joe Strout. So, i wrote a jabber client called ChatterBot and integrated it with ELIZA, which will keep engaging your google friends while you are busy with other stuffs.

As of now its very basic and could possibly be improvised.

Sieve of eratosthenes

While reading this post by Christophe Grand(popularly known as cgrand on IRC).

I was tempted to implement Sieve of eratosthenes by my way in clojure.

So, here is my version using Swiss Army Knife:

prime

Mutability v/s Immutability

At times, data mutability could be dangerous. So, i have tried to figure out “Why mutability is not required”
by performing operations on list in Python and Clojure.

In Python:

>>> lst = [12, 31, "foo"]
>>> lst.append(30) # append operation is destructive
>>> lst
>>> [12, 31, "foo", 30] # So, the actual list is modified

In Clojure:

user> (def lst '(12 31 "foo"))
#'user/lst
user> lst
(12 31 "foo")
user> (conj lst 10)
(10 12 31 "foo")
user> lst
(12 31 "foo") # the original list remains intact

Most objects in Clojure are immutable. When you really want mutable data, you must be explicit about it, by creating a mutable reference (ref) to an immutable object. You create a ref with

user> (def lst (ref ‘(12 31 “foo”)))

The ref wraps and protects access to its internal state. If you look at the ref itself, you will not see its contents:

user> lst
#<Ref@1b5a40a: (12 31 “foo”)>

To read the contents of the reference, you can call

user> (deref lst)
(12 31 “foo”)

You can use @ reader macro instead of deref function

user> @lst
(12 31 “foo”)

Now, you can modify the actual list like this

user> (dosync (alter lst conj 10))
(10 12 31 “foo”)
user> @lst
(10 12 31 “foo”) # Modified list

Conclusion: I am a python fan boy but clojure seems to be far better than python in terms of Data mutability.

Parsing Json data using Clojure

So, here comes my first post on Clojure. Clojure seems to be an extremely powerful language with an extensive support of neatly written libraries. I have written a small code which calls the MailChimp api method listMembers (Api returns the hash maps of vector) and parses the json response and finally returns a list of emails.

(import '(java.net URL))

(use 'clojure.contrib.json.read)
(use 'clojure.contrib.duck-streams)

(def *url* "http://api.mailchimp.com/1.2/?output=json&method=listMembers&apikey=YOURAPIKEY")


(defn fetch-url
"Return the web page as a string."
[]
(let [url (URL. *url*)]
(with-open [buf (reader url)]
(apply str (line-seq buf)))))


(defn get-email-list
"Parses json response and returns a
list of emails"
[]
(let [data (read-json-string (fetch-url))]
(map #(% "email") data)))

get-email-list function returns:

user> (get-email-list)
("foo@gmail.com" "bar@gmail.com" "foobar@gmail.com")

Why don’t oldies get deserved respect.

IPL is on, and everyone is talking about it every second. One thing i have noticed that senior players like Rahul dravid, Sourav ganguly, V.V.S laxman et al are under scanner. Critics are just keeping an eye on every ball, Every ball they miss while batting or fielding, people are ready to criticise.

During the matches when they face a dot ball, they feel embarrassed as they have done some crime. When players like yuvraj singh or any young player misses a shot..I don’t see any one complaining about that. So, i was thinking. Why exactly this thing happens. Does this thing only happen in cricket? I guess it’s “NOT”. It happens in every field. Older people are considered less productive, less efficient, less active. I think age is NO BAR as long as you keep up the pace with new generation. Sometimes experience counts. Like in the second last match between Kolkata night riders and Deccan chargers. McCullum is young, dynamic and brilliant player but that does not mean he is experienced enough to lead the team. Not atleast infront of Ganguly who is still india’s most successful test captain.

Hence, my overall idea is that a good, swashbuckling cricketer can not always be a good captain. Captaincy is much more about innovation and solid knowledge of the game which only comes through ages of Experience and during the course of achieving this you grow old. Which means oldies are a bit more better than the youngster. We should give them respect. :)

Another Fan of Star Wars

Phew! I finished watching all the STAR WARS Episodes. Extremely interesting movies. Actually, Earlier I had only watched one episode that was “The Phantom Menace” in the year 1999. The truth is i didn’t like it much. May be because i didn’t watch the previous series and was not aware of the entire concept. Recently, I got suggestions that i should watch it in the order the film was released.

A new Hope[1977] — Episode-IV
The empire strikes back[1980] — Episode-V
Return of the Jedi[1983] — Episode-VI
The phanton menace[1999] — Episode-I
Attack of the clones[2002] –Episode-II
Revenge of the sith[2005] — Episode-III

I followed this and it really worked. I am an idiot being a die hard movie lover “How come i missed this cult movie”. All the six episodes are fantastic and my favourite character is Master Yoda.

Lisp to Python

The journey from lisp to python has been very unexpected but i must say it was interesting. There is a famous line about python

“Everybody who tries it falls in love the first time. You’ll never meet a single chap who’s tried
python/Iron Maiden and not liked it”

I completely agree with, it happened in my my case too. Well, Lisp will always remain my favourite language. It’s functional approach makes it wonderful and one of the most powerful language. But the web development support for lisp is not so amazing. Though, there are many useful external libraries available at Cliki. Anyway, it’s hard to get the proper documentation.
In case of python you have one giant framework called Django. It has all the stuffs from Development server to Templating system. I am just discovering its power.

Man v/s Woman

The diagram above shows the thought process in a man vs. woman's
brain when this simple question phrase is asked by their
partner/friend:

"Shall we go for a drink?"

Posted via email from Atif’s posterous

Posterous.com rocks!

I just got to know about this service from my friend. It’s really a cool service. Just mail anything you want to get the content published at your multiple accounts i.e blog, twitter, flickr. One single email post@posterous.com will do the work.

Like the way i have published this article on my blog using this service. So, Shoot one mail and keep yourself free from useless issues.

Posted via email from Atif’s posterous