October 30, 2006

Things that bother me about Ruby

I'm getting past that initial infatuation stage with Ruby. At first, you love a new language. It seems so perfect, flawless. The creators are geniuses! You want to use it for everything, especially that pet project you've been meaning to get to. It would be so easy with [insert new language name here], she is so fantastic!

As with any relationship, it's important to communicate with your partner about flaws you see in each other.

OK, Ruby, you know I love you, but here are some things that really bother me:

1. The community web infrastructure stinks. A very large percentage of the time, when I need to go check online doc or whatever for Ruby, the ruby site is down. And, when it's not down, it's S-L-O-W.

2. Ruby is slow. Face it. It is. If you have anything computationally intensive to do, forget it. And don't tell me to implement those things in C and make Ruby wrappers for them. If I wanted to go back to 1991 and write in C (those were good times, C, we're still friends, right?), I would do that. There's no justifiable reason by an interpreted languages should be so slow in straight line execution. I know, programmer time is much more valuable than CPU time, but when you eventually scale to needing several hundred machines or so, it's not true anymore. Price out hardware, rack space, power and cooling for 200 servers and think about how much programmer time you could buy for that.

3. The online doc needs a lot of work. While there are some great tutorials (e.g. from why the lucky stiff), the online reference doc is weird (four-part scrolling frames? ew.) and incomplete. This one will take the most time to work itself out.

4. The cult of 37signals and rails. I like rails; it's once of the nicest web app development frameworks I've seen. And I really like the software that 37signals has created. Those guys are smart programmers and designers, and I would hire them if given the chance. But there's a certain arrogance/contrived wisdom building up there. At work, we've actually had people comment on our UI in some (generally clueless) way, and cite 37signals philosophy as backing them up. Now, I wouldn't say that everything we do on our product is the greatest UI or idea. In fact, our development process and philosophy is very similar to that espoused by the "Getting Real"™ crowd. My annoyance stems from the fact that "you should be like 37signals" becomes a euphamism for "i don't like your UI."

I'm just old and cranky.

Posted by billo at 03:44 PM | Comments (0)

September 19, 2006

DIY SMART disk reporter.

Most (all?) SATA drives have self-diagnostics that report hardware problems. There are a number of freeware utilities available to monitor your disks for problems via this feature.

Here is a do-it-yourself SMART reporter. First create this script, and name it bin/macmaint or something.

#! /bin/sh
email=[email protected]
host=`hostname`

diskstatus=`/usr/sbin/diskutil info disk0 | grep SMART | awk '{print $3}'`

#debug
#echo $diskstatus

if test "$diskstatus" == "Verified"; then
    #echo "disk ok"
    /usr/bin/true
else
    #echo "disk very bad"
    /usr/sbin/diskutil info disk0 | mail -s "Disk problem on $host" $email
fi

Next, add it to your crontab, like this.

% crontab -e

05 * * * * bin/macmaint

This will run once/hour, and email if anything goes wrong.

Posted by billo at 09:43 AM | Comments (0)

September 13, 2006

RRDtool is way cool

A while back I mentioned that I was looking into RRDtool as an alternative to gnu plot.

Well, I did and it is very nice. It took about a full day of hacking to fully understand the concepts behind the tool and get it working the way I wanted. But still it is much easier to work with [than gnuplot --ed] when it comes to time-sampled data. I was able to churn out a nice monitor, and I even made a konfabulator/yahoo widget out of the
resulting jpg file:

Screenshot 53

Posted by billo at 03:04 PM | Comments (0)

August 30, 2006

Inscrutable Java Warning

In my eclipse environment, I get warning like this. I never remember the point of them, and whether I should worry:

Type safety: The cast from Object to ArrayList<String> is actually checking 
against the erased type ArrayList.

I found this nice, concise description here:

The compiler is warning you that the cast you are doing is only ensuring the Object is an ArrayList. It can't tell if it truly is an ArrayList<String>. If it isn't, on your head be it. If it is not really an ArrayList< String> expect a ClassCastException as soon as you do a get, even though there are no explicit casts near the get in your code. The problem in essense is that serialised objects contain no record of their generic type. Many think that design decision was a big mistake.

Ugh.

Posted by billo at 06:35 PM | Comments (0)

August 29, 2006

