Tuesday, April 29, 2008

Inspecting object in javascript

An interesting problem is to inspect unknown objects in javascript. Found a good example of how to do it here. Just to rehash in case the site move:

function inspect(obj, maxLevels, level)
var str = '', type, msg;

// Start Input Validations
// Don't touch, we start iterating at level zero
if(level == null) level = 0;

// At least you want to show the first level
if(maxLevels == null) maxLevels = 1;
if(maxLevels < 1)
return '<font color="red">Error: Levels number must be > 0</font>';

// We start with a non null object
if(obj == null)
return '<font color="red">Error: Object <b>NULL</b></font>';
// End Input Validations

// Each Iteration must be indented
str += '<ul>';

// Start iterations for all objects in obj
for(property in obj)
// Show "property" and "type property"
type = typeof(obj[property]);
str += '<li>(' + type + ') ' + property +
( (obj[property]==null)?(': <b>null</b>'):('')) + '</li>';

// We keep iterating if this property is an Object, non null
// and we are inside the required number of levels
if((type == 'object') && (obj[property] != null) && (level+1 < maxLevels))
str += inspect(obj[property], maxLevels, level+1);
// Is there some properties in obj we can't access? Print it red.
if(typeof(err) == 'string') msg = err;
else if(err.message) msg = err.message;
else if(err.description) msg = err.description;
else msg = 'Unknown';

str += '<li><font color="red">(Error) ' + property + ': ' + msg +'</font></li>';

// Close indent
str += '</ul>';

return str;

Javascript ninja on Cakephp

Fuh.. Cakephp by default uses the script.aculo.us library for ajax which uses the prototype javascript library. To get you're ninja on prototype you can refer directly to the docs. Good stuff..

Using firebug in Ubuntu Hardy Heron

*Update* Yesterday kaeru pointed out that firebug from the ubuntu repo works with the default firefox 3 beta on Hardy. Just tried it and I'm glad to report it does work very nicely. No more need for this workaround.. Just look for it in synaptic or apt-get install firebug.

What can I say? Ubuntu is pretty bleeding edge. :P It comes with firefox 3 beta 5 which is pretty slick. But there are still a lot of add-ons which do not work with firefox 3 beta. Earlier on I've blogged about using the 1.1 beta of firebug with firefox 3 beta. It works pretty well on my home box which runs arch linux. But on my computer at the office running on Ubuntu, firebug doesn't even come out. So I had to find a way around.

Luckily Firdaus of OSCC showed me that you actually can install Firefox 2 on Ubuntu. It's still in the repo and you just have to select it with synaptic or apt-get 'Firefox-2'. But the default installation will share the same default profile of Firefox 3 and so will break firebug when you launch Firefox 3. So what can you do? KageSenshi showed me how creating profiles for firefox will solve the problem. Well, first you have to create a different profile just for Firefox 2 by running 'firefox-2 -profilemanager'. There you can create your profile. Make sure you never use this new profile with Firefox 3 so what we do is that we change the command of the icon to start firefox 3 to 'firefox -P "Default"' and the icon to start firefox 2 to 'firefox-2 -P "firefox2"' (Use the name of the profile you created before). I don't think you can run both versions at the same time but I don't have time to experiment right now. These settings work and I have to get back to work.

Saturday, April 19, 2008

VirtualHost in apache

Finally understand it after reading:
I was having lotsa trouble understanding why wasn't my rules applying to the vhost I was setting up. But after reading that I know you weren't suppose to create multiple NameVirtualHost entry. Just one. The ServerName inside the VirtualHost block will determine whether that block applies to the query or not.

Friday, April 18, 2008

Using ssh and scp without a password

ssh and scp are very useful for making sure you work in a pretty secure environment. But sometimes it can be a hassle if you have to keep on keying in your password to login many times to the server or you might need to write a backup script but do not want to write your password in the script then I have found a solution at https://help.ubuntu.com/community/SSHHowto#public-key-auth.

Basically what you need to do is copy your public key to the authorized keys file on the server. If you haven't got a public key yet just type in:

ssh-keygen -t dsa

And that will create an id_dsa.pub file in your ~/.ssh folder (By default, you can set it in other places if you want). Anyway, copy the content of that file (it should be just one line) into the ~/.ssh/authorized_keys file on the server you want to login. Now whenever you ssh username@server you'll access it straight away without any password. And scp also works without password so you can write those scripts.

Bash your head on this..

Uhm.. Bash scripts are really great.. But sometimes you just forget how to do even the simplest thing (like how do you set an else condition :P). So here's a very good and simple starting point at:
http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html. That should be able to bring you up to speed till you start writing whole apps in bash.. ;)

Thursday, April 17, 2008

svn, ldap and groups.. big words

Alhamdullillah.. just got svn with ldap auth working. And even restricting commit by user group. It was quite tedious to finally get the settings right, but here's some references which was used:
Starting to look good.. :)

Wednesday, April 16, 2008

Using ldap auth in lighttpd

Alhamdullillah.. It is quite easy to set up lighttpd to authenticate using ldap. Found a reference here: http://wiki.netbsd.se/Lighttpd_on_NetBSD. Just enable mod auth and follow the examples in the wiki. Great.. :)

