Trying to understand Ruby :symbols

After reading Kevin Clark's recent post on Ruby symbols made me want to learn more about this mysterious part of the Ruby language. After writing some unit tests to ensure that a symbol really is the same object as any other with the same name, I have come to the following conclusion: symbols are immutable string objects, same named symbols share the same object and therefore the same object_id.

Kevin's example points out that they make great keys for hashs, and other indicators of what action to take (:get, :post, etc.)

Coming from a Java background, symbols have made me hit my head a number of times, this rather helpful post from Rob Sanheim helped clear things up a lot for me.

Why the lucky stiff also has a good explaination, he suggests:

Symbols

Symbols are words that look just like variables. Again, they may contain letters, digits, or underscores. But they start with a colon.

:a, :b, or :ponce_de_leon are examples.

Symbols are lightweight strings. Usually, symbols are used in situations where you need a string but you won’t be printing it to the screen.

You could say a symbol is a bit easier on the computer. It’s like an antacid. The colon indicates the bubbles trickling up from your computer’s stomach as it digests the symbol. Ah. Sweet, sweet relief.

So I've got a number of different explainations of symbols, I've written 5 unit tests about them, but I'm still not 100% sure of all their uses. I suppost I just need to get Rails installed and start playing with that to really see how symbols should be used...

Technorati Tags: , , , , ,

Configuring Subversion (svn) on Linux (Debian Stable)

My last post documented how to install Subversion. This post will cover the resulting configuration of Apache, plus the creation of the initial repository.

When you install Subversion, it adds two LoadModule lines to /etc/apache2/httpd.conf. This is not wanted as the Debian version of Apache2 installs things slightly differently from the default Apache (httpd.conf is not used, all this configuration now lives in apache2.conf, plus the loading of modules is done differently). edit /etc/apache2/httpd.conf and remove the 2 uncommented LoadModule lines.

Debian loads modules a little differently that the default Apache2. It lists the available modules as individual configuration files within a mods-available directory, then enables these by linking to them from a mods-enabled directory.

We need to create the two required module configuration files that are required by Subversion (we just removed them from /etc/apache2/httpd.conf!):

cd /etc/apache2/mods-available
echo "LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so" > dav_svn.load
echo "LoadModule authz_svn_module /usr/lib/apache2/modules/mod_authz_svn.so" > authz_svn.load


Now we need to enable them so that Apache will load them when it restarts:

cd ../mods-enabled
ln -s ../mods-available/dav.load
ln -s ../mods-available/dav_svn.load


That's the modules configured, now we need to create the Subversion virtual host entry that will point to our Subversion repository. Again, Debian does things a little different with virtual hosts, it has them listed as separate virtual host configuration files in sites-available and then enables them in sites-enabled:

cd /etc/apache2/sites-available

Due to Blogger being a pain when it comes to trying to post details containing lots of <'s and >'s, I'm including a link to an almost-copy of my Subversion virtual host configuration file. As you can see, it points the WebDAV & Subversion modules at /var/svn which will be the root of our repository, and uses Apache's htpasswd authentication to validate access.

Now we need to make the Subversion site available to Apache:

cd ../sites-enabled
ln -s ../sites-available/svn


Ok, that's Apache all done and dusted, now we just have to actually create the repository and then we are done.

The repository must be 'owned' by the same user that Apache runs as, otherwise read/write access may be blocked and all sorts of strange problems can occur, Debian runs Apache as user www-data by default:

mkdir /var/svn
chown www-data:www-data /var/svn


Now that the repository's root directory has been created, it's best to be the same user as Apache when creating the repository to ensure the files are created with the correct permissions:

su – www-data
svnadmin create /var/svn


That's the repository created, now we need to restart Apache to let the WebDAV & Subversion modules know that the repository is now available:

/etc/init.d/apache2 reload

If you now point your browser at http://svn.yourdomain.com you should see a web view of your new repository...what's that? It's asking for a username and password? Oh yes, we need to create any required users via the Apache htpasswd utility:

cd /etc/apache2
htpasswd -c svn.htpasswd your_username


Ok, try that URL again, you should be able to login and see a rather basic view of an empty Subversion repository. There is a slightly nicer skin that can be applied to Subversion to make the repository view cleaner, it's tucked away in the /usr/local/src/subversion-1.2.1/tools/xslt directory. These XSL and CSS files need to be added to the virtual host's document root, but as you may have noticed the DocumentRoot is the root of the Subversion repository. This means that you just have to import the two files into Subversion for the changes to take effect:

cd /usr/local/src/subversion-1.2.1/tools/xslt
svn import svnindex.xsl http://svn.yourdomain.com/svnindex.xsl -m "Improved web interface."
svn import svnindex.css http://svn.yourdomain.com/svnindex.css -m "Improved web interface."


