Archive for February, 2009

Open… EULAs?

Facebook has taken all of about a week to come up with a new “governing document” for guiding the creation of its future EULAs through some kind of community-driven process, acccording to CNET News:

The thrust of the new plan is that future changes in the Facebook agreements with users will be put up for open debate in a process of “notice and comment.” The forum will be open to all Facebook users. If Facebook proposes a modification to a term of service that is uncontroversial or has limited feedback, it will get incorporated into the user agreement after a stated period of time. But if there’s argument or division over a proposed change, users will be able to debate them and ultimately vote on updates to the Facebook agreements.

Wait a second… online communities? Voice of the people in the creation of a defined user-powered space? I’m feeling some deja vu here. Better keep reading:

Zuckerberg also made it clear that the new governance applied only to fundamental issues of privacy and data ownership, and not the Facebook product itself: “There will be hundreds and thousands of product changes going forward, and that’s not what we’re talking about. This is about the rules and framework.”

Ah. Ok. that was it – I was thinking about openness in general. His whole use of the word “open” just sent me down this road of thinking about openness of data and openness of software. I started to actually imagine a day when I might consider uploading some of my pictures to Facebook instead of Flickr and MobileMe and JungleDisk. But then that came crashing down when I realized how much smarter FB really is than the whole general macro trend of data ownership over the last quarter century.

The process of deciding how FB gets to keep and use your data is what you’ll get some buy-in on now, kids! Yay! Don’t worry about ever actually getting to talk about having your data open – if FB wants you to have that, you’ll get that! “Just trust us”! Yay!

No worries on Zuckerberg actually, you know, getting it any time soon, I guess.

If this doesn’t make any sense at all, then take this as a thesis: the net is gearing up to become one big data mashup orgy. Standards like HTML 5 and products like Safari 4 and Flex and Chrome and Google Site Creator are going to punch massive holes in the garden walls of places like Facebook over the next three years or so, rendering all their attempts at locking-in user data absolutely laughable. Before you know it, we’ll be passing around self-signed data stores as business cards, looking at browser-created custom mashups of information, and using Twitter to comb interesting and titillating information out of the cloud. Sure nerds do this already, but I’m talking about everyone else – that will just be how the internet is. Might we still use Facebook for social graph management? Sure – but only if it doesn’t insist on being the center of our universe. Stick that in your EULA, Mark!

Tags:

Kill tooltips/keep captions in Lightbox

Using Lightbox? Me too. The version I’ve been working with lately is the jQuery-based one by Krewenki. It’s a handy little plugin and seems to have all the basic stuff that you know and love from the older script.aculo.us-based Lightbox.

If you use Lightbox much, you’ll know that you add captions to the large version of your photo by placing the caption information in the title attribute of the link tag you wrap around the thumbnail image. If you want to get fancy with your captions like I did, you’ll want to put some HTML in the title attribute – maybe a title and an unordered list for some bullet points.

But when you hover the thumbnail, you see a nasty-looking tooltip filled with raw HTML. It took me some time to figure out the best way to get rid of the tooltip on hover but replace it in time for the larger version of the picture to be able to see it for the caption. Making the tooltip disappear was trivial, but replacing it turned out to be a bit tricky – each time I clicked, I kept getting blank captions.

Turns out that this is because I was attaching to the onclick event. Onclick fires when both mousedown and mouseup have happened, so the callback happens too late – the link is already loading. When I switched my title replacement event to be mousedown, the caption showed up just fine.

The jQuery snippet below blanks the title attribute on all Lightbox thumbnail links when the cursor enters the link’s space (defined by the dimensions of the thumbnail image) in the mouseenter event, and then replaces it on either mouseleave or mousedown. This injects the title back into the DOM in time for the caption to be used by Lightbox.

At least that’s my theory for why it works. I should probably find some technical backup for this somewhere in the annals of JavaScript, but being as that’s pretty unlikely, I’ll just go ahead and post the working code. Note that unlike some versions of Lightbox out there, Krewenki’s works by having you designate Lightbox elements by placing a “lightbox” class on the anchor, as opposed to setting the anchor’s rel attribute. It could be argued that this is slightly out of spec with how HTML is supposed to work, but it’s a pretty esoteric thing to compare link “relationship” designators with the appropriate semantic space for classes. And anyway, I don’t really care that much… :-p

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Removes title attr on Lightbox thumbnail links
// replaces for caption on mousedown
function killLightboxTooltips () {
  $.each($('.lightbox'), function(i, link) {
    var title = $(link).attr('title');
    $(link).bind("mouseleave mousedown", function () {
      $(this).attr('title', title);
    });
   
    $(link).bind("mouseenter", function () {
      $(this).attr('title', "");
    });
  });
}

Tags:

Installing Rails on CentOS 5

