Connecting to postgres database using jython

import java.sql.Connection as Connection
import java.sql.DriverManager as DriverManager
import java.sql.ResultSet as ResultSet

db = DriverManager.getConnection("jdbc:postgresql://localhost/testdb","db_user","db_password")
st = db.createStatement()

sql = 'select * from stat limit 10'
res = st.executeQuery(sql)
while res.next():
    for x in range(1,res.getMetaData().getColumnCount()+1):
        print res.getString(x),
    print

Original code for Scala from http://blogs.enterprisedb.com/2010/07/08/scala-postgresql-access/

Note: You may have to set CLASSPATH to postgresql-9.1-901.jdbc4.jar which can be downloaded from http://jdbc.postgresql.org/download.html

Encoding files using ffmpeg

Convert to mp4

ffmpeg -i input_file.avi -y -threads 2 -map 0.0:0.0 -f mp4 -vcodec mpeg4 -b 1213 -aspect 16:9 -s 640x352 -r ntsc-film -g 12 -me epzs -qmin 2 -qmax 9 -acodec aac -ab 96 -ar 48000 -ac 2 -map 0.1:0.1 -benchmark output_file.mp4

 

Convert to mov

ffmpeg -i input_file.avi -y -threads 2 -map 0.0:0.0 -f mov -vcodec mpeg4 -b 1213 -aspect 16:9 -s 640x352 -r ntsc-film -g 12 -me epzs -qmin 2 -qmax 9 -acodec aac -ab 96 -ar 48000 -ac 2 -map 0.1:0.1 -benchmark output_file.mov

Struggle is Good! I Want to Fly!

Once a little boy was playing outdoors and found a fascinating caterpillar. He carefully picked it up and took it home to show his mother. He asked his mother if he could keep it, and she said he could if he would take good care of it.

The little boy got a large jar from his mother and put plants to eat, and a stick to climb on, in the jar. Every day he watched the caterpillar and brought it new plants to eat.

One day the caterpillar climbed up the stick and started acting strangely. The boy worriedly called his mother who came and understood that the caterpillar was creating a cocoon. The mother explained to the boy how the caterpillar was going to go through a metamorphosis and become a butterfly.

The little boy was thrilled to hear about the changes his caterpillar would go through. He watched every day, waiting for the butterfly to emerge. One day it happened, a small hole appeared in the cocoon and the butterfly started to struggle to come out.

At first the boy was excited, but soon he became concerned. The butterfly was struggling so hard to get out! It looked like it couldn’t break free! It looked desperate! It looked like it was making no progress!

The boy was so concerned he decided to help. He ran to get scissors, and then walked back (because he had learned not to run with scissors…). He snipped the cocoon to make the hole bigger and the butterfly quickly emerged!

As the butterfly came out the boy was surprised. It had a swollen body and small, shriveled wings. He continued to watch the butterfly expecting that, at any moment, the wings would dry out, enlarge and expand to support the swollen body. He knew that in time the body would shrink and the butterfly’s wings would expand.

           But neither happened!

The butterfly spent the rest of its life crawling around with a swollen body and shriveled wings.

It never was able to fly…

As the boy tried to figure out what had gone wrong his mother took him to talk to a scientist from a local college. He learned that the butterfly was SUPPOSED to struggle. In fact, the butterfly’s struggle to push its way through the tiny opening of the cocoon pushes the fluid out of its body and into its wings. Without the struggle, the butterfly would never, ever fly. The boy’s good intentions hurt the butterfly.

As you go through school, and life, keep in mind that struggling is an important part of any growth experience. In fact, it is the struggle that causes you to develop your ability to fly.

As instructors our gift to you is stronger wings…   

Its my fault!!!

A man in a hot air balloon realized he was lost. He reduced altitude and spotted a man below. He descended a bit more and shouted, "Excuse me, can you help me? I promised a friend I would meet him half an hour ago, but I don't know where I am."

