Posts

Showing posts from February, 2011

[Level 3] Python Encapsulation.

There are two ways to implement property encapsulation. [test1.py] #!/bin/env python class C(object): #class C():     y = 3     z = 4     def __init__(self):         self.__x = 2         self.z = 0         self._z = 00         self.__z = 000     def getx(self):         return self.__x     def setx(self, val):         print "x is read only"     x = property(getx, setx) #    x = property(getx) #    x = property(lambda self: self.__x) c=C() print(c.x,c.y,c.z) c.x=3 print(c.x,c.y,c.z) print c.z print c._z print c.__z #AttributeError [test2.py] #!/bin/env python #!/bin/env python class B(object):    def __init__(self):        self.__x = None    @property    def x(self):        """I'm the 'x' property."""        return self.__x    @x.setter    def x(self, value):        self.__x = value    @x.deleter    def x(self):        del self.__x b=B() b.x=12 print(b.x) print(b.__x) #AttributeError

[Level 3] Python Abstract Class Implement

If you want to implement python abstract class, you could use astract base class of python. The sample code as the following: [common.py] #!/bin/env python from abc import * __all__ = ['CommonClass'] class CommonClass:     __metaclass__ = ABCMeta     def __init__(self, name, age):         self.name = name         self.age = age     def displayAge(self):         print 'My age is: %s' % self.age     @abstractmethod     def displayName(self):        pass [myABC.py] #!/bin/env python from common import * class MyClass(CommonClass):     def __init__(self, name, age):         CommonClass.__init__(self, name, age)         def displayName(self):         print "Hi %s!" % self.name if __name__ == "__main__":     st = MyClass('Stanley', 25)     st.displayAge()     st.displayName() execute myABC.py # ./myABC.py My age is: 25 Hi Stanley! # According to above sample, if you want to define abstract class, you have three things t

[Level 2] DNS Round Robin.

If you want to setup DNS round robin, just add the record like below into your database. ; dns round robin rr      IN      A       192.168.0.101 rr      IN      A       192.168.0.102 rr      IN      A       192.168.0.103 Wish this helps. regards, Stanley Huang

[Level 2] DNS setup on Ubuntu.

If you want to instal DNS on Ubuntu, the steps of DNS setup as the following: 1. install bind9 # apt-get -y install bind9 2. setup named.conf.local # cat /etc/bind/named.conf.local // // Do any local configuration here // // Consider adding the 1918 zones here, if they are not used in your // organization //include "/etc/bind/zones.rfc1918"; # This is the zone definition. replace example.com with your domain name zone "example.com" {         type master;         file "/etc/bind/zones/example.com.db";         }; # This is the zone definition for reverse DNS. replace 0.168.192 with your network address in reverse notation - e.g my network address is 192.168.0 zone "0.168.192.in-addr.arpa" {      type master;      file "/etc/bind/zones/rev.0.168.192.in-addr.arpa"; }; 3. setup named.conf.options # cat /etc/bind/named.conf.options options {     directory "/var/cache/bind";     // If there is a firew

[Level 3] How to get option 43 from dchp server.

You can following the steps to implement get option 43 from dhcp server. [server side] 1. install dhcp  server: # apt-get install dhcp3-server 2. modify /etc/default/dhcp3-server: (modify) INTERFACES="eth0" 3. modify /etc/dhcp3/dhcpd.conf: (add) option space VendorInfo; option VendorInfo.text code 10 = { text }; subnet 192.168.2.0 netmask 255.255.255.0 {   range 192.168.2.2 192.168.2.9;   filename "pxelinux.0";   option subnet-mask 255.255.255.0;   option broadcast-address 192.168.2.255;   vendor-option-space VendorInfo;   option VendorInfo.text "option43 text"; } 4. restart server: # /etc/init.d/dhcp3-server restart [client side] 1. modify /etc/dhcp3/dhclient.conf: (add) option space VendorInfo; option VendorInfo.text code 10 = { text }; (modify) request subnet-mask, broadcast-address, time-offset, routers,         domain-name, domain-name-servers, domain-search, host-name,         netbios-name-servers, netbios-scope, i

[Level2] Pass parameters to make.

$ cat Makefile all: ifdef aa         echo "defined" ifeq "${aa}" "123"         echo "true" else         echo "false" endif else         echo "not defined" endif $ $ make echo "not defined" not defined $ $ make aa="000" echo "defined" defined echo "false" false $ $ make aa="123" echo "defined" defined echo "true" true $ Wish this helps.  regards, Stanley Huang

[Level2] authorized key for ssh.

If you want to pre-authorized key for ssh loging (without password prompt), please try the following steps: 1. Create key stanley@s1$ echo "y" > /tmp/y stanley@s1$ ssh-keygen -f ~/.ssh/id_rsa -N"" < /tmp/y 2. Verify public key stanley@s1$ ssh-keygen -f ~/.ssh/id_rsa -y  3. Copy public key to remote server stanley@s1$ ssh stanley@s2 echo `cat .ssh/id_rsa.pub` \>\> ~stanley/.ssh/authorized_keys or stanley@s1$ ssh-copy-id -i ~stanley/.ssh/id_rsa.pub stanley@s2 4. Test stanley@s1$ ssh stanley@s2 The authenticity of host 's1 (192.168.1.1)' can't be established. RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx. Are you sure you want to continue connecting (yes/no)? yes stanley@s2$ exit stanley@s1$ ssh stanley@s2 stanley@s2$ Wish this helps. regards, Stanley Huang