Skip to content

Laundry List

I haven’t been updating, but I actually have been busy with a variety of programming tasks.  Here’s a list of my thoughts at the moment:

  • I’ve been doing a considerable amount of work with web video lately.  That means I’ve gotten intimate with the various players, encoding options, and media storage solutions.  And here’s what I now know that all you already did: shit is fragmented as fuck.  You wanna put a video on a web page, and have that video be accessible via all browsers, and on mobile devices? Good luck; it’s possible but you’ll need the same content encoded in at least three different formats.
  • Happily, Amazon S3 is working out really well.  The S3 ruby gem makes access from a rails site incredibly easy.
  • A little off-topic, but seriously fuck Apple for their ur-holding-it-wrong-no-wait-our-signal-strength-algorithm-was-fucked explanation.  I have always been of the opinion that my iPhone dropped calls were 3/4 AT&T’s ultra-shitty service and 1/4 iPhone design problems.  With this complete horseshit excuse I’m willing to push it to 50:50 blame here.
  • I am currently annoyed at Microsoft’s ISV developer support.
  • I’ve been putting in work on the open source ruby libraries used to connect to Intuit’s cloud platform.  It would be done already except ruby doesn’t currently support xml canonicalization (i.e., c14n) in any serious fashion.  Hopefully though, c14n support will be in the next minor release of nokogiri.  At that point I’ll be able to create a validating SAML gateway using ruby.  Swank.
  • I got all my web sites now running on a single hosting service (I had my main blog running at Joyent ever since early 2006).  Shout-outs to RimuHosting; they’re incredibly helpful and I like the VPS I get for the price.  And if perchance you sign-up with them holler my name/email address.

I really, really need a new skin for this site.  I’ve been trawling around themeforest.com and haven’t seen much that I’ve liked.  I’ll continue looking and y’all have a great day.

Tagged , , , , ,

“Symbolic link not allowed” in Apache w/Passenger & Rails

Once again I worked a long time on something that ended up having a simple resolution.  It goes to show you that after troubleshooting for a while you need to go back and re-evaluate ALL of your assumptions.  I plowed on and wasted so much time.  So that others can learn from my mistake, on to the problem and the solution…

The Problem

I had bootstrapped my production rails environment using Apache and mongrel but after dealing with too much bullshit around 404 situations I wanted to move over to using Phusion Passenger instead of mongrel.  I had setup the deployment structure using capistrano thusly:

1
cap deploy:setup

…and then I did a code update…

1
cap deploy:update

and so I had the releases/ and shared/ directories, and the current symlink pointing to the latest release.  I ran

1
passenger-install-apache2-module

on the server and added the requisite elements to the httpd.conf file:

1
2
3
4
5
6
7
8
9
10
11
12
13
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11
PassengerRuby /usr/local/bin/ruby

<VirtualHost *:80>
   # Server name
   ServerName myserver
   DocumentRoot /var/www/ruby/project/current/public
   <Directory /var/www/ruby/project>
      Allow from all
      Options -MultiViews +FollowSymLinks
   </Directory>
</VirtualHost>

Note that per this solution I had changed the <Directory> to point to the directory that contains the current symlink while leaving the DocumentRoot to point to the public directory. So I restart httpd (with no errors) and attempt to go to the root of my web app and I get a 403 Forbidden error. Looking in the apache error_log I see:

1
Symbolic link not allowed: /var/www/ruby/project/current

I did a million things over the course of several hours, so lets talk about the solution.

The Solution

I did not realize that apache was trying to traverse multiple symlinks to get to the current release version. In my Capistrano deploy.rb I had set

1
set :deploy_to, "/home/myuser/ruby/project"

In this case, /home/myuser/ruby was a symlink in the to /var/www/ruby. I finally noticed this when I really scrutinized what the /var/www/ruby/project/current symlink was pointing to… it was /home/myuser/ruby/project/releases/20100526211937. The httpd.conf was correct, the current symlink was able to be traversed but it routed through the /home/myuser/ruby symlink, which couldn’t be traversed.

Everything worked perfectly when I updated my deploy.rb to

1
set :deploy_to, "/var/www/ruby/project"

I should also note that I had to manually unlink the /var/www/ruby/project/current symlink and create the correct one. Once I had done that I could continue to cap deploy using the updated deploy.rb.

Tagged , , ,

Great Article on TDD in Rails

Found a great article about using RSpec, AuthLogic and Factory_Girl in Rails.  Certainly helped me to flex the ol’ muscles again after being away from Ruby TDD for awhile.

Tagged , , ,

Frustration-Driven Development

I’m in the process of moving our site from 100% full-browser Flex to a mix of HTML and Flex. We should have done it that way in the first place, but full-browser Flex got us way off the ground extremely quickly so I’m not too bothered. The single biggest change to moving our app into an embedded swf rather than full height and width and it seems to be moving along pretty smoothly.

I have one post on Generating Flex Layouts with Ruby Templates that’s been in the ol’ crock pot for awhile, stewing away. I also have one in the hooper that I’m not satisfied to publish yet that talks about Flex vs. HTML for new web sites/applications. Until the dinger dings, however, seeya next time!

