Doctype

November 30th, 2009
By: Steven Haddox
3 Comments »

I just found out about Doctype.tv and I am _insanely_ excited:

Share It:
[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Slashdot] [StumbleUpon] [Email]

My Ultimate Wish List

November 29th, 2009
By: Steven Haddox
2 Comments »

I’m going to post this list with the following preface: I would never expect to receive anything on this wish list (hence the “ultimate”).  I am merely thinking of things I’d love to someday have but probably won’t anytime soon as I don’t have thousands of extra dollars just laying around :)

Before I get into my list itself, I thought that everyone might want to know about a really cool tool I’ve been using for nearly the past year or so called the “Universal Wish List Button” by Amazon.  It allows you to easily add items from any website onto your wish lists on Amazon.com. It has made my life a lot easier for managing my wish lists and has been quite useful to me on a weekly basis at least so I highly recommend it :)

I have a lot of Ruby and Ruby on Rails books, but what I don’t have is a ton of swag to go with it. I’d love a few Ruby on Rails related t-shirts and other miscellaneous stuff :)

  • This shirt in Medium and Charcoal would be awesome.

  • This sticker for my netbook would be very cool :)

  • Or even this button to go on my backpack for the few times I do travel.

So nothing in that list is too bad (ranging from $4-$30ish). How about the next genre… Technology :) This will make your mouth water and probably destroy your bank account as well:

  • A new 27″ iMac to replace my Mac Pro and it’s crappy 23″Acer monitor. Specs:
    • 2.8GHz Quad-Core Intel Core i7
    • 8GB 1066MHz DDR3 SDRAM
    • 2TB Serial ATA Drive
    • Apple Remote, Magic Mouse, Wireless Keyboard
    • AppleCare Protection Plan for iMac - Auto-enroll (NEVER buy a Mac without it!)
    • Total price with gov’t discount: $2,622.00

  • But what if I wanted to just bide myself over until I can save up for the nice new shiny iMac? Well I could always upgrade my current setup. I do have a Mac Pro first generation after all that’s only 3 years old, surely it’s good for something still right?
    • There’s always the 24″ LED Apple Display ($799)

    • But then I’d need the ATI Radeon 4870 graphics card to make it work with my Mac Pro ($314)

    • I’d also need more RAM (another 12GB should do it) to keep my slow moving Mac Pro going ($402)
    • Total price to upgrade current setup: $1515 (You can see why I’d rather just get the 27″ iMac no?)
  • Next up on my list is a Drobo S (NEW at only $799!) & of course I’d need 5 2TB hard drives to go in it ($699.95).

  • Last, but not least is a TiVo. You see, I absolutely HATE my Verizon FiOS DVR. I hate that in order to use it I have to have their crappy ActionTek Router and then piggy-back my Apple Airport Extreme network setup off of it. So if I could just get rid of that stupid DVR I could ran a CAT5 down to my Airport Extreme and skip the bandwidth throttle on my 50MBPS connection. That would be great… how can I do that though? By getting a TiVo (yay!) (TiVo HD = $250 normally $300). Add in a 1TB drive to store a whole lot more since I can upgrade it myself for only an additional $80.

And that about sums up my main dream items right now. Is there anything technology related that is in your ultimate setup wish list? Anything I should know about but have somehow missed? Let me know in the comments :)

Share It:
[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Slashdot] [StumbleUpon] [Email]

I’m Thankful

November 26th, 2009
By: Steven Haddox
4 Comments »

I suck at blogging so I figure a quick blurb of text will be better than nothing.

