Tuesday, May 14, 2019
Sunday, May 12, 2019
Be pythonic
The Zen of Python
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
See https://legacy.python.org/dev/peps/pep-0020/
Python Code Style
https://docs.python-guide.org/writing/style/
Pytonic
"Pythonic" means something like "idiomatic Python"
The sense of how to use Python the right way.
The idiom the Python language encourages.
To be Pythonic is to use the Python constructs and datastructures with clean, readable idioms.
Exploiting the features of the Python language to produce code that is clear, concise and maintainable.
https://blog.startifact.com/posts/older/what-is-pythonic.html
Wednesday, January 22, 2014
piVC Serversetup
piVC is a logic verfication program by Stanford University. To serve the class CS458, it requires a piVC server set up for students to use Java piVC client.
To provide better portability, the piVC server is set up in a Virtual Machine (VM) on KVM virtualization.
VM name: piVC
VM credentials: GDC convention
VM ip: 128.153.145.236
Below are the instructions on HOWTO install piVC server:
1. check out the piVC source code:
https://github.com/jgalenson/piVC
1) install svn
sudo apt-get install subversion
2) checkout source code
svn checkout svn://www.jasonland.com/piVC
3) download yices
http://yices.csl.sri.com/download.shtml
cp yices-1.0.40/bin/yices ../../piVC/bin
4) install build tool
sudo apt-get install build-essential
sudo apt-get install ocaml
5) install java for the client
sudo apt-get install openjdk-7-jdk
6)compile the source code
cd piVC/src
make
7) Configure the server
check the machine ip: ifconfig
specify the local machine static ip in piVC/conf/piVC_server.conf
dp_server_address = xxx.xxx.xxx.xxx:4243
8) Run the service
cd piVC/bin
./both_servers
9) Config the piVC client
Download the client from here
http://cs.stanford.edu/people/jasonaue/pivc/
Run the client by
java -jar PiVC.jar
Change the server address
Settings->Change Server Address -> xxx.xxx.xxx.xxx:4242
Run the program
Compile
To provide better portability, the piVC server is set up in a Virtual Machine (VM) on KVM virtualization.
VM name: piVC
VM credentials: GDC convention
VM ip: 128.153.145.236
Below are the instructions on HOWTO install piVC server:
1. check out the piVC source code:
https://github.com/jgalenson/piVC
1) install svn
sudo apt-get install subversion
2) checkout source code
svn checkout svn://www.jasonland.com/piVC
3) download yices
http://yices.csl.sri.com/download.shtml
cp yices-1.0.40/bin/yices ../../piVC/bin
4) install build tool
sudo apt-get install build-essential
sudo apt-get install ocaml
5) install java for the client
sudo apt-get install openjdk-7-jdk
6)compile the source code
cd piVC/src
make
7) Configure the server
check the machine ip: ifconfig
specify the local machine static ip in piVC/conf/piVC_server.conf
dp_server_address = xxx.xxx.xxx.xxx:4243
cd piVC/bin
./both_servers
9) Config the piVC client
Download the client from here
http://cs.stanford.edu/people/jasonaue/pivc/
Run the client by
java -jar PiVC.jar
Change the server address
Settings->Change Server Address -> xxx.xxx.xxx.xxx:4242
Run the program
Compile
Sunday, August 2, 2009
Samba Server on Centos HOWTO
TDB database
root: > smbd -b | grep PRIVATE_DIR
/etc/samba
root: >smbd -b | grep LOCKDIR
/var/cache/samba
use tdbbackup utility to backup those tdb files
mkdir a directory and change its ownship
chown account.group /path/to/directory
Samba Configruation File
root: >smbd -b | grep smb.conf
/etc/samba/smb.conf
Dry run Samba Configurations
root: >testparm /etc/samba/smb.conf
root: >smbclient -L xxx.xxx.xxx.xxx(SambaServerIP) -U%
Samba valid user setup
root: >smbpasswd -a csguest
New SMB password:
Retype new SMB password:
startsmbfilepwent_internal: file /etc/samba/smbpasswd did not exist. File successfully created.
Added user csguest.
chown user.group /path/to/sambashare
Run/start/stop/restart Samba Server
root: >service smb reload
root: >service smb start
root: >service smb stop
root: >service smb condrestart
Mount Samba Share in Linux
root: >apt-get install smbfs
root: >smbmount //SambaServerIP/SambaShare /mnt/Dir -o username=account, password=pwd
Access Samba Share in WindowsXP
Control Panel -> User Accounts -> yourUserAccount
Click Manage my network passwords
Add button to enter Server, User name and Password
Server: xxx.xxx.xxx.xxx(SambaServerIP)
Username: xxx.xxx.xxx.xxx\AccountName
Password:******
My Computer -> Tools -> Map Network Drive
Folder: //SambaServerIP/SambaShare
root: > smbd -b | grep PRIVATE_DIR
/etc/samba
root: >smbd -b | grep LOCKDIR
/var/cache/samba
use tdbbackup utility to backup those tdb files
mkdir a directory and change its ownship
chown account.group /path/to/directory
Samba Configruation File
root: >smbd -b | grep smb.conf
/etc/samba/smb.conf
Dry run Samba Configurations
root: >testparm /etc/samba/smb.conf
root: >smbclient -L xxx.xxx.xxx.xxx(SambaServerIP) -U%
Samba valid user setup
root: >smbpasswd -a csguest
New SMB password:
Retype new SMB password:
startsmbfilepwent_internal: file /etc/samba/smbpasswd did not exist. File successfully created.
Added user csguest.
chown user.group /path/to/sambashare
Run/start/stop/restart Samba Server
root: >service smb reload
root: >service smb start
root: >service smb stop
root: >service smb condrestart
Mount Samba Share in Linux
root: >apt-get install smbfs
root: >smbmount //SambaServerIP/SambaShare /mnt/Dir -o username=account, password=pwd
Access Samba Share in WindowsXP
Control Panel -> User Accounts -> yourUserAccount
Click Manage my network passwords
Add button to enter Server, User name and Password
Server: xxx.xxx.xxx.xxx(SambaServerIP)
Username: xxx.xxx.xxx.xxx\AccountName
Password:******
My Computer -> Tools -> Map Network Drive
Folder: //SambaServerIP/SambaShare
Friday, May 1, 2009
Centos: nilfs compiling from src
Download source:
2.6.18 centos kernel source code (kernel-devel-2.6.18-128.el5.centos.plus.i686.rpm)
http://rpm.pbone.net/index.php3/stat/4/idpl/12390365/com/kernel-devel-2.6.18-128.el5.centos.plus.i686.rpm.html
kernel module source code
http://www.nilfs.org/download/nilfs-2.0.12.tar.bz2
patch for Centos
http://www.nilfs.org/pub/centos/5/SRPMS/nilfs-kmod-2.0.12-r.src.rpm
userland utilities source code
http://www.nilfs.org/download/nilfs-utils-2.0.12.tar.bz2
Required packages:
gcc
yum install gcc
e2fsprogs-devel
yum install e2fsprogs-devel
default installed: make binutils
Installation Instructions:
I. use Centos rpm installer to unpackage the kernel source code
The source code will be in the directory :
/usr/src/kernels/2.6.18-128.1.6.el5-i686
2. untar the nilfs kernel module source code and userland utilities source code
kernel module is in the directory: nilfs-2.0.12
utilities is in the directory: nilfs-utils-2.0.12
3. uncompress the nilfs-kmod-2.0.12-r.src.rpm package and copy the patch file nilfs-rhel5-kern-feature.patch to the kernel module src directory nilfs-2.0.12
_______________________________________________________
--- a/fs/kern_feature.h 2008-02-12 08:38:22.000000000 -0000
+++ b/fs/kern_feature.h 2009-04-09 12:27:24.000000000 -0000
@@ -30,6 +30,25 @@
/*
* Please define as 0/1 here if you want to override
*/
+/* for Red Hat Enterprise Linux / CentOS 5.x */
+#if defined(RHEL_MAJOR) && (RHEL_MAJOR == 5)
+# define NEED_MOUNT_SEMAPHORE 1
+# define NEED_INODE_GENERIC_IP 0
+# define NEED_INODE_BLKSIZE 0
+# define HAVE_PAGE_MKWRITE 1
+# if (RHEL_MINOR < 1)
+# define PageChecked PageFsMisc
+# define SetPageChecked SetPageFsMisc
+# define ClearPageChecked ClearPageFsMisc
+# endif
+# if (RHEL_MINOR > 0)
+# define NEED_INC_NLINK 0
+# if (RHEL_MINOR > 2)
+# define NEED_DROP_NLINK 0
+# define HAVE_LE32_64_ADD_CPU 1
+# endif
+# endif
+#endif
/*
* defaults dependent to kernel versions
_______________________________________________________
4. apply the patch to the kernel module source code
root: ~> patch -p1 < nilfs-rehel-kern-feature.patch
5. compile the kernel module source code root: ~> make
root: ~> make install
6. compile the utils source code
root: ~> make
root: ~> make install
Userful resource:
http://www.nilfs.org/download/READMEv2
http://www.cyberciti.biz/faq/appy-patch-file-using-patch-command/
http://rpm.pbone.net/index.php3/stat/4/idpl/12390365/com/kernel-devel-2.6.18-128.el5.centos.plus.i686.rpm.html
http://www.nilfs.org/en/faq.html
http://www.nilfs.org/en/pkg_centos.html
2.6.18 centos kernel source code (kernel-devel-2.6.18-128.el5.centos.plus.i686.rpm)
http://rpm.pbone.net/index.php3/stat/4/idpl/12390365/com/kernel-devel-2.6.18-128.el5.centos.plus.i686.rpm.html
kernel module source code
http://www.nilfs.org/download/nilfs-2.0.12.tar.bz2
patch for Centos
http://www.nilfs.org/pub/centos/5/SRPMS/nilfs-kmod-2.0.12-r.src.rpm
userland utilities source code
http://www.nilfs.org/download/nilfs-utils-2.0.12.tar.bz2
Required packages:
gcc
yum install gcc
e2fsprogs-devel
yum install e2fsprogs-devel
default installed: make binutils
Installation Instructions:
I. use Centos rpm installer to unpackage the kernel source code
The source code will be in the directory :
/usr/src/kernels/2.6.18-128.1.6.el5-i686
2. untar the nilfs kernel module source code and userland utilities source code
kernel module is in the directory: nilfs-2.0.12
utilities is in the directory: nilfs-utils-2.0.12
3. uncompress the nilfs-kmod-2.0.12-r.src.rpm package and copy the patch file nilfs-rhel5-kern-feature.patch to the kernel module src directory nilfs-2.0.12
_______________________________________________________
--- a/fs/kern_feature.h 2008-02-12 08:38:22.000000000 -0000
+++ b/fs/kern_feature.h 2009-04-09 12:27:24.000000000 -0000
@@ -30,6 +30,25 @@
/*
* Please define as 0/1 here if you want to override
*/
+/* for Red Hat Enterprise Linux / CentOS 5.x */
+#if defined(RHEL_MAJOR) && (RHEL_MAJOR == 5)
+# define NEED_MOUNT_SEMAPHORE 1
+# define NEED_INODE_GENERIC_IP 0
+# define NEED_INODE_BLKSIZE 0
+# define HAVE_PAGE_MKWRITE 1
+# if (RHEL_MINOR < 1)
+# define PageChecked PageFsMisc
+# define SetPageChecked SetPageFsMisc
+# define ClearPageChecked ClearPageFsMisc
+# endif
+# if (RHEL_MINOR > 0)
+# define NEED_INC_NLINK 0
+# if (RHEL_MINOR > 2)
+# define NEED_DROP_NLINK 0
+# define HAVE_LE32_64_ADD_CPU 1
+# endif
+# endif
+#endif
/*
* defaults dependent to kernel versions
_______________________________________________________
4. apply the patch to the kernel module source code
root: ~> patch -p1 < nilfs-rehel-kern-feature.patch
5. compile the kernel module source code root: ~> make
root: ~> make install
6. compile the utils source code
root: ~> make
root: ~> make install
Userful resource:
http://www.nilfs.org/download/READMEv2
http://www.cyberciti.biz/faq/appy-patch-file-using-patch-command/
http://rpm.pbone.net/index.php3/stat/4/idpl/12390365/com/kernel-devel-2.6.18-128.el5.centos.plus.i686.rpm.html
http://www.nilfs.org/en/faq.html
http://www.nilfs.org/en/pkg_centos.html
Tuesday, April 21, 2009
NilFS: tutorial
Nilfs is a LFS that NTT(Nippon Telegraph and Telephone Corp.) Group distributed to the Linux world.
It has been merged into Linux mainline 2.6.30 rc-1
Below is the tutorial of how to set up a LFS partition in a VMware VM.
1. Attach multiple virtual disks to the VM in VMware
Editing virutal machine settings -> add -> add a hard disk
2. Install a CentOS5.1 distro in the VM and run the more than 260 updates
(It is said CentOS5.1/5.2 are both OK. But CentOS5.0 needs to be patched.)
root : centos

3. Download the NilFS kmod and utils rpms from nilfs.org site.
i386 utilities package: http://www.nilfs.org/pub/centos/5/RPMS/i386/
i386 kernel module package: http://www.nilfs.org/pub/centos/5/RPMS/i686/
Look for the nilfs utilities : nilfs-utils-2.0.12-1.i386.rpm
Look for the exact kernel version 2.8.18_128 : kmod-nilfs-2.0.12-2.2.6.18_128.1.6.el5.i686.rpm
the utilities and the kernel module version should match the same nilfs version and also the centos kernel version.
(It also includes PAE and Xen rpm packages in the same directory)
4. Install the NilFS rpm package
root: ~>rpm -Uvh kmod-nilfs-2.0.12-2.6.18_128.1.6.el5.i686.rpm
5. Format the virtual disk as nilFS and mount to the system.
(The extra disk is /dev/hda)
Format the disk by mkfs command
root: ~>mkfs -t nilfs2 /dev/hda
mount the LFS disk by mount command
root: ~>mount -t nilfs2 /dev/hda /root/nilfs

6. Use the nilFS to recover the data
Before you make some changes, you can set a checkpoint by mkcp
root: ~>mkcp
root: ~>lscp (lscp will show what checkpoints you have)

After you make the changes, you sjhould make the previous checkpoint to be a snapshot and then mount that previous snapshot to a new spot
root: ~>chcp ss 5
root: ~>mount -t nilfs2 -r -0 cp=5 /dev/hda /root/nilfs-cp
nilfs.org website instructions are at the link http://www.nilfs.org/en/about_nilfs.html (how to use nilfs --incomplete)

7. Umount nilFS disk
root: ~>umount /root/nilfs-cp
root: ~>umount /root/nilfs
Next --> Setup NilFS in a Xen Guest
Subscribe to:
Posts (Atom)
