Tuesday 7 February 2012


Roodi [ Ruby Object Oriented Design Inferometer ]

Roodi stands for Ruby Object Oriented Design Inferometer. It parses your Ruby code and warns you about design issues you have based on the checks that is has configured.

Very easy to install and use with your code.

# gem install roodi

We can check one or more files using the default configuration that comes with roodi.

Check all ruby files in a rails app:
    roodi "rails_app/**/*.rb"

Check one controller and one model file in a rails app:
    roodi app/controller/sample_controller.rb app/models/sample.rb

Check one controller and all model files in a rails app:
    roodi app/controller/sample_controller.rb "app/models/*.rb"

Check all ruby files in a rails app with a custom configuration file:
    roodi -config=my_roodi_config.yml "rails_app/**/*.rb"

CUSTOM CONFIGURATION

To change the set of checks included, or to change the default values of the checks, you can provide your own config file. The config file is a YAML file that lists the checks to be included. Each check can optionally include a hash of options that are passed to the check to configure it. For example, the default config file looks like this:

    AssignmentInConditionalCheck:    { }
    CaseMissingElseCheck:            { }
    ClassLineCountCheck:             { line_count: 300 }
    ClassNameCheck:                  { pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/ }
    CyclomaticComplexityBlockCheck:  { complexity: 4 }
    CyclomaticComplexityMethodCheck: { complexity: 8 }
    EmptyRescueBodyCheck:            { }
    ForLoopCheck:                    { }
    MethodLineCountCheck:            { line_count: 20 }
    MethodNameCheck:                 { pattern: !ruby/regexp /^[_a-z<>=\[\]|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/ }
    ModuleLineCountCheck:            { line_count: 300 }
    ModuleNameCheck:                 { pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/ }
    ParameterNumberCheck:            { parameter_count: 5 }

PostgresSQL Commands for CentOS/Linux & pg_hba.conf configuration

Most of the time we can not install or use pgadmin. I tend to forget simple commands for administering the database. Hopefully this blog will help as reference when working with PostgreSQL

  • Login as "postgres" to start using database:
    # su - postgres
    
  • Create a new database:
    $ createdb mydb
    
  • Drop database:
    $ dropdb mydb
    
  • Access database:
    $ psql mydb
    
  • Get help:
    mydb=# \h
    
  • Quit:
    mydb=# \q
    
  • Read command from file:
    mydb=# \i input.sql
    
  • To dump a database:
    $ pg_dump mydb > db.out
    
  • To reload the database:
    $ psql -d database -f db.out
    
  • Dump all database:
    # su - postgres
    # pg_dumpall > /var/lib/pgsql/backups/dumpall.sql
    
  • Restore database:
    # su - postgres
    # psql -f /var/lib/pgsql/backups/dumpall.sql mydb
    
  • Show databases:
    #psql -l
    or
    mydb=# \l;
    
  • Show users:
    mydb=# SELECT * FROM "pg_user";
    
  • Show tables:
    mydb=# SELECT * FROM "pg_tables";
    
  • Set password:
    mydb=# UPDATE pg_shadow SET passwd = 'new_password' where usename = 'username';
    
  • Clean all databases (Should be done via a daily cron):
    $ vacuumdb --quiet --all

  • The pg_hba.conf file states who is allowed to connect to the database server and which authentication method must be used to establish the connection.This configuration is very useful when we try to connect database through pgadmin client.

    Default pg_hba.conf
    # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
    
    # "local" is for Unix domain socket connections only
    local   all         all                               trust
    # IPv4 local connections:
    host    all         all         127.0.0.1/32          trust
    # IPv6 local connections:
    host    all         all         ::1/128               trust