Now revisit that URL again, and it should be a slightly nicer view of the repository, now with two files in it, svnindex.xsl and svnindex.css.

That's it, the repository is fully available to any user that you have created an htpasswd entry for in /etc/apache2/svn.htpasswd and who has a suitable Subversion client (TortoiseSVN and RapidSVN are two that I have used).

For full documentation on how to really use Subversion, please take a look at the O'Reilly Version Control with Subversion online book or buy the rather excellent book Pragmatic Version Control Using Subversion by Mike Mason.

Please let me know if you found this post (and the last one on how to install Subversion) useful, if so I might start to blog about Subversion even more...

UPDATE: I've moved some files around on my server, I've not changed any of the content of this post.

Technorati Tags: , , , ,

Installing Subversion (svn) on Linux (Debian Stable)

This post details my recent install of Subversion 1.2.1 on Debian Stable. The Debian packaged version of Subversion is currently only 1.1.4, but I wanted to install the latest version as it supports full WebDAV autoversioning & has the FSFS repository back end as the default.

I wanted to access Subversion via the WebDAV protocol, this requires Apache2. As Debian Stable only recently included the apache2 package, I had to update to that version first.

Note: all these commands were run as the root user.

Install Apache2:

apt-get install apache2

That installs the web server and all the required packages, it does not start Apache by default, you need to edit /etc/default/apache2 and change NO_START to 0, then run /etc/init.d/apache2 start to get the basic web server running.

When you build Subversion from source, it requires the apxs2 tool to be able to build and install the Subversion extension modules. This is hidden away in the apache2-threaded-dev package, it's not available in any other package:

apt-get install apache2-threaded-dev

Now we need to download, build and install Subversion. Download Subversion 1.2.1 and save it in /usr/local/src

Unpack Subversion:

tar zxvf subversion-1.2.1.tar.gz
cd subversion-1.2.1

