ipynb2viewer - Afternoon hack

ipython nbconvert has lot of handy options to convert ipynb to markdown, html etc… But I wanted to upload ipynb to gist.github.com and create a link in nbviewer.ipython.org. Started with curl and soon realized, it is getting messy. So wrote a small python program ipynb2viewer, Source code. Install pip install ipynb2viewer Usage Upload all ipynb files in the given path to gist.github.com and return nbviewer urls. ipynb2viewer all <path> Upload mentioned file to gist. [Read More]

easy_install broken in os x mavericks

I hardly use easy_install. Nowadays all the python requirements are installed via pip. IPython is my primary python console. After installing mavericks, I installed IPython and fired IPython console. Following warning message appeared ➜ ~ ipython /Library/Python/2.7/site-packages/IPython/utils/rlineimpl.py:94: RuntimeWarning: ****************************************************************************** libedit detected - readline will not be well behaved, including but not limited to: * crashes on tab completion * incorrect history navigation * corrupting long-lines * failure to wrap or indent lines properly It is highly recommended that you install readline, which is easy_installable: easy_install readline Note that `pip install readline` generally DOES NOT WORK, because it installs to site-packages, which come *after* lib-dynload in sys. [Read More]

Check Tamil word or sentence is palindrome

How to check given text is palindrome or not def sanitize(text): for char in [" ", ".", ",", ";", "\n"]: text = text.replace(char, "") return text def palindrome(word): # This approach is o(n), problem can be solved with o(n/2) # I am using this approach for brevity return word == word[::-1] palindrome(sanitize("madam")) # True palindrome(sanitize(u"விகடகவி")) # False Here is the hand made version for Tamil # Assign the variable meal the value 44. [Read More]

How Tamil Unicode works

Tamil has 247 characters. No panic. It is simple. 12 uyir eluthu(அ,ஆ..ஔ), 18 mei eluthu(க்,ங்..) , 216 uyirmei eluthu(12 * 18 க,ங ).1 ayutham(ஃ). I assume you know what is unicode. If not read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets and then read wikipedia page. You will understand most of it. Back to the post. Every character or letter in unicode has value called code point. [Read More]

coverage.py to test web application coverage without writing tests

Tests are mandatory for packages, modules, web apps. If you are lazy to write unit tests but wanted to see the coverage for web app here is the short cut. Lets consider a Python web app uses Flask, runserver.py runs the development web server. Normally server is started by the command python runserver.py. Now use coverage run runserver.py. coverage python package will run the python program til program exits or user halts. [Read More]

Observations from handling python workshop in engineering colleges

Observations from handling python workshop in engineering colleges I handled 5 python workshop/sessions for novices from 8th march to 20th august, each one stretching from 1 hour to 2 days. It was worth the time. Students who participated in the workshop where from Computer Science, Electronics background of Under Graduate and Post Graduate level. Minimum strength was 60 and maximum was close to 100. When handling the strength of 60 students in lab, remember every one have their own pace of picking up. [Read More]

avoid accessing wrong column in csv

Avoid accessing wrong column in csv I was parsing few csv files. All were from same provider. Format isDate, Name, Email, Company, City etc in one file. I made an assumption all the downloaded files are in the same format. For my surprise few files had same format and others din’t. with open(filename, 'rb') as f: reader = csv.reader(f) reader.next() # first row contains column names for row in reader: name, email, company = row[1], row[2], row[3] #save to db In the above code the fundamental mistake is fixing the position of the columns in csv file. [Read More]
csv  python  tip 

Funny experience of using trace module to trace function call

I came across this issue in httpie and started my investigation. The problem is while pretty printing the json, output is alpha sorted because keys are hashed and user wanted to preserve the order. Then I made 3 comments to the issue. First comment was half correct and explained why it isn’t possible to get the desired output, quickly I figured my assumptions were wrong and second comment explained what is actually happening, finally I proposed the solution. [Read More]

Why This Kolaveri Di song words language

I was wondering how many words in why this kolaveri di song belongs to english. So I wrote this code to evaluate. #! /usr/bin/env #! -*- coding: utf-8 -*- lyrics = """ yo boys i am singing song soup song flop song why this kolaveri kolaveri kolaveri di why this kolaveri kolaveri kolaveri di rhythm correct why this kolaveri kolaveri kolaveri di maintain please why this kolaveri di distance la moon-u moon-u moon-u color-u white-u white background night-u night-u night-u color-u black-u why this kolaveri kolaveri kolaveri di why this kolaveri kolaveri kolaveri di white skin-u girl-u girl-u girl-u heart-u black-u eyes-u eyes-u meet-u meet-u my future dark why this kolaveri kolaveri kolaveri di why this kolaveri kolaveri kolaveri di maama notes eduthuko apdiye kaila snacks eduthuko pa pa paan pa pa paan pa pa paa pa pa paan sariya vaasi super maama ready ready 1 2 3 4 whaa wat a change over maama ok maama now tune change-u kaila glass only english hand la glass glass la scotch eyes-u full-a tear-u empty life-u girl-u come-u life reverse gear-u love-u love-u oh my love-u you showed me bouv-u cow-u cow-u holy cow-u i want you hear now-u god i am dying now-u she is happy how-u this song for soup boys-u we dont have choice-u why this kolaveri kolaveri kolaveri di why this kolaveri kolaveri kolaveri di why this kolaveri kolaveri kolaveri di why this kolaveri kolaveri kolaveri di flop song """ dict_file_path = "/usr/share/dict/words" def sanitize(words): for index, word in enumerate(words): if word. [Read More]

SSL for flask local development

Recently at HasGeek we moved all our web application to https. So I wanted to have all my development environment urls to have https. How to have https in flask app Method 1 from flask import Flask app = Flask(__name__) app.run('0.0.0.0', debug=True, port=8100, ssl_context='adhoc') In the above piece of code, ssl_context variable is passed to werkezug.run_simple which creates SSL certificates using OpenSSL, you may need to install pyopenssl. I had issues with this method, so I generated self signed certificate. [Read More]
python  ssl  https  flask