August Software Developer Meetup

Last night was the monthly Madison Software Developer meetup.  Quite a few folks were there, and as always it was great to hear about the interesting software that’s being worked on in the Madison, Wisconsin area.  Check out the meetup group and stop by sometime!

Last night’s discussion (aside from introductions) was mostly around Google Wave, Objective-C/C++, the virtues of Python, camera bars (you’d have to have been there), and more.  Having it in the Sundance bar was pretty cool– the place was dead so we had room to stretch out and relax.

Tagged

Dynamically Resizing Flash/Flex

The problem with embedding flash/flex components in web pages is that you must specify the viewport of the ‘movie’ and it’s tough to change it. That’s fine for flash movies, as they’re mostly movies. But Flex apps may need to change their size depending on what type of workflows they implement. I figured it would be a tough nut to crack: we’d need to trap resize events, and then call out to javascript in the embedding html page to resize the viewport appropriately. Not the hardest thing in the world, but I didn’t look forward to writing all that javascript.

Until I found out the coolest technique evar: you write your Javascript in an XML tag in your Flex code, and then inject that Javascript out into the browser at runtime and call it. That’s cool shit right there, friend. Big, huge ups to Noel at doesnotcompute for creating a reusable object that encapsulates this behavior: BrowserCanvas.  Noel’s examples are really illustrative, but they are Flash-oriented so I had to do a little re-jiggering to  use the lib in my existing Flex code.

Note: the widget I wanted to embed was a workflow nicely encapsulated in a single component, so I was able to easily add the item to the application at runtime rather than to write out the mxml. The toughest thing was just trying to figure out where to init the BrowserCanvas class, as I didn’t know exactly where the stage was available in the Flex Application life cycle. I ended up hooking into addedToStage and it worked fine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private var canvas:BrowserCanvas;
                       
private function onAddedToStage():void {
    AnalyticsManager.instance.initTracker(this);
    canvas = new BrowserCanvas(stage,"Shopping");
    addShopView();
}
               
private function onResize(event:ResizeEvent):void {
    if( canvas ) {
        var shopping:ShopForPlansView = event.currentTarget as ShopForPlansView;
        canvas.height = shopping.height.toString();
    }
}
           
private function addShopView():void
{
    var shopping:ShopForPlansView = new ShopForPlansView();
    shopping.id = "shop";
    shopping.percentWidth = 100;
    shopping.addEventListener(ResizeEvent.RESIZE, onResize);
    addChild(shopping);
}

The other issue I had to deal with was that I needed to explicitly pass the name of the object/embed objects that embedded the swf in the html page (“Shopping” in this case). The example at Noel’s website somehow figures it out automagically.

I also can’t end the post without shouting out the inspiration for the BrowserCanvas: this post on actionscript.org. It’s a really good read that lays out the idea behind Javascript injection from the flash/flex runtime. A fantastic read.

Tagged ,

Happy Ending

I spent all day Friday trying to prep a company CentOS VPS for a rails app. My first job: get ruby installed. Being more used to Ubuntu flavors of Linux I had no previous experience with YUM, but a package manager is a package manager is a package manager. I went for the gusto:

sudo yum install ruby

Oh, ruby installed alright. Version 1.8.1. Ugh. I updated the yum repositories again and updated only to find myself at version 1.8.5. Double Ugh. So, time to install from source. I ended up finding a really good writeup of the process at the fine blog Catapult Creative. The problem was that my CentOS install was ‘hardened’ per company policy so it had no tool chain, extremely outdated (‘approved and tested’) versions of libs and apps, and little-to-no package manager repositories enabled. 

sudo yum install httpd-devel\
  openssl-devel\
  zlib-devel\
  gcc\
  gcc-c++\
  curl-devel\
  expat-devel\
  gettext-devel\
  mysql-server\
  mysql-devel

Now that I had an actual tool chain, I started about building ruby. I won’t go into the gory details (the link above has excellent step-by-step instructions). The only problems I had were that I needed to enable support for readline, etc. in the ruby install and it doesn’t compile by default. Also, to get the install to work with mysql I had to rebuild the native extensions for the mysql gem. After banging my head against the desk for 45 minutes, I realized it was a command-line typo that had done me in (!~CURSES). Ladies and gentlemen, note that, oddly, you need a total of 4 dashes in the instruction:

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

I was only using 3 dashes. After that, things were up and running quickly.

Tagged , ,

The Code You Want

In reading the excellent RSpec Book, I came across a great idea that I’ve been using as my mantra of late: “write the code you want to have.”  In its original context, the authors discuss how to write your test scenarios when you have not yet implemented the code behind them.  In that case, they suggest you code to an imaginary world where you use all the wonderful methods and accessors that would make your life simple.  Then, you go and implement those wonderful methods and accessors.

I think it’s also useful at another, more philosophical level, however; sometimes we don’t write the code we want because we perceive it to be too difficult to write.  Or we don’t work in a language because someone says it won’t work, or we won’t be allowed to deploy it.  In these cases, writing the code we want to have becomes more of a rallying cry in order to Get Shit Done.  I need to make some kind of cross stitch sampler to hang on my wall with that thing.