I’m thankful for (in no particular order):

  • Katie and her constant love, support, understanding, forgiveness, and encouragement. Her belief in me and how valuable and special I am is more than I ever thought of myself and has helped make me the confident, cheerful, and kind person I am today.
  • Paisley for her smile, laughter, hugs, kisses, pain, crying, and growth. Watching her grow on a daily basis helps me realize how much we take for granted every day and how there is always room to do more, learn more, and be a better person.
  • A job that provides a stable income for my family and allows me to grow professionally.
  • A boss who cares about his employees and takes the suggestions we have to heart and really listens to our needs.
  • Ruby for making my life as a programmer enjoyable.
  • Rails for providing the easiest web development framework that just gets it right the first time.
  • Friends for being there even when you haven’t talked to them in months.
  • Online friends for getting you through the months when you never make time to talk to your old friends. For meeting up to eat sushi when you’re in town. For teaching you new skills, experiences, and helping you realize how important a random stranger can be to anyone.
  • Google Reader, Twitter, and social networking in general for distracting me from whatever it is I’m supposed to be doing.
  • My iPhone for making it so much easier to get distracted on the go.
  • Vacations for forcing me to take a break.
  • Impromptu trips for reminding me that family is always more important than that blog, website, side-job, or house project I wanted to work on right then.
  • Shopping for making Katie look gorgeous no matter the time of year.
  • Eating out for saving me from having to find energy to do dishes.
  • Vocelli’s pizza for giving me an easy pre-planned meal (even if they always get it wrong) at least once a week.
  • Katie’s baking for satisfying my sweet tooth and helping me keep my tummy she loves ;)
  • Computers for providing me a way to make a living without having to be a “real man” (e.g.: cars, hunting, manual labor, hardware, and hammers).
  • LOST for being the most amazing television show ever!
  • Snowboarding (even just once a season) for reminding me about the beauty of the Earth we live on and giving me that rush that nothing else quite can.
  • My savior and constant example, Jesus Christ, for reminding me to turn the other cheek, bite my tongue, forgive others, and be patient.
  • Life for helping me to realize that there’s always a reason to keep going even when it seems like there’s no point to it at that specific moment in time.
  • Being a girl and being able to express my emotions freely not caring about what others may think of me.
  • Portland, OR, Japan, and San Francisco for giving me places I would one day like to live because of their community, beauty, and kind people.
Share It:
[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Slashdot] [StumbleUpon] [Email]

Integrating Controllers, jQuery, JSONP, and Remote Domain Requests with Rails

July 2nd, 2009
By: Steven Haddox
No Comments »

I’m developing an application that needs to have a normal web presence (typical HTTP/HTTPS) as well as a very easily consumable 3rd party API. With these requirements in mind I easily decided to run with Ruby on Rails (.to_json anyone?) I’ve been working on it for over a month now and have encountered a situation where my controllers are getting a little large due to having to handle logic on whether the request via the API url was a Javascript AJAX requests or a regular HTTP request. Generally this is easily solved in the respond to block with something like:

respond_to do |format|
  format.html # reports/show.rhtml
  format.js { render :partial => 'reports/show' } # reports/_show.rhtml
end

This example is just rendering a partial that is also used in my show.rhtml to save updating more than one file at a time. However, my current project started turning into things like this (due to the API methodology we had decided upon with the client in advance that got extended into doing things we hadn’t anticipated):

# show method
respond_to do |format|
  format.html # reports/show.rhtml
  format.json { render :json => @report } # json format of the report data
  format.js { render :partial => 'reports/show' } # reports/_show.rhtml
  format.js_vdata {
    render :template => 'reports/show.visual_json', :layout => false, :content_type => 'application/json'
  }
  format.table {
    render :template => 'reports/show.html_table', :layout => false, :content_type => 'application/json'
  }
  ... [more formats for special MIME types here with customized views all from the same report data] ...
end

As you can see this code was being extended to generate multiple kinds of reports for loading via an API with AJAX requests. The extra formats are all being returned as JSON in order to allow for JSONP and remote-access from other domains and then the user can display the requested data / customize it as they desire. But how did I go about providing those same views to users on the web application itself? Create another format just to render the same view for regular HTTP requests? Definitely not very DRY. So it occurred to me that the following might be a possible solution:

#Controller show method
respond_to do |format|
  ...
  format.js_vdata {
    if request.xhr?
      render :template => 'reports/show.visual_json', :layout => false, :content_type => 'application/json' and return
    else
      render :template => 'reports/show.visual_json', :layout => true, :content_type => 'text/html' and return
    end
  }
  format.table {
    if request.xhr?
      render :template => 'reports/show.html_table', :layout => false, :content_type => 'application/json' and return
    else
      render :template => 'reports/show.html_table', :layout => true, :content_type => 'text/html' and return
    end
  }
end

#View template for reports/show.visual_json
< %- if request.xhr? -%>
  < %= @report.visual_data.to_json %>
< %- else -%>
  
  < %=debug @report.visual_data %>
< %- end -%>

Although this was a basic proof of concept there was already a problem with it. Any request coming from a remote domain would send requests for ‘jsonp’ and would not be recognized by request.xhr? (at least with jQuery 1.2.6 on the server we were consuming this API). I’m not sure why this was, but it seemed to be the situation I had to work with. This meant those requests were getting the HTML version of the page (not fun for parsing via Javascript). The solution I found was this (please note this is a very initial stab and is more than open to refactoring suggestions):

#Controller
before_filter :set_request_type

#show method
respond_to do |format|
  ...
  format.js_vdata {
    begin
      render_dynamic_template('reports/show.visual_json')
    else
      render_dynamic_template('reports/show.nil')
    end
  }
  format.table {
    begin
      render_dynamic_template('reports/show.html_table')
    else
      render_dynamic_template('reports/show.nil')
    end
  }
