So I was laying in bed this morning, thinking about how late I get up now compared to when I worked at Avon. I tend to go to sleep around 1am or later most nights, and get up around 9:00 or 9:30 am. Late night seems to be optimal coding time for me, the tv is off, most of my twitter network is winding down, things just get quite on the net and in my house - code flows.

This is a stark contrast to how things were with Avon. I was usually in bed by 11 and up by 4:30 am to make it in for the 5:30 am start time. I never understood why a call center had to be open at 6 am for customers? I mean really, the Avon ladies couldn’t wait until 8am like most normal humans in this day and age?!?

When the constrains were lifted from your life because you work from home, how did your life change?

I am sure if you read my blog, you are aware that Steelpixel Hosting has been “acquired” by RailsPlayground for an undisclosed sum of nothing (read: $0). I made a major MAJOR mistake with the hosting server and the easiest route was to just move people to a new service. The control panel hard drive died, it was also our “backup” server and we didn’t have any external copies of the customer data. Luckily the websites were intact on another server, we just lost CC and control panel data.

The current blog you are reading is on my new private server (vps) running both nginx (rails) and litespeed (php). I have almost all my sites moved over to this box, I think I only have 4 or 5 more to move at this point. I am also thinking about setting up a new blog geared more towards my rails work, I find a lot of nifty tips that I feel should be shared because the search results on these issues are totally lacking. I will link to it once I get it up.

Tasty Planner our 1st place app, has been updated. We have really revamped the Menu Planning, Grocery List Creator, our Chef list, and the Recipe Sharing portions. We added popularity algorithms to recipes, changed our backend search engine (sphinx now), focused on SEO a bit, and tried to really clean up the UI. You can also find a brand spankin new Recent Recipe Atom feed if you are curious to follow new recipes up to the minute :).

A counter cache is a drop dead simple feature that makes counting child objects much faster. It allows you to keep a database field on the parent object, with the integer in it. Rails will update the counter for you when an association is made between the parent and child objects. This allows you to do a simple SQL query for the counter stored on the parent object, rather than counting *all* the associated objects each time. Very handy, but something changed in edge (2.0) recently that made all the instructions on tutorial sites stop working.

Counter cache has become a attr_readonly attribute, and as such you can’t directly mess with it and have the changes saved when you call object.save. Take this railscast example and give it a shot against the latest edge build… You will end up with all 0’s in the count column. So what is a guy/gal supposed to do to get some Counter Cache action into a db table for objects that are already in production? Let me show you my edge based migration…



  def self.up
    add_column :recipes, :saved_recipes_count, :integer, :default => 0
    Recipe.reset_column_information
    Recipe.find(:all).each do |r|
      Recipe.update_counters r.id, :saved_recipes_count => r.saved_recipes.count
    end
  end

So if you note, we are using update_counters instead of update_attributes. The update_counters call takes two arguments, the first arg is the id of the object and the second arg is a hash of counters with the amount to increment by (or decrement if the number is negative). The update_counters call is the same thing rails uses behind the scene to update your counters when you add/remove child objects.

Hopefully someone will find this stuff helpful, it drove me nuts for about a half hour the other night.

Well, I guess the jig is up. My g rankings are starting to slip. I suspect if I redesigned the site a little to point to all my active projects and all the writing I have done around the web, I would probably go up a few notches. I used to be 8 of the top 10 search results for my name, but that is no longer.

I used ClaimID in an effort to try and “glue” all my work together, but that doesn’t seem to be helping. They did turn out to be an easy way to start using openID, though.

So here are some projects I am working on:

I have also done some various writings around the internet:

Here’s to hoping I can find some time to make this site a bit more useful and redesign it a bit!

Life goes on

Filed Under General | 1 Comment 

I am not even sure people follow this thing anymore :). Either way, here are some quick updates.

We won first place with our rails rumble app entry, Tasty Planner. I am very proud of our team and we are all excited to turn it into a real business!

You would think with working from home that I would update this blog more, but it is hard, for sure. The really nice thing about working from home is that I get to spend *all* of my time with Brayden when I have him (1/2 the week) and get my work done at night and after he goes home on Saturday afternoon. It really has been working out nicely.

I am also about to launch my first open source project, so stay tuned for details on that!

Chris and I recently released the new Web 2.0 Show website and we worked very hard to ensure the performance was as quick as we could make it. We used the ySlow plugin for firefox and made most of the tweaks they suggested, we were able to get to a B (86) before we added things like the twitter script.

The biggest performance gain we made was to turn on rails full page caching for the episodes index, the episode show page, and the archives page. The big issue is, we didn’t build a namespaced admin controller for the site, we embedded the admin stuff into the restful resources, like episodes/new, for inline admin stuff. We put in a simple admin interface (just a bar across the top) but it broke as soon as we turned on page caching. Chris and his boss had just solved this very issue at their work, so I took the tip from Rich and started hacking up a quick javascript method to do an admin navbar.

First, I had to add the route and the controller action to handle the ajax requests for an admin navbar.


routes.rb
map.resources :episodes, :has_many => [ :comments ], :collection => {:archive => :get, :search => :get, :admin_bar => :get}	

episodes_controller.rb
def admin_bar
    respond_to do |format|
      if logged_in?
        format.js
      else
        format.html {render :nothing => true}
      end
    end
end

Once that was done, I just needed to add the ajax request and the admin_bar div to the application.rhtml, it loads the ajax request each time the page does. I placed the code at the bottom so the admin bar loads last and doesn’t hold up any of the page rendering. I used url_for to make the ajax call, but this blog doesn’t seem to like my code syntax.


new Ajax.Request('/episodes/admin_bar', { asychronous:true, evalScripts:true, method: 'get'})

The last piece was to add the rjs and have it pull in the shared/_admin_navbar.rhtml partial.


page['admin_bar'].replace_html :partial => 'shared/admin_bar'

And that’s it, now the rjs should pull in your admin_navbar partial and dump it into the admin_bar div.

Next Page →