Write the code you want to have.

Tagged ,

RSpec, Cucumber, and BDD Testing

I got real sick while on vacation in the mountains (a combination of cold/flu and altitude sickness) and had some down-time to work on my rails app.  My main goal is to get all of the user login/user invite functionality locked down before I start expanding the feature set of the app itself, as well as to get the existing code (not a whole lot) under test.

The QuickBase gem I’ve been working on uses RSpec for the unit tests, and I’d heard good things elsewhere so I bought the PDF version of The RSpec Book before we headed to the airport.  I’ve done TDD before, and am used to the xUnit syntax and philosophy but it was real interesting delving into Behavior Driven Development (BDD) and the way they used Ruby to reduce testing to real english sentences.  Below is an actual working example of my login integration tests using Cucumber:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Feature: Login to application

        So that I can access my application's info
        As a user
        I want to login to the application
       
        Scenario: Access to login page from home page
                Given I am on the homepage
                When I follow "Login"
                Then I should be on the login page
               
        Scenario: A valid user can login
                Given I am on the login page
                When I login as "mytest" with password "mytest"
                Then I should see "You're now logged in"
                And I should be on the home page

I gotta say, to actually run the tests and see all green after writing that made me grin ear-to-ear.  I should note that it took me awhile (and a few swears) to get the constituent parts installed on my Macbook Pro (nokogiri in particular has a bug involved with installing it to vendor/gems and is very opinionated about your installed libxml2 version).  After a little bit of configuration heartache, though, I got things running really well.

The other slight issue I had in getting RSpec working with my model unit tests was that RSpec adds some generators for your use in Rails (rspec_model, for instance, which wraps the built-in ‘script/generate model’) except that it generates the appropriate test code under /spec instead of /test.  I had obviously created many models, controllers, etc. without using the wrapped generators, so I had some work to do to manually establish the /spec folder hierarchies.  I also had to google a bit to figure out how to move over and include my fixtures from /test.  Ultimately, though, things settled down pretty quickly and I’m loving it.

I guess I should also declare that I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 and loving it.

Also: I got Google Wave developer sandbox access.  More to come wheeeeeeeeeeee!

Tagged ,

On Effort

I’ve recently subscribed to Zed Shaw’s twitter feed and it’s been very illuminating. Just yesterday he posted a new [blog|article|rant] at his site about why he (A/L)GPL’s his code after his experience with Mongrel. Personally, I appreciate his stance, which (from the linked post) boils down to:

Open source to open source, corporation to corporation.

Specifically, I appreciate honesty like this, and Zed has an excellent point that many corporations accrue many ducats using open source code and libs without ever giving back to those same projects.  The good ol’ boy, ‘no-one-ever-got-fired-for-buying-IBM’ effect is still strong at large companies; they either want to be able to discreetly pay nothing for software or be able to brag that they bought a $40 million Oracle system.  So, allow OSS projects to use your stuff free, and charge those corporations up the wazoo for using the sweat-of-your-brow to get rich.  If your stuff really is that good, they’ll pay.

I feel like Zed’s latest post dovetails interestingly (though likely not his intention) with a talk he gave that I raved about on twitter awhile back.

Zed Shaw – The ACL is Dead from CUSEC on Vimeo.

This is a really good talk not only about a specific solution to a specific problem (ACLs in the banking industry, and how to build a better mousetrap) but later in the talk he also gets into some stuff that any software developers/engineer/programmer/whatever-you-want-to-call-yourself should at least have an opinion on.

Zed favors constantly improving yourself by writing code.  Learn new languages, new frameworks, new technologies.  Invent things.  Useful things.  Most importantly: do not give these useful inventive things to your miserable employer unless your compensation and respect is commensurate with them.  If your employer treats you fantastic, then hack away on the nights and weekends to deliver an improved build of Library X!  If you’re little more than a code slave, then do your job competently, go home, and create open source Library X for the good of mankind; or hell, create  your own company and sell Library X back to your original employer.

The reason that the monkeyfucks at slashdot don’t get this view is because it’s nuanced.  He’s not saying “Fuck your employer! Dog it at work! raggahaggharrwr!”  As he explains quite well in the video (starting at the 42:00 minute mark), you have your work coding, and you have your home coding.  If your company treats you really well, then let them in on the secret nuggets you’ve been doing at home!  If not, then be professional, do your assigned tasks, be polite, write really good code, but don’t let them have your ideas and inventions!

I like his views on a philosophical level, which contributes to my irritation when said views are dismissed because “I’ve never heard of him or his supposedly awesome projects.”  Jesus, if commercial (or apache/mozilla-level in the oss world) success were a prerequisite for an opinion, the slashdot comment boards would have goddamned tumbleweeds rolling through.

All of which is to say: I don’t agree with everything dude says, but then again I don’t have to.  He’s written some damn fucking fine code in his day, he’s orders of magnitude smarter than me, and I appreciate his views on Coding For A Living.  Also, you really should watch that video above– it’s got lots of good stuff in it.

And please let me be an example: don’t ever, ever, EVER read the comments at slashdot; they’ll melt your brain.

Tagged , ,