Jason Fox

Icon

programming, products, and pontifications…

24 Hours at the `Ring in 19,500 Frames

Tim Hahne reduces the 24 hour endurance race at the Nurburgring into just 19,500 frames. 13 beautiful minutes of Porsches, Ferraris, Audis, Aston Martins, BMWs and lots of German men wearing massive headphones.

Installing MySQL with the InnoDB Plugin

I found after installing MySQL 5.1 that the “fast index creation” feature is not utilized by the default InnoDB storage engine that comes with MySQL 5.1. This is the main reason why I went through the trouble of installing MySQL 5.1 in the first place. :-/ However, have no fear, the InnoDB plugin is here! (ok, that was lame, anyways…)

The InnoDB plugin is a replacement InnoDB storage engine developed with the help of Sun, Google and Percona. It supposedly provides better overall performance compared with the default InnoDB storage engine that comes with MySQL and it adds a few new features that I want such as “fast index creation.”

If you’d like to try out the InnoDB plugin you’ll have to recompile MySQL as a pre-compiled binary drop-in is not provided yet for OSX. So, here are the steps for compiling and installing MySQL 5.1 with the InnoDB plugin while maintaining a working MySQL 5.0 installation on your computer.

  1. Download the MySQL 5.1 source distribution (v.5.1.43 for me; Change Platform to: Source Code; Scroll down to the last distribution: Generic Linux (Architecture Independent))
  2. Download the InnoDB plugin source distribution (v.1.0.6 for me)
  3. Create a new install directory for MySQL 5.1: sudo mkdir /usr/local/mysql-5.1.43
  4. Change ownership of the install directory to the mysql user: sudo chown -R mysql /usr/local/mysql-5.1.43
  5. Extract the MySQL source: tar -zxf mysql-5.1.43.tar.gz
  6. Extract the InnoDB plugin source: tar -zxf innodb-1.0.6.tar.gz
  7. Change into the MySQL source directory for storage engines: cd mysql-5.1.37/storage
  8. Remove the version of the InnoDB plugin that MySQL comes with: rm -fr innobase
  9. Replace the InnoDB plugin with the one you downloaded: mv innodb-1.0.6 innobase
  10. Change into the MySQL source root: cd ..
  11. Create the make file: ./configure --prefix=/usr/local/mysql-5.1.43 --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=innobase --without-plugin-innodb_plugin --with-federated-storage-engine; note, I’m also including the Federated Storage Engine here in case you find a use for it in the future; NOTE: You will receive the following warning, however, IT DID WORK, so just ignore it:
    configure: WARNING: unrecognized options: --without-plugin-innodb_plugin, --with-federated-storage-engine
  12. Compile MySQL: make; takes about 10 minutes or so
  13. Install MySQL: sudo make install
  14. Change into your install directory: cd /usr/local/mysql-5.1.43
  15. Create the MySQL database: sudo ./bin/mysql_install_db --user=mysql
  16. Change ownership of the var directory to the mysql user: sudo chown -R mysql ./var

For more information see…

If you get stuck you can check out the following resources that I used to complete this process:

Installing Apache2 with SSL Support on Mac OS X

Here are the steps for installing Apache2 with SSL support on your local development machine. Several of our applications require HTTPS for certain actions and I’ve been bitten in the past by not testing this in development. So, here’s how to get Apache up and running with SSL.

Compiling and Installing Apache

  1. Download the latest source distribution (v2.2.15 for me) from: http://httpd.apache.org
  2. Extract the source: tar -xvf httpd-2.2.15.tar.gz
  3. Create an install directory (I put it in /usr/local): sudo makedir /usr/local/apache2
  4. Configure the makefile with the following options: ./configure --prefix=/usr/local/apache2 --enable-ssl --enable-setenvif --enable-proxy --enable-headers
  5. Compile the source code: make
  6. Install apache: sudo make install
  7. Create your self-signed SSL keys by following this tutorial: http://developer.apple.com/internet/serverside/modssl.html
    • Scroll down to the Configuring SSL section and start from there
    • You will need to download mod_ssl to get the sign.sh script mentioned in the tutorial but that’s all you need it for. You’ll notice the mod_ssl site says it’s only for Apache 1.3.X. That is because Apache2 has built in SSL support which we enabled in the makefile configuration above so mod_ssl is no longer needed.
  8. Edit your httpd.conf file: sudo vi /usr/local/apache2/conf/httpd.conf
  9. Add the following configuration to the bottom of the file to proxy all HTTP and HTTPS requests to port 3000, i.e., Rails:
    • This assumes Rails is running on port 3000 on your machine
    • This assumes you put the SSL keys where the tutorial told you to
    • The last tag might already be in your httpd.conf file, if so, no need to repeat it here
      # Apache needs to know you want to accept connections over HTTPS
      Listen 443
      
      SSLCertificateFile /etc/httpd/ssl.key/server.crt
      SSLCertificateKeyFile /etc/httpd/ssl.key/server.key
      
      # Below is optional, but was helpful to me in debugging this setup
      CustomLog logs/ssl_request_log  "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" 
      
      <VirtualHost *:80>
          ServerName localhost
          ServerAlias 127.0.0.1
      
          ProxyPass / <a href="http://localhost:3000/">http://localhost:3000/</a>
          ProxyPassReverse / <a href="http://localhost:3000">http://localhost:3000</a>
          ProxyPreserveHost on
      
      <VirtualHost *:443>
          SSLEngine On
          ServerName localhost
          ServerAlias 127.0.0.1
      
          ProxyPass / <a href="http://localhost:3000/">http://localhost:3000/</a>
          ProxyPassReverse / <a href="http://localhost:3000">http://localhost:3000</a>
          ProxyPreserveHost on
          RequestHeader set X_FORWARDED_PROTO 'https'
      
      <ifmodule ssl_module>
          SSLRandomSeed startup builtin
          SSLRandomSeed connect builtin
      </ifmodule>
      

Auto-starting Apache

If you’d like to have apache start automatically whenever your computer starts do the following:

  1. Create a new plist file for apache with a unique name: sudo vi /Library/LaunchDaemons/org.apache.httpd
  2. Put the following in the file (assuming you installed apache in /usr/local/apache2):
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <dict>
            <key>KeepAlive</key>
            <true />
            <key>Label</key>
            <string>org.apache.httpd</string>
            <key>ProgramArguments</key>
            <array>
                <string>/usr/local/apache2/bin/apachectl</string>
                <string>start</string>
            </array>
            <key>RunAtLoad</key>
            <true />
            <key>UserName</key>
            <string>root</string>
            <key>WorkingDirectory</key>
            <string>/usr/local/apache2</string>
        </dict>
    </plist>
    
  3. Test it out with launchd: sudo launchctl load -w /Library/LaunchDaemons/org.apache.httpd; You should see several instances of httpd running if you do a: ps aux | grep httpd

Testing it out

  1. Fire up Rails on whatever port you are forwarding your HTTP/HTTPS requests to
  2. Request an action with HTTP
  3. Request an action with HTTPS

Possible Problems

I encountered the following cryptic error in FireFox when I was testing out an Apache install on a second dev box:

SEC_ERROR_REUSED_ISSUER_AND_SERIAL

I found out by reading through some forums that each SSL certificate needs to have a unique serial number. Since I had followed the above procedure to install Apache and SSL on both my laptop and the second dev box I already had a certificate with the same serial number stored in my browser (for my local machine) as the one on the second dev box. If you follow the above process the serial number of your certificate will be 01. So to fix this do the following on your new certificate (for me it was the one on the dev box):

sudo openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 02 -out server.crt

This simply assigns 02 to the second certificate and keeps FireFox happy. You probably will not encounter this problem unless you are testing SSL on multiple machines like I was but I figured I’d mention it anyways. Note, you can see the serial number of a certificate in FireFox by going to:

Firefox > Preferences > Advanced > View Certificates (button)

Then double click on a certificate of interest. Also note that Chrome did not complain about this but FireFox won’t even let you visit a site with a duplicate serial number.

If you get stuck…

Try one of the following resources that I used to get this up and running:

Installiing and Running MySQL 5.1 and MySQL 5.0 simultaneously on Mac OS X

I am writing a few new applications and decided to upgrade to MySQL 5.1 from MySQL 5.0.  However, I have several legacy applications that still require MySQL 5.0.  So, I set out to get them both up and running side-by-side so I could forge a new path forward to 5.1 while not abandoning my 5.0 apps.

Installing MySQL 5.1

  1. Download the source distribution of the latest 5.1 (for me it was 5.1.42)
  2. Decompress it and extract it into a directory
  3. Create a new home for the 5.1 files, I put it in /usr/local/mysql-5.1.42
  4. Next cd into the directory where you extracted the files
  5. Run the following command substituting your install directory created in step 3 above: ./configure --prefix=/usr/local/mysql-5.1.42 --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=innobase
  6. Compile the code by running: make; this will take a few minutes (10ish?)
  7. Install into your chosen directory with: sudo make install
  8. Next cd into your install directory: cd /usr/local/mysql-5.1.42
  9. Create the mysql database with: sudo ./bin/mysql_install_db --user=mysql
  10. Change ownership of the var directory (this is the data directory): sudo chown -R mysql ./var
  11. Change ownership of the install directory: sudo chown -R mysql /usr/local/mysql-5.1.42
  12. Create a socket file in your install directory: sudo -u mysql touch mysql.sock; mysql may create this itself on start-up, but, I created it ahead of time
  13. Start the server: sudo -u mysql ./libexec/mysqld --basedir=/usr/local/mysql-5.1.42 --port=6666 --socket=/usr/local/mysql-5.1.42/mysql.sock --user=mysql

Running MySQL 5.1 and 5.0

  1. Edit your my.cnf file and explicitly add: socket=/tmp/mysql.socket; if you do not do this when you start the 5.1 server the socket will be deleted
  2. Create a new my.cnf file in your 5.1 installation root; for me: */usr/local/mysql-5.1.42/; your my.cnf file should look like this:
        [mysqld]
        basedir=/usr/local/mysql-5.1.42/
        port=6666
        socket=/tmp/mysql.5.1.socket
        user=mysql
    
  3. Change ownership of the my.cnf file to the mysql user: sudo chown -R mysql my.cnf
  4. Create a plist file for launchd called something like: com.mysql.mysqld.5.1.plist in /Library/LaunchDaemons; your plist file should look like this:
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
            <dict>
                <key>KeepAlive</key>
                <true />
                <key>Label</key>
                <string>com.mysql.mysqld.5.1</string>
                <key>ProgramArguments</key>
                <array>
                    <string>/usr/local/mysql-5.1.42/bin/mysqld_safe</string>
                    <string>--defaults-file=/usr/local/mysql-5.1.42/my.cnf</string>
                </array>
                <key>RunAtLoad</key>
                <true />
                <key>UserName</key>
                <string>mysql</string>
                <key>WorkingDirectory</key>
                <string>/usr/local/mysql-5.1.42</string>
            </dict>
        </plist>
    
  5. Change ownership of the plist file to root like so: sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.5.1.plist
  6. Test it out by launching mysql: sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.5.1.plist; The next time you start up both MySQL 5.0 and 5.1 should be started up. Check the /tmp directory after start-up to ensure both sockets were created successfully.

A few notes about this process

  • When you install from source the layout of the installation is different than when you install from the binary distribution, i.e., the data direectory is var not data and the server binary is in libexec not bin, etc. For more information check out this article.
  • When starting a second instance of mysqld you must specify different values for the following options: port, socket, pid-file, tmpdir, datadir. However, if you specify the basedir you only need to explicitly set values for socket and port as we did in the last step above. For more information check out this article.
  • When you start the mysql client you must specify the socket and port like so: /usr/local/mysql-5.1.42/bin/mysql -P 6666 -S /usr/local/mysql-5.1.42/mysql.sock -u root; Alternatively you can create a hidden .my.cnf file in your home directory and specify which server should be connected to by default when you run the mysql client. Your .my.cnf file should look like this:
        [client]
        port=6666
        socket=/tmp/mysql.5.1.socket
    

Working with Rails

Now that you have two MySQL servers running you need to tell Rails which one you want to use in a more explicit fashion. Here’s an example from my database.yml file:
    # Main database connection for the media_service;
    # Uses MySQL 5.1
    development:
      adapter: mysql
      encoding: utf8
      database: my_development
      username: foo
      password: bar
      socket: /tmp/mysql.5.1.socket
      port: 6666

The iPad is the Wii of Computing

the_ipad_is_the_wii_of_computing

I think the geeks have it wrong.  The iPad is a revolutionary device and a game changing one at that.  I believe that the iPad is to computing what the Nintendo Wii is to video gaming.  While it may not have the most amazing graphics, the most powerful CPU (though it just might), the most storage or even all of the features that we want such as multitasking, it does not matter.  I repeat, it does not matter, just as it did not matter for the Wii.

The Nintendo Wii is really just a GameCube in different packaging just like the iPad is just an iPod Touch in bigger packaging.   The “magic” of the Wii is not it’s amazing technical specifications like say the Sony Playation 3.  No, the real magic of the Wii is in its ability to change the way that the game is played; literally and figuratively.

The Wii is appealing because anyone can play the games, old, young, veteran video gamers or newcomers and have fun playing them.  The Wii removes the requirement of being a video gamer to play video games.  There’s no need to master impossible sequences of key presses just to be able to challenge your friend to a game of tennis.  Instead you just pick up the controller and play; it requires no instruction and therefore lowers the barriers to video gaming.  The iPad does the same thing for computing.

The iPad is the first “computer” that I would consider buying my mom (actually the Litl Webook was the first, however, it is now surely doomed).  The trick of the iPad is that it removes the “computer-y” things from the computer.  This one aspect of the iPad is the key thing that absolutely makes it a revolutionary device irrespective of it’s technical specifications or naive feature set.  The iPad allows anyone young, old, tech savvy or not to be able to intuitively use a computer for the first time in history.  This to me is why the iPad is a game changer and is one reason why the iPad will not be a flop.

The iPad is a harbinger of things to come in computing, specifically in human-computer interaction models and I, for one, welcome it.

Wireless Audio Streaming with Apple’s Airport Express, Airfoil and VLC

Streaming audio with Apple’s Airport express is seamless and simple.  You plug in the Airport Express into the wall, plug in the audio cables (NOT INCLUDED) to your stereo and off you go.  However, if you want to watch movies on your computer and enjoy the same wireless audio you get with iTunes, things get a bit more complicated.

First off, Apple’s Airtunes protocol apparently has a built in 2-ish second delay before it starts playing the audio you’ve summoned up.  That’s not a problem if you’re listening to music, but, if your audio is paired with some video the result is unsycnhronized viewing.  More importantly, though, is the fact that iTunes only let’s you stream music to the Airport Express.  What about that pirated copy of Paranormal Activity you just downloaded from bit torrent?  Fear not, there is a solution.

First you need to get a nice little app called Airfoil.  Airfoil allows you to stream ANY audio from any application to your Airport Express.  Wow, perfect!  Well, hold on a second, let’s return to that little issue with Apple’s Airtunes protocol before you plop down your $25 for a license (you were going to BUY a license, weren’t you?).

The problem again is that any audio you play over the air with your Airport Express will be delayed about 2 seconds.  This means that your audio will lag behind your video.  Booooo… Ok, so, let’s just delay the video a bit so that the audio has time to catch up!  Simple solution, right?  Yes and no.

Desynchronization of audio and video will work in video players like VLC.  VLC makes desynchronization of audio and vidoe really, really simple.  In fact, you can change the sychronization settings on the fly by pressing the “f” and “g” keys.  I found a post that explains it all.  (Note that his instructions are for an older version of VLC.  However, the instructions are the same except that in the new one you select the “All” radio button in the bottom left hand corner of the preferences pane instead of the “Advanced” checkbox to access VLC’s full array of settings.  Also I found -2100 to be a better delay for me.)

Unfortunately there is no solution that I know of for synchronizing internet video like Hulu.com with the delayed audio of the Airport Express.  That’s a bit of a let down as Hulu.com is really the only way I watch “television” these days (It’s not exactly television if I watch it on my computer, now is it? I’m really “watching computer”.  Oh what will we do when the mediums we’re used to are no more?  How will we know what to call things anymore? Will a newspaper still be called a newspaper if we read it on Apple tablet or will it be a newstablet?)  If anyone knows of a solution please let me know.

In conclusion, a combination of Apple’s Airport Express, Airfoil and VLC allow you to cut the cords and enjoy audio on your stereo wirelessly, however, it’s not without faults and frustrations and some big exceptions (read: no Hulu.com). Oh, I should mention that Airfoil does ship with its own video player that handles the audio desyncrhonization for you.  I however was unable to get it to play several of my videos.

killall Dock – the most awesome command in the world

Ever have Expose freeze up on you? Command-TAB stops working, Spaces stops working, the Dock stops working, show desktop stops working, show windows stops working; you’re trapped!  Well, if you happen to have a terminal window open or can launch one, fear not!  Simply issue the following command (make sure to use a capital ‘D’) and you’re golden.  No restart required!

$ killall Dock

Share and enjoy!

Backgroundjob (Bj) Won’t Start

Recently I had a problem with Bj where it would not start up.  Nothing was written to the backgroundjob log or Rails log and no exception was being thrown.  To make the problem even stranger, Bj would start-up just fine in development but not in production but worked just fine in production from script/console.  After digging into the Bj code and adding some debug statements I found the problem.

# database.yml
development:
  adapter: mysql
  database: my_development
  username: me
  password: password
  host: localhost
  port: 3306

test:
  adapter: mysql
  database: my_test
  username: me
  password: password
  host: localhost
  port: 3306

production:
  development

Bj was getting an ActiveRecord::ConnectionNotEstablished exception but was swallowing it.  The solution was to explicitly define the production database connection in database.yml.

Disk Utility: “File system formatter failed.”

If you receive the “File system formatter failed” error message while trying to partition a large hard drive using Disk Utility in OSX you need to change the partition type to GUID.  Click the Options… button at the bottom of the partition list and select the GUID Partition Table:

screen-capture-12

Iomega Prestiege 1TB Review – First Impressions

iomega_prestiege

Just got my two Iomega Prestiege 1TB hard drives from Amazon ($104/each) to support my new backup strategy (more on that later).  First impressions: PROS: Very quiet, very solid feeling construction, CONS: Activity light placement forces you to put it to the left of you, the color is not at all like the picture; the drive is more of a gun metal, putty grey than a shiny silver aluminum like the MacBook Pro.  Oh well, all I ask is that it will last longer than my Western Digital MyBook.

About

Jason Fox is the Co-Founder of Initiate Commerce, Inc. and the Head of Technology and Development at readMedia, Inc. Jason has over 10 years experience designing and building scalable, internet-based, applications for start-up companies both large and small.

Twitter

    github.com/jfoxny

    • No feed items.

    Recent Wines

    View Jason Fox's profile on LinkedIn
    Jason Fox's Facebook profile