Sunday, October 12, 2008

Qemu networking setup

          
------------ ----------
| | | 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

Monday, August 25, 2008

Configuring your ubuntu for faster internet access

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/

Friday, August 1, 2008

Youtube flash videos to DivX (on Linux)

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

Thursday, May 8, 2008

Using DOT language to produce Flowchart

much better than struggling with the graphical tools.


shon@ubuntu:~$ 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?"]
}

shon@ubuntu:~$ dot test.dot -Tpng -o test.png && eog test.png


Wednesday, April 16, 2008

Contract verification in Python



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)

Getting older, getting better and better!

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.

Anyways Python rocks!

SQLAlchemy elixir: Simple example

DB Setup
[root@localhost ~]# yum -y install postgresql-python \
postgresql postgresql-server
[root@localhost ~]# /etc/init.d/postgresql start
[root@localhost ~]# /etc/init.d/postgresql status
[root@localhost ~]# su - postgres -c "createuser --createdb \
--adduser shon"
[root@localhost ~]# su - shon # normal user
[shon@localhost ]$ createdb test
[shon@localhost ]$ psql test
test=# \q


Code test_alchemy.py


from elixir import *

metadata.connect("postgres:///test")

class Movie(Entity):
has_field('title', Unicode(30))
has_field('year', Integer)
has_field('description', Unicode)

def __repr__(self): return '
' % (self.title, self.year)

metadata.create_all()

def test1():
m1 = Movie(title="Blade Runner", year=1982)
m2 = Movie(title="Life is beautiful", year=1980)
objectstore.flush()
print m1

def test2():
print Movie.select()[0]

test1()
# test2()