Note: Since this post originally went up, some of the packages have changed/updated. I’ve kept things pretty well up-to-date, but you might want to double check the latest versions and alter the bash commands accordingly. Be aware that as of this writing, the Ruby team has made 1.9.1 the latest stable and only Rails itself is deemed compatible with Ruby 1.9x. I.e., Rails passes all its own tests on 1.9.1, but most plugins, libraries, etc are likely to give you problems right now. So your best bet is to use 1.8.7 for awhile until your favorite libraries jump on board the 1.9 wagon.       –Trevor (August 17, 2009)

I recently had to roll a new VM for work in order to run Rails and Sinatra apps on Apache/Passenger. My company favors CentOS as the default distro for all our boxes, so I wasn’t able to use all the super-up-to-date packages that Ubuntu makes available, and I ended up building everything from source. For posterity and for anyone else who needs it, here’s a list of what to do and how to do it.

Dependencies

You’ll need several libraries and the MySQL server, and you can use yum to install them all at once. This set includes the gcc compiler, the gcc-c++ compiler, and the zlib development headers for Ruby. Remember: not all libraries are the same — you’re going to need to make sure that you’re compiling Ruby w/ 32 or 64-bit development headers as appropriate for your architecture.

1
2
3
4
5
6
7
8
9
10
sudo yum install httpd-devel\
  openssl-devel\
  zlib-devel\
  gcc\
  gcc-c++\
  curl-devel\
  expat-devel\
  gettext-devel\
  mysql-server\
  mysql-devel

Ruby

Next up is Ruby. We’ll install 1.8.7-p72, the latest stable as of this writing. First, we’ll make a “src” directory in /usr/local to hold everything:

1
2
3
4
5
6
7
8
sudo mkdir /usr/local/src
  cd /usr/local/src
  sudo curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
  sudo tar xzvf ruby-1.8.7-p72.tar.gz
  cd ruby-1.8.7-p72
  sudo ./configure --enable-shared --enable-pthread
  sudo make
  sudo make install

Ok now for a weird thing — you need to remake and re-install Ruby after using it to run a script that helps you make a new makefile. This is so that you can tell it where the zlib headers live:

1
2
3
4
5
cd ext/zlib
  ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
  cd ../../
  sudo make
  sudo make install

After all that happens, you should have Ruby installed. Check and see by doing:

1
ruby --version

You should see something like:

1
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

Rubygems

Now that you have Ruby installed, Rubygems is easy — the whole thing is in Ruby so there’s nothing to build/compile.

1
2
3
4
5
cd /usr/local/src
  sudo wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
  sudo tar xzvf rubygems-1.3.5.tgz
  cd rubygems-1.3.5
  sudo ruby setup.rb

Rails, Passenger, MySQL and Sinatra

Now that Ruby and Rubygems are installed, you can install Rails, Passenger, and Sinatra as gems:

1
sudo gem install rails passenger sinatra

That will take awhile, as there’s a ton of documentation to build for Rails, and Passenger has to compile some native extensions.

Once that’s done, finish the Passenger installation with their nifty installer tool:

1
sudo passenger-install-apache2-module

Follow the provided instructions at the end of the installer for adding lines to httpd.conf:

1
2
3
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /usr/local/bin/ruby

After that, install the MySQL gem, making sure to specify where the config is:

1
sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

Disabling SELinux

The RedHat family of distros (RHEL, CentOS, Fedora) come with SELinux enabled by default. If you want to learn how to make it work with Passenger, you can try this tip from the Passenger user’s guide. I just turned it off because the box is only going to be used for these apps, and SELinux seems like overkill. Here’s how to shut it down:

First, disable it temporarily:

1
sudo echo 0 >/selinux/enforce

That’s not a permanent fix though, because the next time the server boots, it’ll be turned back on again. You need to edit the config file and turn it off. Open it with your favorite editor and change one line. You need to be root or running as sudo to edit this file, and I prefer Vim when on remote servers, so it’s:

1
sudo vim /etc/sysconfig/selinux

Change this:

1
SELINUX=enforcing

to this:

1
SELINUX=disabled

Restart Apache

You should be able to restart Apache now and have Passenger come up no problem. There are several ways to restart Apache, but I like to use the service way to keep it simple:

1
sudo /sbin/service httpd restart

Optional: Installing Git

For SCM, there are a lot of reasons why I like Git better than Subversion. It’s got a bit of a learning curve, but once you go Git, you never go back.

1
2
3
4
5
6
cd /usr/local/src
curl -O http://www.kernel.org/pub/software/scm/git/git-1.6.0.4.tar.gz
tar zxf git-1.6.0.4.tar.gz
cd git-1.6.0.4
sudo make all
sudo make install

And the man pages:

1
2
3
4
cd /usr/local/src
curl -O http://www.kernel.org/pub/software/scm/git/git-manpages-1.6.0.4.tar.gz
cd /usr/local/share/man
tar -zxf /usr/local/src/git-manpages-1.6.0.4.tar.gz

Now you should have Git installed and ready. Prove it:

1
git --version

You should see something like:

1
git version 1.6.0.4

And that’s it — you now have a full Ruby stack ready to go on CentOS 5. Much of this tutorial was adapted from the awesome Hivelogic post on installing the stack on OS X Leopard.