Custom Search

Tuesday, May 24, 2011

howto linux usb harddisk partition using fdisk cfdisk

howto linux usb harddisk partition using fdisk cfdisk

1)List
# fdisk -l

2)Partition
# cfdisk /dev/sdb <----- Here sdb is the USB drive.
or
# fdisk /dev/
* first Detete all partition
* the create new (using cfdisk we can do it easily)

3) Format
# fdisk -l

# mkfs.ext4 /dev/sdc5

# mkfs.ext4 /dev/sdc6

# mkfs.ext4 /dev/sdc7

4) Mount
# fdisk -l

Saturday, May 14, 2011

python decorator class examples

class FormatMe:
def __init__(self, fun):
self.fun = fun

def __call__(self, name):
return self.fun(name)+2

@FormatMe
def add_test(num):
return num

print "----------", add_test(6)

#######################

class FormatMe:
def __init__(self, const):
self.const = const

def __call__(self, func):
def _wrapper(name):
return func(name)+self.const
return _wrapper

@FormatMe(100)
def add_test(num):
return num

print "----------", add_test(6)

######################

class FormatMe:
def __init__(self, const):
self.const = const

def __call__(self, func):
def _wrapper(name):
return func(name)+self.const
return _wrapper

@FormatMe(const=200)
def add_test(num):
return num

print "----------", add_test(6)

Output
======

---------- 8
---------- 106
---------- 206

Friday, May 13, 2011

howto install VMware-Workstation on ubuntu Ubuntu 11.04 Natty Narwha

1) Download VMware-Workstation
https://download2.vmware.com/software/wkst/VMware-Workstation-Full-7.1.4-385536.x86_64.bundle

2)Remove old VMware-Workstation if exist.
$ sudo vmware-installer -u vmware-workstation

3)Install
$ sudo sh VMware-Workstation-Full-7.1.4-385536.x86_64.bundle

Tuesday, May 10, 2011

How to mysqldump without CREATE TABLE statements

MySql Dump
# mysqldump -u dbuser -p[pwd] --opt databasename > database_backup.sql
MySql Dump without data (only structure)
# mysqldump -u dbuser -p[pwd] --no-data databasename > database_backup.sql
or
# mysqldump -u dbuser -p[pwd] -d databasename --no-data > database_backup.sql
MySql Dump without structure (no drop/create table)
# mysqldump -u dbuser -p[pwd] --no-create-db --no-create-info databasename >
database_backup.sql
Import SQL file
mysql -u user_name -p  database_name < /path/to/file.sql

Sunday, May 1, 2011

Python list comprehensions Tricks

The power of the inline loops.

Suppose we have three-dimensional array:
d3 = [ [ [101,100], [99,98] ] , [ [97,96], [95,94] ] ]

Let's transform it into two-dimensional array
d2 = [ d3[a][b] for a in range(2) for b in range(len(d3)) ]
Result:
[[101, 100], [99, 98], [97, 96], [95, 94]]

and into one-dimensional array:
d1 = [ d2[b][a] for b in range(len(d2)) for a in range(2) ]
Result:
[101, 100, 99, 98, 97, 96, 95, 94]

We can also jump from 3d to 1d:
d1 = [ d3[a][b][c] for a in range(len(d3)) for b in range(2) for c in range(2) ]
Result:
[101, 100, 99, 98, 97, 96, 95, 94]

Now, let's do reverse transformation:
From 1d to 2d:
d2 = [ [ d1[a+b] for b in range(2) ] for a in range(0,len(d1),2) ]
Result:
[[101, 100], [99, 98], [97, 96], [95, 94]]

and from 2d to 3d:
d3 = [ [ d2[a+b] for b in range(2) ] for a in range(0,3,2) ]
Result:
[[[101, 100], [99, 98]], [[97, 96], [95, 94]]]

And of course we can do far-jump from 1d to 3d:
d3 = [ [ [ d1[b+a+c] for c in range(2) ] for b in range(0,3,2) ] for a in range(0,5,4)]
Result:
[[[101, 100], [99, 98]], [[97, 96], [95, 94]]]