The man below replied, "You are in a hot air balloon hovering approximately 30 feet about the ground. You are between 42 and 44 degrees north latitude and between 83 and 85 degrees west longitude."

"You must be an engineer," said the balloonist.
"I am," replied the man, "but how did you know?"

"Well," answered the balloonist, "everything you told me is technically correct, but I have no idea what to make of your information, and the fact is I am still lost."

The man below responded, "You must be a manager."
"I am," replied the balloonist, "how did you know?"

"Well," said the man, "you don't know where you are or where you are going. You made a promise which you have no idea how to keep, and you expect me to solve your problem. The fact is you are exactly in the same position you were in before we met, but now, somehow, it's my fault."

Extract unicode words

import re
import codecs

charset = 'utf-8'
chrs = ''.join({unichr(x) for x in range(0x900, 0x980)}-{unichr(x) for x in range(0x964,0x970)})
other_chrs = ':,./<>?;"[]{}|-=_+!@#$%^&*()`~\'\\'

f = codecs.open(sys.argv[2], encoding='utf-8')

def get_words(line=None):
    retval = []
    for w in re.split(r'[%s]' % other_chrs, line, re.U):
        a = re.search(r'[%s]+' % (chrs), w, re.U)
        if a: 
            retval.append(a.group())
    return retval

for l in f:
    words = get_words(l)
    for w in words:
        print w.encode(charset)

Above code extracts words for devnagari (unichr(0x900) to unichr(0x97f)) charset. You can modify to extract data from other Indian scripts also or any other script.

Unicode charsets range can be found at http://www.unicode.org/charts/

PS: There are some improvements possible in the above code. Especially in regex section.

सरकारी अडचण

आमचा फाटक्यात अडकला पाय , या अण्णांचं करायचं काय?
यांना तुरुंगात घालायचं नाय, यांना बाहेर ठेवायचं नाय
यांना बोलू द्यायचं नाय, मग गप्प करायचं काय?
आमचा फाटक्यात अडकला पाय , या अण्णांचं करायचं काय? II१II

जमली अवघड प्रश्नांची साय, खाली उकळत दुध हाय
तोंड भाजून घ्यायचं का काय, जीभ दातात अडकली हाय
आमचा फाटक्यात अडकला पाय , या अण्णांचं करायचं काय? II२||

टी. व्ही. सारखाच वरडत हाय, कापडं अंगावर ठेवली न्हाय
माझा अडला ह्यो गाढव आता, हरीचे धरतोया पाय
आमचा फाटक्यात अडकला पाय , या अण्णांचं करायचं काय? II३II

उपवास यांना करायचा हाय, पाणी आमच्या तोंडचं जाय
अन्न गोड लागना माय, घास घशात अडकून रहाय
आमचा फाटक्यात अडकला पाय , या अण्णांचं करायचं काय? II४II

पब्लिक त्याच्याच माग माग जाय, त्याला अडवाव कसा नि काय ?
बाहेर जायला दारच न्हाय, पब्लिक हसून म्हणतंय बाय
आमचा फाटक्यात अडकला पाय , या अण्णांचं करायचं काय? II५II


SRC: e-mail forward

गब्बरचे चरित्र

भारतातील महान व्यक्तीपैकी एक म्हणजे गब्बर सिंग होय. पण चरित्रकरांनी त्यांच्यावर नेहमीच अन्याय केला आहे.
गब्बर यांचे प्रेरणादायी जीवन लोकांना कळावे म्हणून गब्बरचे हे चरित्र लिहिले आहे.

