RoR-e

If you haven't seen The 15 minute E-Commerce Site CLICK HERE


I'm currently looking for Contract jobs, Contact Me if you are interested. Dave.

How to find the perfect ruby job (I hope) David Henner May 12

1 comment Latest by Alex Aguilar

So here is the story.

My 9 to 5 job isn't the right job for me. Luckily there are a ton of jobs for developers right now. I think most people in my situation would get an interview and accept a job quickly. Luckily my situation isn't awful. My coworkers are generally good people. But... I'm taking a new approach.

I don't want to just find a job. I want to find a perfect situation for me and my future employer. I have two options:

  1. Create my own business
  2. Force employers to show me their culture.

I'm working on doing both. First, I'm applying to YCombinator. My application was a bit late but if I am accepted I think I have a great shot at having my own company. This will allow me to dictate the culture of the company I create. There is a lot of hard work involved but I'm pretty accustom to hard work.

I am also setting myself up so just in case I'm not accepted I will find my dream job. I am demanding people interview me for at least a full day. This means I want to do actual work during the interview. I want to find out if the code base stinks. I want to find out the developers test their code. Do the business people want a great product or do they just want money now without thinking about the 5 year plan.

At the end of the day, if managers don't care about the 5 year plan, then I'm not going to be there in five years. I want to find a place that I'll want be be at for 30 years. Yeah, I know things change. If I find a place that I'd stay for 3 years then most likely the job went well. I'm thinking doing a one or two day interview where you actually hang out with your future coworkers can help everyone.

The only way I can afford this much time spent on finding the perfect job is to:

  • Build some savings
  • Quit my job before interviewing
  • Tell employers things that might lose the offer

I need to build some savings because I want to start my own company but if that fails I need time to look for a perfect situation.

Quiting my job is the only way I will have time to either start my own company or take days off to interview.

Telling employers things that might have me lose an offer will help me weed out jobs that I will eventually not like. Hey if a company doesn't love making great code, instead of code that just works, then the job will eventually just make me angry. If a company never has code reviews, bad code will eventually get worse. Then I would look for a way out. On the other hand, If a company fits my criteria I will find out and so will they. That should be the point of an interview.


ror_ecommerce, ruby on rails ecommerce done right

Heroku Down OMG David Henner Apr 23

2 comments Latest by DRH

If you were affected by the recent down-time from heroku and have a shared db, you might still have intermittent down time. After contacting Heroku I was told I could just start a new app and point the domain name to the new app. I did this and all is working fine now.

Steps:

First I hope you have a backup of your DB locally. Otherwise you are in a much worse situation than I was in.

If you have a backup, Go to your app locally:

Now go into .git/config and remove all references to heroku.

heroku create my-new-app

Push your app to your new instance.

git push heroku master

Next install taps so you can push your backed up DB to your new instance on heroku.

gem install taps
heroku db:push

Now go to heroku and either destroy your old app or remove the reference to your custom domain.

heroku domains:clear

Finally, point your new app to your custom domains.

heroku addons:add custom_domains:basic
heroku domains:add www.my-new-app.com
heroku domains:add my-new-app.com

That should work.


ror_ecommerce, ruby on rails ecommerce done right

Should I Refactor my ruby code? David Henner Mar 27

Post a comment

The next time you choose to refactor a piece of you don't like, first ask yourself a few questions.

  • Does it work?-
  • Will it work for what I need in the future?
  • Are other things in the application broken?
  • Will refactoring help future development more than other issues in the software?

Too many times I see people refactoring code that works fine. I'm not arguing that working code should not be refactored. Before you do go ahead and refactor you need to understand your efforts might be best put someplace else.

It's probably obvious what you should do with code that just does not work. Most of the time you should refactor the code. That is unless other things in your application are broken and are a higher priority. Too many times I see young developers focusing a lot of effort on things that just don't add much value. If you are constructing a building and a window is not installed and a support beam is not supported correctly don't focus on the window. if the whole building falls that window won't matter much.

Likewise if your end application is banking information and your logging mechanism is broken but you are also possibly exposing banking information to the world. Put your focus on security. Your log might be fun to work on, but you won't have a job long if you expose the wrong data to the world.

90% of the time if your code works and it will work for your needs in the future, then DONT TOUCH IT. Sure you will want to make speed improvements sometimes and if your code is to cryptic to debug you might want refactor. However most software I have worked on has larger issues.

Finally if refactoring will help future development then you need to prioritize your code and take the appropriate action. Remember though, just because one task is more fun, that doesn't make it a higher priority.

Happy Coding!!!


ror_ecommerce, ruby on rails ecommerce done right

Optimize your Images David Henner Mar 11

17 comments Latest by Matt

I want to preface this post with a huge thank you to the developers I've had the chance to work with in Belarus (Altoros). Dmitry Ilyashevich and Yury Velikanau wrote the code that ended up in our code base but the whole team in Belarus is great.

Background

A few months ago my boss brought up a service called smush it. Basically this service allows you to upload an image and return an optimized image. Hence making a smaller image that still looks good for its size.

Taking a longer look Yahoo gives you the libraries they use to make smushit work. Take a look at the bottom of the above link(pngcrush && jpegtran). So the thought was that we could simply install these libraries on our server's that we upload pictures to. I wish I had been given this project but Dmitry, Yury and the Altoros team did a great job getting this working.

