Monday, March 31, 2008

Textmate: Ubuntu style!

If you've ever watched any railscasts, most of them use something called Textmate to edit their files on a Mac. Apparently, it's suppose to be really good.

Well, recently, I've been getting really fed up with Aptana and RadRails. There are lots of things that bug me, like the wait time to save a file and especially the wait time to copy/paste things. It's just horrible. Furthermore, RadRails decides to crap out on me every so often. There are so many errors in the background that I run out of memory. So far, there doesn't seem to be a fix.

Enough of that... I'm moving on to better things, like a Textmate clone: a revved up version of Gedit! Apparently, you can easily make Gedit behave very similarly to Textmate! I followed this guide and so far, everything is smooth.

I haven't tried developing yet. I just installed everything. I'll let you guys know how it goes... but I'm anticipating I'll like this more than RadRails. Only downside is the loss of the SVN plugin and a debugger... I wonder...


W

Ruby Exception Hiearchy

For those who wants a better understand of the exception hiearchy, here it is!

Exception
Errno
NoMemoryError
ScriptError
LoadError
NotImplementedError
SyntaxError
SignalException
Interrupt
StandardError
ArgumentError
IOError
EOFError
IndexError
LocalJumpError
NameError
NoMethodError
RangeError
FloatDomainError
RegexpError
RuntimeError
SecurityError
SystemCallError
SystemStackError
ThreadError
TypeError
ZeroDivisionError
SystemExit
SystemStackError

Cheers,

Joseph

Sunday, March 30, 2008

Ubuntu beats out Mac and Vista

The results are final from the 3-day-long hack-fest and guess who came out on top? Yup, that would be Ubuntu!

A hacking contest was held in Vancouver recently which featured 3 laptops, 1 was a MacBook Air, the other a Vista, and the 3rd was an Ubuntu.

The first to be compromised was the MacBook Air. Amazingly, Vista held its ground until the 3rd day, where it was finally pwned.

More details can be found here:

http://dvlabs.tippingpoint.com/blog/2008/03/28/pwn-to-own-final-day-and-wrap-up


W

Friday, March 28, 2008

Named Routes: url vs path

So I spent a good 30 minutes trying to figure out why my links were missing the host part of the URL.

What I was trying to do was send emails using ActionMailer and generating urls inside the ActionMailer instead of the ActionController. The documentation says that you can use url_for and named routes if you do what it says.

Well, for a while there, I was completely stumped as to why my named routes were missing the host part, until I realized I was using the path method for named routes instead of the url method:

users_path #/users
users_url #http://www.mysite.com/users

The difference is obvious. However, if you're used to using path instead of url, you may be stumped as well. Hopefully, you guys won't have to go through the trouble I did ;)


W

Friday, March 21, 2008

Ubuntu + Postfix

So I researched a little bit about setting up an email server. I at least got something going, as I could send email out. However, I am still using my ISP's server as a relay host, as they block port 25.

On Ubuntu, I set up Postfix by following the documentation.

Then, to use a relay host, I simply went into /etc/postfix/main.cf and entered the server's address into the relayhost variable.

A quick reload of the Postfix server:

>sudo /etc/init.d/postfix reload

and all was right with the world.

To set up POP3 and IMAP, take a look at the following documentation.

Enjoy!


W

Wednesday, March 19, 2008

Bugzilla: Round 2 (continued)

So what happens when your ISP blocks port 80 and 25. Well... Bugzilla cannot be accessed and emails cannot be sent... kinda useless then huh?

Changing the apache listening port from 80 to something else is quite easy:

>sudo gvim /etc/apache2/ports.conf
Change the 'Listen' port to your own preference
>sudo /etc/init.d/apache2 stop
>sudo /etc/init.d/apache2 start

That should fix the port 80 problem.

Now for the port 25 problem. I originally tried to get sendmail to use an alternate port for sending emails. However, this attempt was unsuccessful. I also tried installing postfix, but nothing worked. I then tried to connect to an external smtp server like smtp.gmail.com:587. However, this required TSL to be enabled, and I couldn't find any settings in Bugzilla that would support it. Interestingly enough though, I found a patch to add username/password to the SMTP configurations that will be included in the next Bugzilla:

https://bugs.launchpad.net/ubuntu/+source/bugzilla/+bug/133903