Tips for installing Ruby mysql module in OS X Tiger

I got my new machine and my ruby installation was pretty broken. The ruby that comes with Mac OS X is hopelessly out-of-date, and I had forgotten the things to do to get it to work.

Hand-building ruby from source to get to 1.8.4 is the first thing to do. Then I move the /usr/bin/ruby that comes with mac out of the way and create a symlink to /usr/local/bin/ruby, and ditto for /usr/lib/ruby (symlink to /usr/local/lib/ruby). That way I'm not going to get confused and launch the wrong ruby.

Then, you need to install the Ruby mysql module. I guess I'm a mysql bigot, but don't most people use mysql? I know that there are lots of choices out there, but mysql is what most people use, just for fooling around with stuff at least. Seriously.

To build ruby mysql, follow the instructions at the tmtm.org. In particular, you want to make sure that the configurator can find your mysql includes and libs, e.g.:

% ruby extconf.rb --with-mysql-dir=/usr/local/mysql

Posted by billo at 11:37 AM | Comments (0)

August 08, 2006

set emacs coding system

Every now and then I try to create a new XML file in emacs. It's something I don't do that much, because I hate XML. Hate it. But that's a rant for another day.

The problem I run into is that when you make a new buffer in emacs, it sets the default encoding scheme to iso-latin-1. And, of course, XML is (by definition) utf-8. Emacs tries to be all helpful and says "hey billo you idiot, iso-latin-1 is wrong. change it." Naturally, it doesn't tell me how to change it. So I always waste time trying to remember how to fix the encoding. Since I can't remember anything, I'm writing this note so I can waste less time in the future. I hope I remember I wrote this note.

The solution is:

M-x set-buffer-file-coding-system

Answer: utf-8

Posted by billo at 11:07 AM | Comments (1)

July 27, 2006

gdImageGifAnimAddPtr undefined problems trying to build perl GD

I had quite an unexpected amount of trouble installing the perl GD package on this server. First, I needed to install libgd-devel: the makefile generator didn't notice none of the includes were around. Then I kept getting an undefined symbol:

gdImageGifAnimAddPtr

when trying to load the GD.so during "make test"

The workaround was to disable support for animated GIFs in the configuration. My libgd version is 2.0.28, I guess that must be too old.

Posted by billo at 08:23 AM | Comments (2)

July 17, 2006

Note to self: RRDtool

We use gnuplot at work to make our custom one-off pretty graphs that monitor traffic:

Screenshot 37

It's kind of pain to use, I think largely because of it's history as an X11/postscript graphing tool. If you just want a PNG, it's not really the sweet spot. Gnuplot seems better suited to plotting equations than it does to reams of traffic data.

I noticed our Google mini uses
rrdtool; it looked a lot like gnuplot, so I'm looking into it further to see if it's easier to do little consoles like ours.

Update: needs freetype2 and libpng:

yum install libpng-devel
yum install freetype-devel

Posted by billo at 05:55 PM | Comments (0)

June 29, 2006

How to add mod_jk to apache on Mac OS X

The apache that ships with Mac OS X is still 1.3, not 2.0. Not that this matters, but it surprised me a little.

1. Download mod_jk from apache.org. I used 1.2.15, which is what we use on our Linux machines at work.

2. Compile mod_jk like this:

cd jakarta-tomcat-connectors-1.2.15-src/jk/native
./configure --with-apxs=/usr/sbin/apxs
cd apache-1.3
make -f Makefile.apxs
sudo cp mod_jk.so /usr/libexec/httpd

3. Edit /etc/httpd/httpd.conf:

#jk must be before rewrite
LoadModule jk_module libexec/httpd/mod_jk.so
LoadModule rewrite_module libexec/httpd/mod_rewrite.so
.
.
#jk must be before rewrite
AddModule mod_jk.c
AddModule mod_rewrite.c

4. Define your worker properties and jk mounts normally.

5. restart Apache:

/System/Library/StartupItems/Apache/Apache restart

Posted by billo at 11:53 AM | Comments (0)

May 15, 2006

memcached on Mac OS 10.4 slowness fix

We use memcached at work to vastly reduce load on the application servers and on mysql. The problem is that on Mac OS 10.4 Tiger it was so slow as to be worse than not using it: one query would take 5 seconds, instead of like 5 milliseconds on Linux. It was never a huge deal, because we deploy on Linux, and there are lots of Linux machines around the office. But it made it hard to run a self-contained deployment environment on the developer's Mac.