On to the code. What we did was create a paperclip_postprocess.rb file in config/initializers. Sorry but the code doesn't size well on the blog...

module Paperclip
  class Thumbnail < Processor
    def make
    src = @file
    conv = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
    conv.binmode
    dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
    dst.binmode

  begin
    parameters = []
    parameters << source_file_options
    parameters << ":source"
    parameters << transformation_command
    parameters << convert_options
    parameters << ":dest"

    parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")

    success = Paperclip.run("convert", parameters, :source => "#{File.expand_path(src.path)}[0]", :dest => File.expand_path(conv.path))

    if conv.size > 0
      format = begin
        Paperclip.run("identify", "-format %m :file", :file => "#{File.expand_path(conv.path)}[0]")
      rescue PaperclipCommandLineError
        ""
      end

      case format.strip
      when 'JPEG'
        # Part of libjpeg-progs deb package
        success = Paperclip.run('jpegtran', "-copy none -optimize -perfect :source > :dest", :source => File.expand_path(conv.path), :dest => File.expand_path(dst.path))
      when 'PNG'
        success = Paperclip.run('pngcrush', "-rem alla -reduce -brute :source :dest", :source => File.expand_path(conv.path), :dest => File.expand_path(dst.path))
      else
        dst = conv
      end
    end
  rescue Exception => e
    Rails.logger.error "There was an error processing the thumbnail for #{@basename}. Check imagemagick, jpegtran and pngcrush installed."

    HoptoadNotifier.notify(
      :error_class => "Paperclip - images optimization",
      :error_message => "Paperclip ERROR: #{e.message}"
    )
  end

  dst.size > 0 ? dst : conv
    end
  end
end

At the end of the day This reduced our file sizes dramatically. Some images were reduced in size by about 85%. It is well worth the extra time to get this set up with paperclip.

Check back later as we will try to create our own fork of paperclip and allow this to be a paperclip option. For now install jpegtran and pngcrush on your linux box and start optimizing your images.

Use your Ruby API (Authlogic) David Henner Jan 30

3 comments Latest by Tanel Suurhans

This week I was psyched about creating a new plugin to extend authlogic. I've always had N+1 queries whenever I use current_user. I'd do crazy things like:

@current_user = User.find(current_user.id, 
                          :include => [:roles,
                                       :addresses]
                          )

I knew I was making 2 queries for current_user but that was better than having a N+1 queries. So this week I was determined to correct the problem. I started looking through the authlogic API and to my surprise the solution is already built into Authlogic.

Take a look at The API, with_scope is all you need. So now you could just do this in your application.rb.

def current_user_session
  if defined?(@current_user_session)
    return @current_user_session
  end

  @current_user_session = 
     UserSession.with_scope(
                  :find_options => {
                    :include => [:roles]}
                           ) do
       UserSession.find
  end
end

Now lets say in the addresses_controller.rb you need to include user.addresses. You can over-write the current_user_session method to:

private
def current_user_session
  if defined?(@current_user_session)
    return @current_user_session
  end

  @current_user_session = 
     UserSession.with_scope(
                  :find_options => {
                    :include => [:roles,
                                 :addresses]}
                           ) do
       UserSession.find
  end
end

def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session && 
                    current_user_session.record
end

I'm still looking for the optimal solutions for Rails 3 and authlogic. In rails 3, Arel doesn't make a query to the DB until you need the data. The problem with the standard Rails 2 solution comes because "find" actually makes a query to the DB. So this prevents chaining: @current_user.includes([:roles])

I'll follow up with this post as soon as I "find" a solution I like.

The age of the Ruby Developer David Henner Jan 17

Post a comment

In the past 3 months I have met with about 20 "business guys" that thought they had great ideas. These guys "just" needed a developer to write the code. A re-occurring theme has started to develop. Before you go into business and start looking for a developer...

  1. Understand your great idea will never get off the ground without a developer.
  2. Understand every developer is the same as the next. There are only a select few people that understand having a great developer will help their growth.
  3. Have more to offer than a great idea. For a great idea many people will offer 1 or 2% of their company. LOL

To that I say:

Really! Please tell me you value my work a little!

I agree someone with a great business sense is worth their weight in gold. But please bring more to the table than an idea. I have hundreds of ideas. It doesn't mean I should be paid for the idea. I need to execute and have a plan to success. A good ole business plan helps too.

If you are a developer and someone comes to you asking to build something for them my suggestion is to ask these guys what they really bring to the table. In my last meeting I remember someone continuing to reply, "I know how to run a business." That doesn't make me warm and fuzzy inside when that is all you have to offer.

As a developer, learn to say no to these people. Or, if you just want money and you think the idea is bad, tell them to pay up. Take a contract job and heck if it starts to look like a great idea after 30 days you can still probably get a sizable piece of equity.

To the business people reading this post. I want to remind you, a great developer will double your profits. I suggest you pay a developer friend to interview your potential partner. If you find a great developer, they are worth a large % of your company. Marketing will be easier, scaling will be easier and your bottom line will be larger. So please, don't shoot yourself in the foot and try to screw the guy that will help bring in serious cash.


ror_ecommerce, ruby on rails ecommerce done right