साधे जीवन व उच्च विचार : गब्बर सिंग खूपच साधे सरळ आयुष्य जगत होता. जुने आणि मळलेले कपडे, वाढलेली दाढी, तब्बल वर्ष वर्ष न घासलेले दात, आणि डोंगर दऱ्यातील भटके आयुष्य. जसेकाय मध्यकालीन भारतातला फकीरच. त्याने आपले जीवन आपल्या ध्येय्यासाठी समर्पित केले होते. त्यामुळे त्याला ऐशो आराम, विलासिक जीवन जगण्यासाठी वेळच नाही मिळाला. आणि विचारांच्या परिपक्वते बद्दल काय सांगावे, 'जो डर गया, सो मर गया' या सारख्या संवादांनी त्याने जीवनातल्या क्षणभंगुरतेवर प्रकाश टाकला आहे. गब्बरची दयाळू प्रवृत्ती : ठाकूरने गब्बरला आपल्या हातांनी पकडले होते. यामुळेच त्याने ठाकूरचे फक्त दोन हातच कापले. तो त्याचा गळा हि कापु शकला असता, पण त्याच्या ममतापूर्ण आणि करुणामय हृदयाने त्याला असे करू दिले नाही.
नृत्य आणि संगीताचा चाहता : 'मेहबूबा ओ मेहबूबा' यां गाण्याच्या वेळेस त्याच्या कलाकार हृदयाचा परिचय मिळतो. अन्य डाकुंसारखे त्याचे हृदय शुष्क नव्हते. तो जीवनात नृत्य-संगीत यां कलेंच महत्व जाणून होता. बसंतीला पकडल्या नंतर त्याच्यातला नृत्य प्रेमी खडबडून जागा झाला होता. त्याने बसंतीच्या आत दडलेल्या नर्तकीला ओळखल होत. तो कलेच्या प्रती आपले प्रेम अभिव्यक्त करण्याचे कोणतेही कारण सोडत नसे.

अनुशासन प्रिय गब्बर : जेव्हा कालिया आणि त्याचे मित्र आपल्यावर सोपविलेली कामगिरी पार न पडताच वापस आले होते, तेव्हा त्याने त्याकडे दुर्लक्ष केले नाही. आपल्या अनुशासन प्रिय स्वभावाला साजेस वर्तन त्याने केल. आणि त्या तिन्ही जणांना शासन केले.

हास्य प्रेमी : त्याच्याकडे कमालीचा 'सेन्स ऑफ ह्युमर' होता. कालिया आणि त्याचे दोन मित्र यांना मारण्याच्या पहिले त्याने त्यांना खूप हसविले होते. कारण हसता हसता या जगाचा त्यांनी निरोप घ्यावा असे त्याला मना पासून वाटत होते. तो आधुनिक युगातला 'लाफिंग बुध्द' होता.

नारीच्या प्रती सम्मान : बसंती सारख्या सुंदर मुलीला पकडल्या नंतर त्याने तिच्याकडे फक्त एका नृत्याची विनंती केली. आत्ताचा डाकू असता तर त्याने कदाचित वेगळंच काही तरी मागितल असत.
भिक्षुकी जीवन : त्याने हिंदू धर्म आणि महात्मा बुध्द यांनी दाखविलेला भिक्षुकी मार्ग स्वीकारला होता. रामपूर आणि इतर गावामधून त्याला जे काही मिळत त्यानेच तो आपले भगवत होता. सोने, चांदी, चिकन बिर्याणी, मलाई, पनीर टिक्का इ. भोगविलासी वस्तूंसाठी तो कधी शहराकडे नाही गेला.

सामाजिक कार्य : एकीकडे आपला डाकू पेशा संभाळत असताना तो लहान मुलांना झोपविण्याचे काम हि करत होता. शेकडो माता त्याचे नाव घेऊन आपल्या उनाड मुलांना झोपवत असत. सरकारने त्याच्यावर ५०,००० रुयांचे बक्षीस जाहीर केले होते. त्या काळात 'कोन बनेगा करोडपती' नसल्याने लोकांना रातोरात श्रीमंत बनविण्याचा गब्बरचा हा प्रामाणिक प्रयत्न होता.

231125_2045080768820_129841278

Source: email forward