Setting up trac in ubuntu

After looking for quite some time finally found and easy guide to install trac on ubuntu at http://code.softwarefreedom.org/projects/backports/wiki/TracFastCgi. So I've got it up and running and uploaded one of the first Abdullah Solutions project we did. E-Punch is an online punch clock where you clock in by using a login. It checks your ip to make sure you are in the local network, and there is even a module to use a fingerprint reader. But the fingerprint reader interface was written using VB though and is not included in this folder. I am yet to set up svn so that you can download it but you can already browse it on trac at http://abdullahsolutions.com/trac/epunch

Tuesday, April 15, 2008

Regular expression in VIM

Sometimes you just forget how to do it... Here's some reference that might help


Firebug for Firefox 3

Are you using Firefox 3 Beta? You need to use Firebug but when you check the Extensions page the Firebug is not compatible with Firefox 3 Beta? Well.. here's the solution for you. With beta software use beta software. Go to http://www.getfirebug.com/ and download the 1.1 Beta. It works in Firefox 3 Beta and that is GREAT.. :)

Getting postfix relay to work with godaddy.com

Alhamdullillah after days (and I mean literally days because each day I can spend only a few minutes on this problem) I have finally got it working. To set up postfix to use relay with authentication, just ask the oracle. But to get it working with godaddy? I finally gave up and sent them an email. And in their reply was my answer:
Username: Your full email address (i.e. person@domain.com)
Outgoing Mail Server: smtpout.secureserver.net
Outgoing Mail Server Port: 25, 80, or 3535.

And so first I tested the ports. After telneting the host and ports I finally decided that most probably would work best because the server response has the word 'auth' in it (I have no idea whether it's even relevant or not). Anyhow changed it my /etc/postfix/main.cf to use the 3535 port:
relayhost = smtpout.secureserver.net:3535

And the most important part is the username. It is person@domain.com. It is the person@domain.com you registered your free mailbox with. Not your login name to godaddy. Use the email address. And then run postmap, restart postfix, and viola, it is sending mail and those mails don't just get dumped into trash. Fuh...

Thursday, April 10, 2008

WebDav works :)

Alhamdullillah.. finally got webdav in plone not only working, but rerouted through apache lak tu... :)

First step, enable webdav in plone. Go to the zinstance/etc/zope.conf file and unremark the webdav part.

# # valid keys are "address" and "force-connection-close"
address localhost:1980
force-connection-close off

And restart your zope. That ought to make it listen to port 1980 on localhost for webdav connection.

Then go to your apache web root folder and add a folder with the same name of your plone instance. Inside there put a .htaccess file like this:

RewriteEngine on
RewriteRule ^($|.*) http://localhost:1980/dev/$1 [L,P]

And that will redirect any access to your folder to the proper port (Note: because you can't use VirtualHostMonster for webdav, it has to be in the same folder as your plone instance. You can put the redirect to your plone instance in a different folder and redirect it from there with VirtualHostMonster).

Okay.. Once that is done you should be able to access it using a webdav client. It has to be a webdav client, not your browser because your browser will not know how to handle webdav. Ok.. so for the webdav client? For ubuntu you can try here:
http://sysblogd.wordpress.com/2007/09/09/ubuntu-mounting-remote-filesystem-using-davfs2-fuse/ . Then you can use it just like a normal folder. Cool.

Oh.. for more reference go to:

Tuesday, April 8, 2008

A little drama

Hahahaha... My brothers' (Basyeer and Munzeer) friend blogged about a recent acting they did at Putrajaya. Just for fun, check it out at Heaven's Cloud.

Monday, April 7, 2008

Use rsync to copy files

Finally took time to learn rsync. Great stuff. Can copy gigs and gigs of files real fast. Learned it from http://www.physics.queensu.ca/Computing/Docs/HOWTOs/rsync/. Basically all I needed to do was:
rsync -av -e ssh username@host:/source/directory/ destination/directory

Or if you need to ssh over a different port you would do something like this:
rsync -av -e "ssh -p 443" username@host:/source/directory destination/directory

-a for archive. -v for verbose. -e to specify to use ssh.

Thursday, April 3, 2008

Setting up awstats in ubuntu

Finally my server at abdullahsolutions.com has awstats after delaying to install it for so long. The steps I follow were found at here http://www.petersblog.org/node/697 . Here they are:
  • Install awstats package
  • Edit a file called /etc/awstats/awstats.hostname.conf where hostname is the hostname. Put something like this in it:
  • Make a directory called /var/cache and chmod it 777 so it can be used from the web server
  • Copy icons to web directory:
    cp -r /usr/share/awstats/icon /var/www/icon
  • Run this to update databases:
    /usr/lib/cgi-bin/awstats.pl -config=hostname -update
  • In your web browser, go to the url:
  • Study the stats in quiet awe
  • Edit crontab to update stats automatically every night:
    crontab -e
    0 1 * * * /usr/lib/cgi-bin/awstats.pl -config=hostname -update
But my website is still pretty empty though. Hope to add more stuff soon.

Haiya ala Solah