end

private
  def set_request_type
    @ajax_request = true if request.xhr? or (params[:callback] && params[:callback].include?('jsonp'))
  end

  def render_dynamic_template(template)
    template = 'reports/show.nil' if template.nil?
    if @ajax_request
      layout = false
      content_type = 'application/json'
    else
      layout = true
      content_type = 'text/html'
    end
    render :template => template, :layout => layout, :content_type => content_type
  end
#View template for reports/show.visual_json
< %- if @ajax_request -%>
  < %= @report.visual_data.to_json %>
< %- else -%>
  
  < %=debug @report.visual_data %>
< %- end -%>
#View template for reports/show.nil
< %- if @ajax_request -%>
  < %= [nil].to_json %>
< %- else -%>
  
  < %= 'There is no data at this time.' %>
< %- end -%>

Also, the best tutorial I could find for implementing jsonp support with a quick (like 2 minute) Google search was over at Sitepoint

And that should allow you to render both html and json/jsonp results based upon the kind of request coming in. Obviously it makes an assumption that remote jsonp requests will provide a parameter of ‘callback’ that includes ‘jsonp’ in the string, but given that it is your API that’s not a huge requirement to impose and you can customize it to how you see fit.

If you know of a better way to go about approaching this kind of task I’m more than open to being educated, but given the short time-frame I had and the few tutorials specific to jsonp I found this to be a pretty good first stab. Hopefully this post will help someone else if they find themselves looking for some way to accomplish similar tasks.

Share It:
[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Slashdot] [StumbleUpon] [Email]

Rails and large data strings in MySQL (longtext)

June 6th, 2009
By: Steven Haddox
2 Comments »

During my day-job this week I came across a situation where we had nice functioning code very near to our launch of a Rails application. We had just completed migrating over some historical data from another database (have I mentioned how much I love rake in the past, if not I may have to do a blog post about that too). Anyway, the data all migrated over in a matter of minutes and after invoking a few more custom rake tasks that were simple to write we had every record in the exact same position as it was originally.

The cozy aura of accomplishment had settled upon our little team when we soon discovered that all was not well in Rails-land. You see, we are processing data at defined intervals (on a per-record basis by an attribute on the object). We have a cron job setup to invoke a rake task that checks and sees if each record needs to be updated or not (I love .minutes.ago and built-in timestamp fields btw). Then the rake task fires off the method call to update with the new data as often as needed. After the update is complete we parse the new data and create a JSON string that is stored in the database (for performance over parsing every time we want to display it). We also do a combination of all the past data sets we’ve received (one for 24 and 72 hours each) and store those in JSON format to the database as well. This worked out great on all our sample instances where our objects didn’t have hundreds of data sets being merged and combined into one long JSON string.

However, once we get some live data our application started blowing up rather quickly. We came across an ‘rbuff’ error (or something weird and very vague in its meaning) and spent a little bit of time realizing that the string we were trying to write to the database was more than 64KB. We had set our fields to ‘text’ and it was truncating our data (and hence blowing up all our JSON.parse methods to get our strings back into Ruby hashes). The fix seemed fairly easy, we just had to change our column types from ‘text’ to ‘longtext’.

If you do a Google search you’ll find several ways to have MySQL create a column in the table with a longtext type in Rails. However, none of them worked for me (we tried :text, :limit => huge_number as well as :text, :limit => 64K+1, and several other methods we found online). I couldn’t find any documentation to indicate that Rails had added in support for :longtext as an actual column type as it seems to be MySQL specific. My pair suggested (for the 10th time) that we just put :longtext in our migration file instead of :text and see if it worked. I’m not as much of an off-the-cuff kind of guy as he is and I was skeptical it would work as so many blogs said to do it the ways we had been trying. Well I finally gave in and said, “Okay, well try it your way, but I bet you’re wrong.” We edited the migration to:

change_column :table, :column_name, :longtext

rake db:migrate and all of the sudden our MySQL table was showing a column type of ‘longtext’ as we had wanted all along. Needless to say I was rather embarrassed that this wasn’t better documented and I lost the bet to my pair. My question now is, does anyone know if :longtext as a column type is supported on other database types or is tied directly to MySQL with Rails? I can’t seem to find any documentation for this as a column type anywhere so I’m not sure if it is new to Rails 2.3.2 or if it just has been overlooked in the docs. As the searches I performed hadn’t brought anything back of any use for migrating my column to longtext I figured I should try and make sure I at least get a blog up about it to help anyone else who may be in a similar situation.

Share It:
[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Slashdot] [StumbleUpon] [Email]