Don't Forget to Plant It!

Installing Native Gems With Custom Library Paths

A few weeks ago, I started using the Patron Gem for Skribit and ran into an issue on our CentOS production servers which uses a very old version of libcurl.  I got it working by compiling a new version of libcurl and building the Gem against those binaries.  Since I didn’t want to overwrite the libcurl that CentOS provided, I installed the binaries in another location instead, and updated the LD_LIBRARY_PATH environment variable so Rails could properly load the Gem.

A couple of days ago, Paul brought to my attention that using LD_LIBRARY_PATH isn’t a good thing.  While I didn’t necessarily think it was a big deal, it did peak my curiosity on how I would get this work without it.  Here’s the command I finally used to get it to work:

1
2
3
sudo env PATH="/opt/curl/bin:$PATH" gem install toland-patron \
-v "0.4.1" --source http://gems.github.com \
-- --with-ldflags="-Wl,-R/opt/curl/lib"

The key part is the –with-ldflags option at the very end.  The -Wl,-R<path> option adds the given path to the list of paths the linker will use to find libraries at runtime.  Hopefully, someone will find this information useful, since I couldn’t find this information myself on the ‘nets anywhere.

Switching From Windows to Mac: A Retrospective

Just recently done a 2 week stint working on Windows while Apple Geniuses were working on my MBP, I thought it would be a good time to blog on my own Skribit Suggestion and reflect on my switch to Mac 14 months ago.

Reasons for Switching

Prior to my MBP, I’ve was working on a personal HP laptop that was on it’s last leg.  My screen had started developing an assortment of 1 pixel vertical lines and the keyboard would randomly doouble typed keys.  I had a choice to make - I can either get another (and better) Windows laptop, or do the the switch.  Ultimately, I decided on switching.  Here were my reasons.

Apple made great looking laptops that looks good too

Apple really makes some really good looking laptops, but it’s easy to forget that they they’re functionally great laptops too.  When my wife first got her MacBook, I was amazed at how everything looked so crisp on it.  And speaking as someone that has broken a power connector on a laptop before, MagSafe is a must-have awesome feature.

A Unix based Operating System

When you do development, working on a Unix based environment with a real command line is a big advantage.  Cygwin can help bridge that gap on Windows, but it’s nothing like having a terminal that can size itself properly and not having to constantly translate Windows paths to Unix paths and vice versa.

Another benefit of having a Unix OS is that Open Source software plays much better on it than on Windows.  Most OSS is developed to target Unix first, Windows second.  When working on Elf Island on Windows, my workflow while working on the game (which is developed primarily using OSS), involved starting two different services from Windows System Tray, starting another service from the Windows Services, and finally running a few commands from Cygwin.  I can do the equivalent of all that from the command line on a Unix environment.

A Paid-For Software Friendly Ecosystem

For some reason, it seems that Mac users are willing to pay for software, and as a result there is a lot of reasonably price software for Macs.  Doing software development myself, I can appreciate and definitely want to support this line of thinking.  Sure, Windows has tons of commercial, paid-for software, but I can’t say I feel comfortable about downloading them for fear of excessive ads, poor installations practices, and/or spyware.

Experiencing Something New

Probably the biggest reason for doing the switch is that I’ve been using Windows for years.  It was time for a change - a change for changes’ sake.  Programmers are told that they should regularly learn new languages to keep their skills sharp and to explore new ways of doing things.  It should be the same with the software you use as well.  If you develop software, you owe it to yourself to see how the other side does it to gain some perspective.

Conclusions

So after a year of working fully on the Mac, here’s are some things I like and don’t like about my OS X:

Pros

  • Windows Management. It took a while getting used to, but I have grown to prefer Command+Tab & Command+` to Windows Alt+Tab model.
  • OS Degradation. With my prior laptop, Windows had greatly degraded by it’s first anniversary.  I haven’t experience that with my MBP yet.
  • Great TrackPad. When programming, I try to stay on the keyboard as much as possible, but I find that transitioning between the trackpad and keyboard on my MBP the easiest of any laptop I’ve used before.

Cons

  • Keyboard Shortcut Images. For some strange reason keyboard shortcuts are still displayed using icons (Apple Keys) that in some cases are no longer shown on the keyboard.  Trying to remember what icon is what key can feel like akin to decipher hieroglyphics.
  • Alt Key Menu Access. I miss how the Alt key in Windows gave you keyboard access to the application menu.  I often used that function keyboard shortcut.
  • I Miss My Alt+Ctrl+Delete. I kind of feel that Windows does a better job of preventing errant applications from locking up the whole OS.  I attribute that to Window’s plentiful experience with crashes and lockups.  It seems that lockups on OS X are more catastrophic (requiring a hard reboot) than they should be.
http://macromates.com/

Problems Uploading Files to WordPress?

A Google search seems to indicate that problems uploading files on WordPress installs is a pretty common occurrence.  Unfortunately, I had the hardest time finding the solution to my particular ailment.  Hopefully, this post will find those others who run into this problem in the future.

From the WP Admin pages, go to Settings > Miscellaneous.  Make sure the value for ‘Store uploads in this folder’ is where you want your files stored (in most cases, it should be wp-content/uploads).

Miscellaneous Settings ‹ Don’t Forget to Plant It! — WordPress

In my case, this was pointing to a folder I was using for a WP install I was using to test the Thesis theme I’m using now.  Reverting it to the default fixed my problem.

Creating Static Pages W/ Rails ActionViews

Recently, I needed to create some static reporting pages for Skribit.  From a quick search, I got a lot of results that talk about Rails and static pages, but none did exactly what I needed:

  1. To be able to generate pages with different paths from one URL
  2. Pages to persist across Rails deployments

Not seeing any solutions that fit my needs, I set out to come up with my own.  Here is what I ended up with.

First, I needed to add a route for generating/displaying the reports:

1
2
map.reports 'report/:year/:month/:day', :controller => 'report',
:action => 'show', :year => nil, :month => nil, :day => nil

From here, I could just use the standard caches_page :show declaration, but that would only generate the page I wanted if I used /report/2009/05/25 as the URL.  What if I wanted /report to generate the report for the current week?  Well, you can do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class ReportController < ApplicationController
after_filter :cache_weekly_report, :only => :show
def show
if params[:year]
@year = params[:year]
@month = params[:month]
@day = params[:day]
if File.exist?("#{Rails.root}/public/report/#{@year}/#{@month}/#{@day}.html")
redirect_to reports_path(
:year => @year,
:month => @month,
:day => @day)
else
# render report for a specific day
end
else
today = Date.today
@year = today.year
@month = today.month
@day = today.day
# render report for the current week
end
end
protected
def cache_weekly_report
cache_page(response.body,
"/report/#{@year}/#{@month}/#{@day}.html") if @year
end
end

The magic is in the after_filter method cache_weekly_report.  We basically use the same mechanism Rails page caching uses to save our new report page.  Now, calling /report will generate a static report at /report/2009/05/25, or whatever the current day is.

The last thing to do is to make sure that the reports persist through new server deployments.  That can easily be done with a symlink in your capistrano script:

1
2
3
4
task :symlink_reports do
run "mkdir -p #{shared_path}/report; ln -nfs #{shared_path}/report #{release_path}/public/report"
end
after 'deploy:update_code', 'deploy:symlink_reports'

And that’s it!  What do you think?  I’d love to know if there are any simpler solutions to this.

Building Software to Their Audiences

When building software, it’s a good idea to identify the needs of 3 different kinds of audiences.

The first 2 kinds are obvious ones.  We know to listen to what our End Users ask for, but not necessarily build everything they ask.  And we want to balance what the Business wants with when they want it.

The last audience, the fellow Developer, is often forgotten.  This means writing clear and concise code.  This also means identifying the common maintenance points in your software and making it easy to work with.

And this also means factoring into the design the capabilities of the development team.  Just like it is unacceptable to write bad code, it should be just as unacceptable to over design software beyond the hiring practices of the company you work for.

Turning a New Page

It’s been a month now since I left my contract at AutoTrader.com.  For the most part, I’ve enjoyed my time there, but the thought of celebrating my two year anniversary there was a little frightening.  While I am very adaptable to the corporate life, it isn’t for me.  When FlickStation (the last startup I was a part of) desolved, the plan was to serve a year of corporate duty to get my bearings before heading back into the startup arena.  But some interesting work, interesting politics, and great co-workers kept me there longer than I expected.  But ultimately, I’m addicted to execution and delivery, both of which seem very hard to do well and often in large companies.

Also, for people with entrepreneurial aspirations, the corporate world has a way of slowly draining it from you, replacing it with contentedness.  And when you’re building your startup, those aspirations provides the fuel for you to push on.  I was worried that one day I wake up and find it all gone.

I’m now spending my time at Good Egg Studios, where we just now wrapped up our second week in private beta of Elf Island.  Working here has been like a breathe of fresh air.  The technology is familiar and not so familiar at the same time, and I’m working with some great people (including Startup Weekend alums Rob and Amro) and leadership with great character.  As an added bonus, my commute is a lot shorter now, and also I’m much closer to Skribit.

Oh, and did I mention I was working on a game!  A fscking game!

Growl Notifications for Ant

It’s a real refreshing change to be doing developing on Mac these days.  Currently, our Ant builds at work are less than optimal, taking ten’s of minutes to do a full build.  Fixing it is something we definitely want to do, but because of the complexity of the build and existing deadlines, right now isn’t the best time.  So instead of constantly checking on the progress of my build, I installed this Growl Ant build listener which will display a Growl notification when a build has completed.

The README for the listener got me started - the only thing that didn’t work for me is setting the build listener using the ANT_OPT environment variable.  It looks like the default install of Ant on Leopard uses that environment variable as arguments to pass to the Java VM.  So instead, I just used an alias:

1
alias ant='ant -listener net.slimeslurp.growl.GrowlListener'

Just add this line to your ~/.bash_login to use the build listener every time you build.

Moving Off WP.com

So after three months of WP.com, I’ve decided to move back to my own hosted WordPress blog.  One reason for the move was so that I can beta test our Skribit widget, which can now be easily styled to blend perfectly to your site.  Please give it a shot, and shoot us any feedback.  Right now, this is a one off install, but I’m starting to put things together so that we can roll this new widget out to more testers.

Also, I felt that by moving to WP.com my blog got sort of bleh.  I had to use from one of the provided themes, and was limited in the plugins and widgets I was able to use.  It’s not like it was anything special before, but at least it wasn’t special by my choosing.  So, I’m on my own again, using the WP Subversion installation that Paul recommended.  I also bought this wicket cool theme that is very well done and supported.  Now, I need to get some cool plugins - any recommendations?

Running FiveRuns TuneUp in a Separate Environment

FiveRuns’ TuneUp is a great tool for profiling your Rails app, but by default it is always running in development. This causes two issues 1) every request is slower in development as it is always collecting profiling data, and 2) the TuneUp bar can mess with the layout of your application, especially if you’re rendering content in iframes like we do with Skribit. So instead of having TuneUp always run in development mode, I’ve changed it to run only when the server is started in a new environment called ‘profiler’. Here’s how I did it.

First, you need to tell TuneUp to only run in the profiler environment. You do this by modifying config/tuneup.rb (create this file if it doesn’t already exist):

1
2
3
4
Fiveruns::Tuneup.config do |config|
config.environments.delete('development')
config.environments << 'profiler'
end

Next, copy the development configuration block in config/database.yml and create a new block called profiler:

1
2
3
4
5
6
7
profiler:
adapter: mysql
encoding: utf8
database: YOUR_DATABASE
username: YOUR_USERNAME
password: YOUR_PASSWORD
socket: /tmp/mysql.sock

Finally, create your profiler environment configs by copying your development configs:

1
cp config/environments/development.rb config/environments/profiler.rb

You’re all set! Now, to run the server with TuneUp on, just run the server in the profiler environment:

1
script/server -e profiler

Now, I have TuneUp available to me only when I’m looking to optimize performance.

Aptana Goes Into the Clouds

I use Aptana for RoR development.  Not because it’s a good Ruby or Rails IDE, but because I do so much Java at my paying job and switching between Java development on Eclipse to RoR development on Aptana is a breeze.  Today, I was checking out Aptana’s website for updates when I noticed that they now have a product called Aptana Cloud.

Aptana Cloud appears to be a integrated deployment/hosting platform for Aptana.  You can write applications in PHP, Jaxer (Aptana’s AJAX framework), and Ruby on Rails (coming soon), and deploy them to a cloud with a push of a button.  Right now, it deploys to Joyent’s Cloud, but it appears that the intention is to be provider agnostic, which would be key for adoption.

I’m very interested in trying this out, though I’m going to wait until RoR support is ready.  Hopefully, this will lead to some standards to cloud computing, making it easier to switch from one provider to another.  No doubt this is where lightweight development frameworks should be going (looking at you Appcelerator).