Wednesday, July 28, 2010

Setting up a UAT box remotely

I am not much in to unix environment. So, when I had to setup a UAT box remotely, I had a score of issues and after a lot reading, learning, trying and asking I reached a set of commands that worked. This is not very specific to the requirement I had.. installing ruby on rails 1.2.3 and postgres on Fedora 12 machine using putty. I know it's a very old version. I wish I could secretly upgrade the version overnight. But it's not possible especially when product is already in production.

Anyway, here are the steps to set up the box that just had Fedora 12 installed and had access to internet.

Installing postgres
yum -y install postgresql postgresql-server postresql-devel


Installing ruby
wget ftp://ftp.ruby-lang.org//pub/ruby/1.8/ruby-1.8.6-p399.tar.gz
tar -xzvf ruby-1.8.6-p399.tar.gz
cd ruby-1.8.6-p399
./configure
make


Checking Ruby installation
ruby -v


Installing rubygems
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.2.tgz
tar -xzvf rubygems-1.3.2.tgz
cd rubygems-1.3.2
ruby setup.rb


Installing all the required gems
gem install rails -v=1.2.3 --include-dependencies
gem install pg -- --with-pgsql-include-dir='/usr/include/pgsql' --with-pgsql-lib-dir='/usr/lib/pgsql'
gem install postgres
gem install mongrel
gem install rubyzip
yum install fcgi fcgi-devel
gem install fcgi -r -- --with-fcgi-lib=/usr/local/fcgi/lib --with-fcgi-include=/usr/local/fcgi/include


Restoring the database

[root@uvt eProfile]# su postgres
-bash-4.0$ psql template1
template1=# create database extranet owner postgres;
template1=# \q
[root@uvt eProfile]# psql -U postgres -d extranet -f db.out


After doing all this, placing the application and starting the server. I wasn't still able to access the application via browser. Later the Admin found that it was due to unix internal firewall. Huff! twas a tough time. But, tough times never last, tough people do.

Wednesday, July 14, 2010

Dynamic variable names

Here is a way of dynamically setting instance variable names in ruby. So as in given example you can use @a, @b et. al. w/o first defining them.

def funcA
new_hash = {:a=>'A',:b=>'B',:c=>'C',:d=>'D'}
new_hash.each{|k,v|
instance_var = "@#{k}"
instance_variable_set(instance_var.to_sym, v)

}
end

funcA
puts @a


Actually, I wanted to iterate through a Settings table and create instance variables for all the settings available. Settings table has name and value columns to store admin settings. And I did not want to write a line for setting every instance variable.

It was simpler than i had thot

settings = Settings.find(:all)

settings.each{|setting|
instance_variable_set("@#{setting.name}","#{setting.value}")
}


Regards,
UVT

PS - I luv Ruby :-)

Saturday, July 10, 2010

Cyclic redundancy issue

Q. Error expected specifier-qualifier-list

A. It is because of cyclic-imports. One file imported to other file and the other file imported back to first one. To avoid this one should use "Forward Class reference"

@class for one of the files instead of #import.

It's explained here : http://timburrell.net/blog/2008-11-23/effective-c-cyclical-dependencies/

Making the iphone keyboard go away

There are three ways to do it:

Here's the basic one:

All the text fields should be connected to file's owner.
- (BOOL)textFieldShouldReturn: (UITextField *)sender {
[sender resignFirstResponder];
return YES;
}


For more events - http://blog.costan.us/2009/01/dismissing-virtual-keyboard-on-iphone.html

Playing with Top and Bottom Nav Bars

Q. How to hide Top Navigation bar?

A.
self.secondNavController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.secondNavController.navigationBar.hidden = YES;



Q. How to disable Bottom Bar (Tab Bar) when a view is pushed?

[delegate.secondNavController hidesBottomBarWhenPushed];

Pushing UIWebView on Navigation controller

This is a stupid mistake that I did when I was a beginner:

Issue : When I am trying to push A UIWebView on a navigation controller it is giving :
- Application tried to push a nil view controller on target
{
simpleDemoAppDelegate* delegate = [[UIApplication sharedApplication] delegate];
delegate.username = usernameText;
delegate.password = passwordText;
[delegate.secondNavController pushViewController:webView animated:YES];
}



Solution:

I had declared the webView variable in header file but not initialized the weView variable:

Corrected Code:

{
simpleDemoAppDelegate* delegate = [[UIApplication sharedApplication] delegate];
delegate.username = usernameText;
delegate.password = passwordText;
webView = [[WebViewController alloc]init];
[delegate.secondNavController pushViewController:webView animated:YES];
}


And this "animated:YES" is fooking important!

Otherwise you will get a pushViewController:]: unrecognized selector sent to instance error.

Friday, July 9, 2010

Error starting Postgres

The postgres database service on my fedora box has failed to start
I say
service postgresql restart

it says

#Starting postgresql service: /etc/init.d/postgresql: line 114: echo: write error: Permission denied


I am trying with root access and it was working fine before the reboot. I have not installed anything new. :-(

Solution:

Thanks to Aasif Shaikh for his timely help
This was the mantra he used

# su - postgres -c "/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data"


OR use this if the above says file not found

# su - postgres -c "/usr/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data"


And postgres was up and running :-)

-UVT

PS- Postgres sucks!

Why a new blog?

It's a purely technical, no-nonsense, problems and solutions blog.

It's just a repository of bugs that bugged me and their solutions that finally saved my life. I'm not sure how much it would help the world. But I know it will help me someday.

Sshh!! No-nonsense!

-UVT