We now need to ensure that all build dependencies are taken care of, plus let the build scripts know where the apxs2 tool is located (it's in a non-standard place with Debian):

./configure --with-apxs=/usr/bin/apxs2

Build Subversion:

make

Run the unit tests to ensure that the built version is a valid release (note: this can take quite a while - well at least it does on my poor Celeron Linux server!):

make check

Install the Subversion binaries and libraries to the correct places:

make install

OK, that's Subversion installed, but it's not available yet, we still need to config access to it via Apache, and create the initial code repository. Please see my next post on how to do this...

Technorati Tags: , , ,

Mr. IT Conversations (Doug Kaye) discovers my podcast post

Just took a quick look through my StatCounter logs, and found a strange link from Google Groups pointing at my recent post about the podcasts that I listen to. I followed it through to find Mr. IT Conversations himself, Doug Kaye, thanking me for my review:

"There are new blog postings like this one *literally* every day, but I particularly liked what Andrew had to say"

Cheers for the kind words Doug!

Technorati Tags: , , , , ,

A list of the podcasts that I subscribe and listen to

Peter Cooper asked a few days ago about what podcasts people are subscribing to. Here's my list:

IT Conversations
IT Conversations got me into podcasting, it's the original and the best for anything to do with technology. They have loads in interesting recordings, the best ones for me are recordings of presentations given at conferences like eTech and Web2.0. If I could only subscribe to one podcast it would have to be this one.
http://www.itconversations.com/index.html

For Immediate Release: The Hobson and Holtz Report
Neville Hobson and Shel Holtz are two communication professionals who discuss public relations, corporate communications and how that intersects with technology in a twice-weekly show, each show is about 1 hour in length. They normally discuss what's happening in the blog and podcasting worlds including any new tools or sites that are of use in tracking what is going on. Shel and Neville get some great banter going and so this podcast is one of my favourites.
http://forimmediaterelease.biz/

Lee Hopkins' Better Communication Results
A short weekly podcast by Lee discussing communication issues and how you can improve your communication results. Lee has a very entertaining style and his podcasts are always a pleasure to listen to.
http://www.hopkins-business-communication-training.com/communications_mp3s.html

Gillmor Gang
The Gillmor Gang has been podcasting for quite a while, they were originally hosted as part of IT Conversations but have now moved off into their own 'space'. They are five industry experts who have been around the block a few times discussing recent technology issues (e.g. Apple/Intel, Gnomedex, RSS, Attention). They normally have some good disagreement going, this extends the context of the item in question as you get a more balanced view.
http://gillmorgang.podshow.com/

Gillmor Daily
Similar to the above Gillmor Gang, but hosted by Steve Gillmor and a guest or two.
http://gillmordaily.podshow.com/

LugRadio
A fortnightly show that looks at Linux and open source. It's hosted by four British guys, with lots of swearing and foul language. They normally interview a lead developer of an interesting open source project, and discuss various distros, applications, etc. I find it a pretty good, light-hearted look at the open source world.
http://www.lugradio.org/

Manager Tools
A weekly podcast on how to be a better manager. The two US hosts have a lot of managerial experience and give a very informative and educational show. They are upbeat presenters, and present real stuff that is actually useful. I have particularly enjoyed their most recent editions that covered how to host more effective meetings.
http://www.manager-tools.com/

Ruby on Rails
A podcast dedicated to providing information about Ruby on Rails. It covers new tools, modules, and tips & tricks for Rails, interviews with key players in the Rails world among other things. There has only been two of them so far so I'm not sure just how good or useful this one will be.
http://podcast.rubyonrails.org/

BayCHI
BayCHI is the San Francisco Bay Area chapter of the ACM Special Interest Group on Computer-Human Interaction (SIGCHI). They have a number of interesting recordings of lectures by industry experts in the web world including David Sifry of Technorati, Stewart Butterfield of Flickr, and Scott Berkun of ex-Microsoft.
http://www.baychi.org/podcast/

Agile Toolkit
I haven't listened to this one yet, but it's got a good list of recordings with various people from the agile world.
http://agiletoolkit.libsyn.com/

Please let me know if you have found this list useful, and if there are any that you are aware of that you think I would be interested in.

Technorati Tags: , , , , , , , , , , ,

Pretty printing Java classpaths using Ant's pathconvert task

Lance Hankins posted on Saturday about more readable classpaths using the <propertyregex> task. It jogged my memory back about 4 years when I was trying to solve the same problem. This was back in the days of Ant 1.4.1 and just before the existence of the optional Ant-Contrib package. Back then I was considered a bit of an Ant Meister by my colleagues as I managed to spend hours tweaking the smallest of things in my lovingly created Ant build environment searching for perfection...

So how did I solve this particular issue? A clue is in the title of this post, I used the <pathconvert> task, which is normally used to convert lists of files, directories, etc. and convert them to a different platform's style. So path separators using Windows ';' get converted to Unix ':', etc. But you can also use it to convert the path separators to something else, in my case a nicely formatted string for displaying in a printable form.

Here's the code:


<!-- get the source compile classpath in a printable form -->
<pathconvert pathsep="${line.separator}| |-- "
property="echo.path.compile"
refid="path.classpath.compile">
</pathconvert>

The original classpath is referenced in 'path.classpath.compile', and the newly formatted classpath is saved in 'echo.path.compile'. The magic is the pathsep statement. This says that the path separator (the ';' or ':') is to be replaced with a new line (CR or CRLF depending on operating system) followed by some characters that make the listing look nice.

To display your pretty printed classpath just use:

<echo message="|-- compile classpath"/>
<echo message="| |"/>
<echo message="| |-- ${echo.path.compile}"/>

This gives the following output:

[echo] |-- compile classpath
[echo] | |
[echo] | |-- /tomcat/common/lib/jsp-api.jar
[echo] | |-- /tomcat/common/lib/ant.jar
[echo] | |-- /tomcat/common/lib/jmx.jar
[echo] | |-- /tomcat/common/lib/commons-collections-3.1.jar
[echo] | |-- /tomcat/common/lib/commons-dbcp-1.2.1.jar
[echo] | |-- /tomcat/common/lib/commons-el.jar
[echo] | |-- /tomcat/common/lib/commons-lang-2.1.jar
[echo] | |-- /tomcat/common/lib/commons-pool-1.2.jar
[echo] | |-- /tomcat/common/lib/tools.jar
[echo] | |-- ...

So there you have it, nicely formatted classpaths using only standard Ant tasks.

Technorati Tags: , ,

Add fresh RSS content to your website with Feed Digest

Peter Cooper in the UK has just launched Feed Digest, the successor to the very popular RSS Digest.
It's a tool that allows you to put a section of HTML on your website which is powered by one or more RSS feeds so it means that your website is updated by these RSS feeds.

Here are a number of things you could do with it:

* Show the latest BBC news.
* Display your latest 10 del.icio.us bookmarks.
* Display your latest blog post in your home page.

I haven't thought of my use for this yet, If I add too much other data, the blog posts will disappear into a sea of links, but it's an interesting service none the less.

The other thing that is interesting about this service is that it's powered by Ruby on Rails. This is a Ruby-based web framework that I've been reading about lots but haven't got into yet. There are quite a few US-based sites that use it, but Peter's is the first UK one that I've heard about.

Technorati Tags: , , , ,