I then found out that my own ISP, Shaw, had an email server. I hope I'm not using it illegally, but there is no authentication required for mine. I ended up setting configuration to use SMTP rather than sendmail, and added the SMTP server from Shaw. I then restarted apache2 for safe measures, and VOILA! Bugzilla with emails!

Obviously, this is a workaround which uses an external SMTP server, but it works! Maybe if I have more time, I will play with sendmail and see if I can get it to work. In the meantime... I'm happy!


W

Bugzilla: Round 2

With the previous installations of Bugzilla, there were several configurations that were missing. Firstly, after logging in as an adminstrator, it was not possible to change any of the parameters using the website. Secondly, emails were not working properly. There were several other configuration mistakes as well, but I will not list them here.

So, I present to you Round 2:

Follow the previous instructions in installing the version from the Ubuntu repos.

If you get an error about not being able to log into database, do the following:

>sudo /etc/bugzilla/localconfig
change $db_pass to the correct password, then save
>sudo apt-get remove bugzilla
>sudo apt-get install bugzilla

This should reinstall bugzilla with the correct password to access the database.

Next, we will upgrade to the latest version (3.1.3 at this time):
1. somehow get the 3.1.3 tarball and store it in /var/www/ (wget or straight from Bugzilla's website)
2. >su
3. >tar -zxvf bugzilla-3.1.3.tar.gz (this will create a folder called bugzilla-3.1.3)
4. >cd bugzilla-3.1.3
5. >./checksetup.pl --check-modules (install anything that it tells you to)
6. >gvim localconfig (or use any editor that you prefer)
6.1 change the $webservergroup from 'apache' to 'www-data' (debian linux uses www-data)
6.2 fill in the $db_pass for the 'bugs' user
6.3 save and quit
7. >./checksetup.pl (this should reconfigure a bunch of templates and set everything up)
8. chmod -R 755 . (not sure if we really need to do this)
9. chmod -R 755 /var/lib/bugzilla/data (not sure if we really need to do this)

Now it's time to replace the originally installed Bugzilla from the Ubuntu repos:
1. cd .. (so now we are back in /var/www/)
2. rm -rf bugzilla/*
3. cp -pr bugzilla-3.1.3/* bugzilla/ (not sure if the p is needed)
4. chown www-data:www-data -R bugzilla

Configure apache:
1. >gvim /etc/apache2/httpd.conf
1.1 add to the bottom if not already there:

<Directory /var/www/bugzilla>
AddHandler cgi-script .cgi
Options +Indexes +ExecCGI
DirectoryIndex index.cgi
AllowOverride Limit
</Directory>
2. >/etc/init.d/apache2 stop

3. >/etc/init.d/apache2 start (perhaps restart will work here too, but this is safer

Now go to your Bugzilla using your browser and login as the administrator. As a hint, you know it worked if you can get to the home page, DON'T see version '2.22.1 Debian' somewhere (the default look is Dusk, so it should look a little dark - not a white background), and you can login.

After logging in, go to the parameters page (.../bugzilla/editparams.cgi). Set the maintainer, then save. If this works, the installation should be working fine. These were all the parts that were originally giving me problems (page not found, could not write, etc, etc, etc!!!).

If you expect emails to work, try creating a new user account and see if you get any emails in the inbox. However, if you are like me and port 25 is blocked, there's more fun to come ahead ;)

Next post, I will go over how to setup Bugzilla when port 80 and 25 are blocked by your ISP.


W

Tuesday, March 18, 2008

Bugzilla Installation on Ubuntu: extra comments

So I was giving Bugzilla a try on my Ubuntu, following the steps in the previous post. All went well, except for one little hiccup.

The bugzilla page would show, except when you tried to log in, it gave you a page not found. Apparently, there is a bug with the default setup in Ubuntu:

https://bugs.launchpad.net/ubuntu/+source/bugzilla/+bug/133903

To fix it, simply go to the params file and modify the 'urlbase' to the correct path (without the '.'). Remember to use sudo!


W

Monday, March 17, 2008

Bugzilla Installation on Ubuntu

the installation guide on bugzilla's website scares me, you can easily spend over a day in order to get it up and running. Fortunately, that's not the case for ubuntu.

with the help of apt-get, we can easily cut it down to 15 mins

1. apt-get install mysql-server (if it's not already there)
2. then follow on screen instructions
3. mysql -u - root -p (we need to create a new user called bugzilla)
4. GRANT ALL PRIVILEGES ON *.* TO 'bugzilla'@'localhost' IDENTIFIED BY 'password';
5. \q
6. apt-get install bugzilla (we are half way done already lol)
7. follow on screen instructions

and you are done! goto http://yourserver/bugzilla and start using it.

the package we just installed is version 2.2, for those who want the latest and greatest, please keep reading, I need another 15 minutes of your time.

1. goto /var/www/ and wget the latest tarball from bugzilla
2. tar -zxvf the_file_you_just_downloaded.tar.gz
3. log back into mysql and create a 'bugs' account (step 3 and 4 from previous section)
4. cd into the newly extracted bugzilla folder
5. cp -pr ../bugzilla/data .
6. sudo ./checksetup.pl
7. sudo chmod -R 755 .
8. sudo chomd -R 755 /var/lib/bugzilla/data
9. open /etc/apache2/httpd.conf

add the following line to the bottom (if it's not there)

<Directory /var/www/bugzilla>
AddHandler cgi-script .cgi
Options +Indexes +ExecCGI
DirectoryIndex index.cgi
AllowOverride Limit
</Directory>
10. restart the server : sudo /etc/init.d/apache2 restart
11. rename the newly extracted folder to bugzilla
12. enjoy


J

Saturday, March 15, 2008

Postgres + Rails + Ubuntu Troubleshooting

Problem 1 - forgotten password for postgres

Solution - TOUGH! you gotta re-install, that's what happened to me

Problem 2 - sudo apt-get remove postgresql did not remove any of the configuration files

Solution - use apt-get purge postgresql instead, this applies to all other packages

Problem 3 - sudo apt-get purge postgresql did not remove all the associated files

Solution - use sudo apt-get purge postgresql* instead or you can run apt-get autoclean after

Problem 4 - postgres refuses connection, but I swear I entered the password correctly!!!

Solution - postgres is very protective, the account you are logging in must match your current linux account .

Problem 5 - But what if I want postgres to manage its own account?

Solution - edit /etc/postgresql/8.1/main/pg_hba.conf, look near the bottom of the file, modify "Unix domain Socket" to local all all md5, "IPv4 local connections" to host all all 127.0.0.1/32 md5

and don't forget to restart the server by doing /etc/init.d/postgres-8.2 restart

Problem 6 - I installed postgres-pr but rails can't connect to postgres and I tried installing the
regular postgres gem but it failed!

Solution - in order to install the postgres gem, make sure you have the libpq-dev gem installed first. (gem install libpq-dev). Try installing the postgres gem again, it should work!

Problem 7 - I want postgres to run on some other port, what can I do?

Solution - first edit the /etc/postgresql/8.2/main/postgresql.conf, change the port number there first (don't forget to restart the server) then you have to goto your rails directly and edit config/database.yml, add ":port [portnumber]" to all your environments.


J

Monday, March 10, 2008

RoR: each

So I was needing to do some eager loading in a very particular way. I had an array of users, and I needed to eager load some tables:

users.each { |user| user.reload(:include => :country) }
# use user.country somewhere down below

Reading the API, it says that it will pass on any options passed into reload to the find. I thought, "Great! It'll eager load things". Well, I was wrong. When I got down to using country, it did another SQL find! I thought that maybe the reload doesn't do eager loading, so I tried to force it:

users.each { |user| user = User.find(user.id, :include => :country) }

This should definitely work, except when I accessed my individual users, they were the same as if I hadn't executed the above line. It seems that the assignment to the user object doesn't change the one in the users array! However, you can change the attributes of the user object. My guess is that when assignment is involved, a new user object is created in the scope of the each block.

I ended up doing a very crude, brute force way:

i = 0
users.each do |user|
users[i] = User.find(user.id, :include => :country)
i = i + 1
end

This has solved my problem, albeit ugly.


W

Sunday, March 2, 2008

Mcolumn reference "id" is ambiguous

Today I tried to improve the performance of my action by doing just one db call through eager loading. For those who have no idea what it is, please read our previous post

http://twoblinddevs.blogspot.com/search?q=eager+loading

This is what I wanted to do

Person.find(:first, :include=>[ :person_info, :messages], :conditions=>["id = :user_id", { :user_id => session[:id]}] )

when I refreshed the browser, it shows me this error message - Mcolumn reference "id" is ambiguous.

The reason rails complain is because all three tables have an id column. In order to work around this problem, you simply have to change id = :user_id to people.id = :user_id


J