Sunday, October 24, 2010

Linux chmod by the numbers

Up to this point, we’ve been setting the mode with letters. It turns out that you can also set the mode numerically. Here’s how it works:

  1. Write the permissions you want the file to have. To make your life easier, write the permissions grouped into sets of three letters. For example, let’s say you want file info.sh to have these permissions
    - rwx r-x r-- info.sh
    
  2. Under each letter, write a digit 1; under each dash write a digit zero. Ignore the dash at the very beginning that tells you whether it’s a file or directory. This gives you three binary numbers.
    - rwx r-x r-- info.sh
      111 101 100
    
  3. Now convert each set of three digits to a single digit using this table:
    BinaryBecomes
    0000
    0011
    0102
    0113
    BinaryBecomes
    1004
    1015
    1106
    1117
    From our example, the 111 101 100 translates to the number 754.
  4. Now use that number in a chmod command to set your desired permissions on the file:
    chmod 754 info.sh

Thursday, October 21, 2010

Minimize ripple effects in OOP programing

What is the meaning of minimize ripple effect?
Minimizing the ripple effects means limit the force of  changes to a program. Simply saying by keeping details secret in your code (information hiding or encapsulation).


Basically there are three ways of doing it: 


By indirection 
  That means named constants replacing "magic numbers" in your piece of code.
  e.g: 
  A magic number is a direct usage of a number in the code. see the following piece of code as example     which is not best practice to use:


public class Foo {
     public void setPassword(String password) {
          // don't do this
          if (password.length() > 7) {
               throw new InvalidArgumentException("password");
          }
     }
}


 Best practice is in the following code: 







public class Foo {
     public static final MAX_PASSWORD_SIZE = 7;

     public void setPassword(String password) {
          if (password.length() > MAX_PASSWORD_SIZE) {
               throw new InvalidArgumentException("password");
          } 
}

***  It will improve the readability of the code and of course maintainability

***  Imagine the case where I set the size of the password field in the GUI. If I use a magic number, whenever the max size changes, I have to change in two code locations. If I forget one, this will lead to inconsistencies.


By minimizing visibility


 Use private fields, package-private classes to hide information from public access.


By generic references


Use  (polymorphism) - using high level references (interfaces or abstract classes) instead of low level references (concrete classes).



Tuesday, October 19, 2010

Linux IP Commands

Display Current Config for all NIC's: ifconfig

Display Current Config for eth0: ifconfig eth0

Assign IP: ifconfig eth0 192.168.1.2

Ping: ping -c 3 192.168.1.1

Assign multiple IP's: ifconfig eth0:0 192.168.1.2

Assign second IP: ifconfig eth0:1 192.168.1.3

Disable network card: ifconfig eth0 down

Enable network card: ifconfig eth0 up

View current routing table: route "or" route -n

View arp cache: arp "or" arp -n

Assign IP/Subnet: ifconfig eth0 192.168.1.2 netmask 255.255.255.0

Assign Default Gateway: route add default gw 192.168.1.1

Trace Route: traceroute www.whatismyip.com

Trace Path: tracepath www.whatismyip.com

DNS Test: host www.whatismyip.com

Advanced DNS Test: dig www.whatismyip.com

Reverse Lookup: host 66.11.119.69

Advanced Reverse Lookup: dig -x 66.11.119.69

Tuesday, October 12, 2010

Installing Maven on linux

What is maven?
Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:
  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution
If you want to have more details about maven please refer The Philosophy of Maven and The History of Maven.

Advantages of using mavan:
  1. common build structure
  2. build best practices enforcement (shared build meme)
  3. automated build of application, from source code to pre-production platform => fast time to market with reduced risks
  4. works well with distributed teams ;-) Location doesn't matter.

Compared to Ant:

  1. Higher level of reusability between builds
  2. Faster turn around time to set up a powerful build (once you're used to Maven)
  3. Less maintenance
  4. Shared build meme. I know how to build any maven project
  5. Greater momentum: Ant is now legacy and not moving fast ahead. Maven is forging ahead fast and there's a potential of having lots of high-value tools around Maven (CI, Dashboard project, IDE integration, etc).
You can download the maven:

How to install:

create a environment variable on bash profile as
MAVEN_HOME=/installation path/apache-maven-2.2.1
Finally export it as export PATH=$MAVEN_HOME/bin:$PATH on your bash profile in Linux and source the bash profile .

You can check if maven is correctly installed by having mvn -v on terminal.