My friend Derek found this article, which details the fix. I tested it, and it works for me. Super short summary:

Edit memcached.c and add (anywhere above line 105, which reads #ifdef TCP_NOPUSH) the line:

#undef TCP_NOPUSH

Then


make install
setenv EVENT_NOKQUEUE 1
/usr/local/bin/memcached -m 128 -p 11211

Posted by billo at 05:00 PM | Comments (0)

May 03, 2006

Tamper Data, a cool FireFox plugin

When I debug web sites (something I'm sure everybody does, right?), I like tools that let me look at the HTTP headers and such. Too what cookies actually are set, etc. One tool I liked was the Live HTTP Headers FireFox extension. Jeff just showed me an even better one: Tamper Data. It basically does the same thing, but there are two big differences.

First, it's formatting of the data is vastly better: there is a table of entries for each request with performance and summary data. This lets you figure out where your pages are fat: like included images or js or whatever. Then you can click on each request to find out more.

Second, you can go into "tamper mode," where you can edit the requests coming from your browser before they get to the server. This can be very handy.

Posted by billo at 05:08 PM | Comments (0)

April 07, 2006

notes on building PHP 5 on a Fedora Core 3 system

I have a generally vanilla FC3 system. I wanted to update to PHP 5 because of security issues in PHP. These are the extra things I had to do to get it to work.

First, my configure line is this:

./configure --with-apxs2=/usr/sbin/apxs --with-mysql

Problems:

I had to make links for libjpeg and libpng:

cd /usr/lib
ln -s libjpeg.so.6 libjpeg.so
ln -s libpng.so.3 libpng.so

These are packages I needed to add:

yum -y install libpng-devel
yum -y install freetype-devel
yum -y install libc-client-devel
yum -y install unixODBC-devel
yum -y install aspell-devel

I actually had some trouble with postgresSQL connector, so I turned it off. I don't use it myself, so that doesn't really matter.

I tried to replicate the configure line from my php4. Big mistake. All I got were segfaults and link errors. I re-configured with the minimalist line above. Now everything is happy.

Posted by billo at 06:24 PM | Comments (0)

March 08, 2006

Dealing with accented character sets in MySQL

Here's something I learned about today. Suppose you have a table of city names, and some of them are really the same city, but with alternate spellings like Skovde and Skövde. How do you find them?

Check out this awesome query:

select city, id, count(id) as cnt from city 
  group by city collate utf8_general_ci 
  order by cnt;

Anything with a "cnt" column > 1 is probably a dup. Then you can look at the individual entries and figure out what to do. (In my case, I have an alias table that I merge the dups into.)

The key to this is that you can change the collation rules in the table on the fly, which will decide that o == ö, for example. You could do the same thing with latin1 or other character sets too.

Posted by billo at 12:36 PM | Comments (0)

March 03, 2006

TextMate is a good editor.

I've been an emacs user for 20 years. Gosh, that is scary. Every now and then I try to use a different, "modern" editor or IDE for a while. Visual Studio. Borland JBuilder. Eclipse. TPU. (ha! just kidding. I used TPU before I used emacs).

I always end up going back to emacs.

Since I've been experimenting with Ruby on Rails, I'm trying TextMate. It has emacs-ish basic bindings, so it's tolerable out of the gate. It has a nice, simple, but powerful extension mechanism, with a lot of pragmatic tools that cover all the languages I care about. It also has very nice Rails support, apparently because all the Railserati use it. Watch the video demo, and you might want to try it to.

So far, I've used it long enough to actually pay the shareware fee. I really like it. Let's see if I'm still using it in a month.

Posted by billo at 05:34 PM | Comments (0)

February 28, 2006

Nomination for most J-cliché web page of all time.

I'm actually not sure if this is a parody or if it's real.

http://www.jcorporate.com/html/products/productsfm.html

Posted by billo at 04:34 PM | Comments (0)

February 14, 2006

Why I hate Java, reason #347

Java:

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }

Ruby:

        sleep(1)

Posted by billo at 03:13 PM | Comments (0)

January 17, 2006

Ruby, Mac OS X, gems problem

I wanted to add the Ruby gem "termios" which allows setting properties on a TTY so you can to single-keystroke input processing. I found a nice recipe for this here, but I ran into problems with Gems. I could have sworn that it was working fine (and I was right, it turns out.)

The error I got was: "can't find ruby headers," and it turns out to be caused by the latest XCode Update which has universal binary support. The fix is pretty mundane; just some symlinks so the headers will be found in the default place:

cd /usr/lib/ruby/1.8/powerpc-darwin8.0
sudo ln -s ../universal-darwin8.0/* ./

Now gems is happy again. This is all in 10.4/Tiger, BTW.

Posted by billo at 01:52 PM | Comments (0)

August 10, 2005

My first Ruby CGI

This is a little script that could be written in Perl, or shell. But I wrote it in Ruby. If you put it on a web server, in a directory with a bunch of jpg files, it zips them up and returns them. I use it to pull down a bunch of photos from my web site to whatever photo editing software I happen to be using.

#! /usr/bin/ruby
require "cgi"

cgi = CGI.new

url = cgi.script_name
relativepath = ""

if url =~ %r{(.*)/photozip.cgi$}
  relativepath = $1
  if relativepath =~ /\.\./
    cgi.out() { "sorry" }
  end
end

basedir = '/someplace/on/server'
localpath = basedir + relativepath 

d = Dir.new(localpath)
hasjpeg = false;
d.each do |file|
  if file =~ /jpg$/
    hasjpeg = true
    break
  end
end

if hasjpeg
  if File.file?(localpath + "/allphotos.zip")
    cgi.out("status" => "302",
            "location" => "#{relativepath}/allphotos.zip")
    { "redirect" }
  else
    Dir.chdir(localpath)
    status = `/usr/local/java/bin/jar cf allphotos.zip *.jpg`
    cgi.out("status" => "302",
            "location" => "#{relativepath}/allphotos.zip")
    { "redirect" }
  end
else
    cgi.out() { "sorry, no jpegs here." }
end

Posted by billo at 08:58 AM | Comments (0)

August 05, 2005

Ruby

Ruby is a totally cool programming languages. It's almost as cool as lisp. I'm about two weeks into using it, and I suddenly am not thrilled about perl anymore.

Ruby manages to be practical and elegant at the same time. It allows you to write code that is terse, expressive and clear.

Posted by billo at 08:37 PM | Comments (0) | TrackBack

July 21, 2005

mkid-like hack for spotlight

If you ever used the "mkid" package for finding references to functions in source files, you might appreciate this. I've tried to get the mkid package to compile on Mac OS X, but with no luck. It doesn't work that great with java, anyway, and has fallen into serious neglect. I guess everyone uses fancy IDEs nowadays anyway.

In any case, spotlight has a command line interface called mdfind. Try this little trick in your emacs. First, visit a source file at the top of your source tree. Then do M-x compile and give this command:

mdfind -onlyin `pwd` "println" | xargs grep -n "println"

Substitute whatever function or class or method you want for "println." Then use M-x next-error to walk through all occurences. Add key bindings and macros and have some refactoring fun.

Posted by billo at 08:19 AM | Comments (1)

June 30, 2005

google maps API

The google maps API is now "official." I tried it out; it is incredibly easy to use. It took about 20 minutes for me to make a nice map on my wife's web site. I could do it again (now that I understand the API) in about 3 minutes.

There is one serious problem, and that is their API access key system. It is incredibly brittle, and can cause your maps to work on "www.example.com" and fail on "example.com." And randomly work or break on funny hosts like http://test.example.com:8080/.

Hopefully google will fix this soon or just disable the API key thing until they can.

Google Maps API

My sample map

Posted by billo at 01:27 PM | Comments (0)

June 29, 2005

Hoist by my own tools

I was always bothered by the behavior of velocity that on certain errors, it would throw a stack but no message. I finally got fed up and decided to track it down. It turned out to be not a bug with Velocity or Kayak, but rather a bug in the "logfilt" tool that I wrote to trim down log output. The regex to strip away the preamble stuff in [] was too hungry, and was eating the entire message when the velocity message had a ] on it. Bah! There is probably some trite lesson here, but I am too sleep deprived to articulate it.

Posted by billo at 04:13 PM | Comments (0)