Software Developer with over seven years of extensive application development/design experience mainly in Pyhon on Unix platform.
Design and develop open source solutions for The Hub.
Development of scalable Notification component for their new product.
One of the BladeLogic products helps datacenter admins to update OS for patches released by OS vendors. I contributed by automating update process for RPM/Yum based Linux distributions.
Ensim is leading provider for web hosting applications. Ensim Pro for Linux (also know as Linux Webppliance) was the flagship product for shared hosting management.
Write scripts to automate routine server administration tasks. Monitor server health, plan and contribute to server farm management.
JSON-RPC protocol has got much less attention than it deserves. It is so elegant and simple. Our experience of working on JSON-RPC was plesant.
For uninitiated JSON-RPC is lightweight remote procedure call protocol similar to XML-RPC. I find it incredibly useful in building easy to maintain applications.
We effectively used JSONRPC in our project Cowoop to make it easy to debug application.
It is often seen that unless it is an open source application, in the design phase very little attention is paid towards maintainablity of the application. With many no so clearly seperated layers it makes it increasingly difficult to debug. This makes bug fixing painful and no fun process for those who are working on it. And further these in most cases are not the architects who designed the application. Architect is either moved on to design some other project or is working on next release.
Lets directly jump to example code. So here is my python function.
>>> def add(a, b):
return a + b
>>> add(1, 2)
3
Project exposes above function add using JSON-RPC. We use Flask + jsonrpc2 to serve JSONRPC over http.
Let us see how does jquery JSONRPC plugin calls this API.
Result
jsonrpc function that you see in above screenshot is part of our js client library. Really it is a a few lines wrapper on top of jquery jsonrpc plugin function jsonRPC.request()
Do you think JSONRPC2 is fairly successful in helping create a maintainable application?
There is no word in JSONRPC2 specification about Authentication yet (not a complaint) . But I think it is necessary for further success of JSONRPC. It’s possible to use http auth but not many would prefer it so I see people implementing two type of solutions.
Session id is kept in authcookie and sent/validated with every http request.
Session id is passed as special parameter in every rpc call. For eg. above add function may be invoked like below
add(1, 2, _session='somesessionid')
--> { "method": "login", "params": {"username": "me", "password": "secret"}, "id": 1}
<-- { "result": "somesessionid", "error": null, "id": 1}
--> { "method": "echo", "params": ["Hello protected JSON-RPC"], "id": 1, "session": "somesessionid"}
<-- { "result": "Hello protected JSON-RPC", "error": null, "id": 1}
In the initial phase of this open source project cowspa developed by Cowoop, we had chosen knockout.js as important client side component. However during the implementation team bowed to the delivery pressure and couldn’t get a chance to learn, explore and use knockout or any other MVC library. Certainly a mistake! Ultimately we have to paid the price of having to maintain really complex pure jquery based bug-prone codebase. However at this stage, I decided to rectify this and started looking for different client side templating and MVC libraries. Essentially the library that binds the templates to data and can auto-update as the data changes. I was stunned by choice of libraries/frameworks available. There are just too many of them. Ones I liked are
Ember is perhaps the best one even according to this post. Angular is very capable and is sheer magic. And well there are many more like excellent backbone.js. We finally narrowed down two options: Knockout and Agility. Agility, I liked most, mainly because of it’s clear syntax and looked like producing very maintainable code. So it was really tempting to go for it. But for us at this point of time knockout scored better at mainly with it’s project maturity (age). Agility is at 0.1.2 at this moment and knockout 2.0.0 and hence knockout enjoys much bigger community.
So while we go ahead now with knockout I will certainly keep an eye on agility’s development would love to find an excuse to use it.
While there is a lot already written here my quick howto
$ sudo bash
# apt-get install dnsmasq squid
# echo "listen-address=127.0.0.1" >> /etc/dnsmasq.conf
# echo "no-dhcp-interface=" >> /etc/dnsmasq.conf
# vi /etc/dhcp3/dhclient.conf
# # ^ uncomment line #prepend domain-name-servers 127.0.0.1;
# vi /etc/resolv.conf # Add nameserver 127.0.0.1
# /etc/init.d/dnsmasq restart
# vi /etc/squid/squid.conf
http_port 3128
visible_hostname localhost
acl all src 0.0.0.0/0.0.0.0
cache_effective_user proxy
cache_effective_group proxy
http_access allow all
icp_access allow all
positive_dns_ttl 1 month
negative_dns_ttl 1 minute
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
cache_dir ufs /cache 400 16 256
cache_store_log none
# mkdir /cache # I have this dir on reizerfs partition
# chown proxy.proxy /cache
# /etc/init.d/squid restart
Configure your browser to use 127.0.0.1:8080. Also read detailed dnsmasq setup article http://ubuntu.wordpress.com/2006/08/02/local-dns-cache-for-faster-browsing/
You want to implement search against user objects stored in redis using Python. Something like querying for all user ids whose username begins with “an”.
Here we have user objects stored in as hashes with “user:obj:” as prefix.
For example
user:obj:3955 {id: 3955, username: 'John', ..}
We need some extra data structures to support our search i.e. (search user objects where username begins with given phrase. So search for jo should match John, Joe and so on. We will use sorted sets of all usernames and will assign every element a score. This score is a float and helps us in finding the matching words.
Some scores for eg.
a -> 0.097ab -> 0.097098ac -> 0.097099bc -> 0.098099
So for above four string if we find strings that has score that is => 0.097 and < 0.098, we find all strings that begins with ‘a’
Code
# Search usernames that begins with given phrase
#
# usernames: (username1, username2, ..)
# userscore:<username>: float
# user:obj: { id: int, username: string }
usernames_zset = "usernames"
def my_ord(c):
return "%03d" % ord(c)
def get_score(s):
return '0.' + ''.join(map(str, map(my_ord,s)))
def get_next_score(s):
s_score = get_score(s)
part0 = s_score[:4]
c = s_score[4]
next_c = str(int(c)+1)
part1 = s_score[5:]
return part0 + next_c + part1
def add_user(conn, username, score):
# The User Object
uid = conn.incr('user:idgen')
conn.hset('user:obj:%d' % uid, 'id', username)
# datastructures necessary to implement search
conn.zadd(usernames_zset, username, score)
def add_test_data(conn):
test_data = ('abc', 'ab', 'a', 'shekhar', 'shon', 'sh', \
'zxcvbnmasdfghjklqwertyuiop0', 'zxcvbnmasdfghjklqwertyuiop00')
for username in test_data:
score = get_score(username)
add_user(conn, username, score)
import redis
conn = redis.Redis()
add_test_data(conn)
# conn.zrange(usernames_zset, 0, -1) # Whole set
a_score = get_score('a')
b_score = get_next_score('a')
print 'Find all users starting with "a" -> INF'
print conn.zrangebyscore(usernames_zset, a_score, 'INF')
print 'Find all users starting with "a"'
print conn.zrangebyscore(usernames_zset, a_score, b_score)
print 'Find all users starting with "a" limit 2'
print conn.zrangebyscore(usernames_zset, a_score, 'INF', 0, 2)
Surely one of the most over-hyped film. What was good? Aamir, Music and the first half laughs. Post interval it becomes a predictable, boring, idiot bollywood movie.
Munnabhai s were certainly better. I would say watch it on TV or atleast don’t pay 3 times higher than usual for tickets like we did. 4 and half stars by critic hmmmm..
sudo apt-get install usb-modeswitch wvdial vi /etc/wvdial [Dialer Defaults] Phone = #777 Password = Username = Baud = 460800 Stupid Mode = 1 New PPPD = 1 Tonline = 0 Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 Modem Type = Analog Modem Baud = 460800 Modem = /dev/ttyUSB0 ISDN = 0
I do like Ubuntu Netbook Remix’s UI. However with 10.04 it’s just gone so unstable for me.
Considering all that I decided to switch to Xfce. It just worked like charm. But now I also use (and like :) ) UbuntuOne service for my backup. UbuntuOne is not integrated for XFCE. Also you cant do everything from UbuntuOne’s cli.
u1sdtool -q; killall ubuntuone-login; u1sdtool -c # configuration u1sdtool --create-folder ~/my_data # add folders you want to be synced u1sdtool --list-folders u1sdtool --current-transfers
For more details you might want to check Ubuntu One wiki .
Pulling your hairs over some i18n bug or you fix it but are not able to explain what. This is little help in getting fair idea about unicode/codecs/encoding/decoding etc.
Quick tips:
Now
Must Read
Continue reading
This how I convert flash I usually use Firefox VideoHelper Addon to download youtube videos. To play them on my Philips DVP5986K DVD player from USB drive, I need to convert it to DivX.
mencoder /home/shon/Desktop/file-864260998.flv -ovc lavc -oac mp3lame -ffourcc DX50 -o out.avi
Linkedin is one of the few sites that has certainly impressed me with it’s clever design. I would rate it very highly for professional networking. It has one very popular feature “recommendations”. Well while I am not against recommending or get recommended by, as I have done both in past. But I see people who think that more and more people they have in their list (no matter how they know well each other professionally) and more recommendations they have received (mostly by requesting others) would make their prospects better. Umm oh, I wonder why are they are madly behind this. I receive a quite a few requests often. Some morning you check your emails and you see that some colleague in your company 2 years ago sends you a mail with subject “can you endorse me?”. And the email says something similar.
Dear ,
I’m sending this to ask you for a brief recommendation of my work that I can include in my LinkedIn profile. If you have any questions, let me know.
Thanks in advance for helping me out. -
Now this above guy could be someone I don’t know that well how well he/she is skilled. But now I can’t deny the request so in a day or two I would look at some other recommendations available for my other LinkedIn friends, copy some matter and send what is requested for. He happily accepts and send me a nice Thank you email. I see people who worked completely unrelated departments and has probably no ability to judge other’s work, go praising out of good relationships. May be what should happen on Orkut testimonials or somewhere similar. Does these people who have tens and hundreds of people in network and so many recommendations have no work other than hopping the jobs and sending such requests.
Next time I interview a guy with many endorsements , I would probably more cautious hiring him.
cat /etc/wvdial.conf:
[Dialer Defaults] Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 Modem Type = USB Modem Baud = 460800 New PPPD = yes Modem = /dev/ttyACM0 ISDN = 0 Stupid mode = 1 Phone = #777 Password = internet Username = internet
Don’t understand above. Um ok but I am too lazy to explain.
------------ ---------- | | | Guest | | Host ----+------+----- | | | | Hub | | | | |tap0| |tap1 | | | |-----+-----+-----| | | eth0 | | | | | | | | ----+------- ---------- | (Internet) Host * Add a hub # vde_switch -x -d -tap tap0 -tap tap1 * Assign ip to host's nic # ifconfig tap0 192.168.1.1 * Setup ip forwarding Modify /etc/sysctl.conf net.ipv4.ip_forward=1 * Setup masquerading # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE * Fire qemu # vdeqemu -m 1024 -localtime /vm//jos_8.04_01/jos_8.04_01.img Guest # ifconfig eth0 192.168.1.2 # route add default gw 192.168.1.1 # vi /etc/resolv.com # ping google.com
better than struggling with the graphical tools.
$ cat test.dot
digraph FlowChart {
node [
fontname = "Bitstream Vera Sans"
fontsize = 8
shape = "record"
]
edge [
fontname = "Bitstream Vera Sans"
fontsize = 8
fontcolor = "Red"
]
// all blocks
greet [label="Hello, techie", shape="oval"]
which_os [label="What OS do you use?" shape="diamond"]
like_me [label="Great, me too!", shape="oval"]
which_browser [label="You must be using firefox", shape="diamond"]
ff [label="Cool", shape="oval"]
bye [label="Bye", shape="oval"]
// relations
greet -> which_os
which_os -> like_me [label="I use Linux"]
which_os -> which_browser [label="I use Windows"]
which_browser -> ff [label="Right"]
which_browser -> bye [label="what firefox?"]
}
$ dot test.dot -Tpng -o test.png && eog test.png
import zope.interface.verify
class ITest(zope.interface.Interface):
def foo(arg1): pass
def bar(): pass
class Test(object):
zope.interface.implements(ITest)
def foo(self): pass
class Test2(object):
zope.interface.implements(ITest)
def foo(self, arg1): pass
class Test3(object):
zope.interface.implements(ITest)
def foo(self, arg1): pass
def bar(self): pass
for cls in (Test, Test2, Test3):
try:
if zope.interface.verify.verifyClass(ITest, cls):
print "OK: %s correctly implements %s" % (cls.__name__, ITest.__name__)
except Exception, err:
print "Error detected with %s's implementation: %s" % (cls.__name__, err)
Python programming is joy. I was stuck on python 2.3 at my work for long and could not really get chance to explore later versions. Now that I got the opportunity doing re-architecture of the product I started exploring these. I am more than excited looking at deque, groupby, defaultdict and much more … Also on top of it there exist excellent python softwares like twisted, sqlalchemy, turbogears makes it even more cool.
It’s little pity that the language is stll somewhat less recognized than others. Or there are more hyped languages exist.