Accumulating Knowledge Archive About Categories Tags
29 Sep 2013

Bad Interviews

Saw a link to this set of 'interview' questions linked from reddit. Supposedly someone was asked these during an interview at Goldman Sachs.

I received a similar interview once when I was an undergrad. I walked into a room, introduced myself to the gentleman sitting there, and then was quizzed with 25 questions about Java. Now, given I was applying for an internship, the questions were probably easier than this (I don't recall). However, the interview format was really just a quiz of 25 questions.

I've probably done on the order of 30-50 interviews over my career. (I did a lot of interviews during Waterloo's co-op program. I didn't get a tonne of job offers, so I got a lot of practice.) This interview is one of my clearest memories of interviewing, and not for good reasons. It's one of those points I wish I could got back and change -- years later I keep replaying how else I might have handled the situation.

Regardless of how I should have handled it in the past, I know how I would handle something like this today: I would leave. That's it. I'd thank the interviewer for his or her time, say the position doesn't look like a good fit, and leave.

IMHO, quiz-style interviews demonstrate either a lack of respect or lack of empathy for the interviewer and also a lack of interviewing skill on the part of the interviewer. Either way, it tells me this isn't a place I'd like to work.


24 Aug 2013

Comparing Performance of Random number Generators

I am writing a program where I need to create random numbers. Potentially a lot of random numbers, and they must be unique. I will be putting them in my database so I'm using a unique constraint there, but for performance reasons on this API I really never want to get a collision.

So "how fast do different generators work?", I wondered. Here's some really anecdotal, inconclusive results for how 2 different libraries perform. I'm testing methods from UUIDTools and Ruby's SecureRandom.

Here are the results, read into them what you will.

1.9.3p448 :034 > Benchmark.measure { 10000.times { UUIDTools::UUID.timestamp_create }}
 =>   0.310000   0.000000   0.310000 (  0.318563)

1.9.3p448 :035 > Benchmark.measure { 10000.times { UUIDTools::UUID.random_create }}
 =>   0.640000   0.010000   0.650000 (  0.673812)

1.9.3p448 :036 > Benchmark.measure { 10000.times { UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com") }}
 =>   0.930000   0.010000   0.940000 (  0.959783)

1.9.3p448 :037 > Benchmark.measure { 10000.times { UUIDTools::UUID.sha1_create(UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com") }}
 =>   0.940000   0.010000   0.950000 (  1.007404)

1.9.3p448 :038 > Benchmark.measure { 10000.times { SecureRandom.hex }}
 =>   0.050000   0.000000   0.050000 (  0.060006)

1.9.3p448 :039 > Benchmark.measure { 10000.times { SecureRandom.base64 }}
 =>   0.120000   0.000000   0.120000 (  0.124282)

1.9.3p448 :040 > Benchmark.measure { 10000.times { SecureRandom.urlsafe_base64 }}
 =>   0.130000   0.010000   0.140000 (  0.136464)

1.9.3p448 :041 > Benchmark.measure { 10000.times { SecureRandom.uuid }}
 =>   0.110000   0.000000   0.110000 (  0.113453)

I'm going with SecureRandom and may not use UUIDTools in the future (I'm using it another project)


24 Aug 2013

Being a good citizen

I just found an SO Question. I wanted a quick validation on how I was creating an XOR validation on 2 fields. (I was doing it right, I just like to know I'm doing it as simply as possible.)

While I was looking at the post I updated it to match the Rails 3 errors api and also to use more concise syntax on the validations. I rely on Google and SO so much, I love being able to contribute back, even if in a small way.

In case I forget again, here's XORing 2 fields in a validation.

class AvailabilitySearch < ActiveRecord::Base
  validate :room_class_xor_property

  private
  def room_class_xor_property 
    if !(room_class_id.blank? ^ property_id.blank?)
      errors.add(:base, "Specify room_class_id or property_id, not both")
    end 
  end 
end

Of coure, it doesn't count until it's tested

it "should require either room_class_id or property_id" do  
  dates = {:start_date => 2.days.from_now, :end_date => 4.days.from_now}
  AvailabilitySearch.new(dates).should_not be_valid
  AvailabilitySearch.new(dates.merge(:room_class_id => 1)).should be_valid
  AvailabilitySearch.new(dates.merge(:property_id => 1)).should be_valid
  AvailabilitySearch.new(dates.merge(:room_class_id => 1, :property_id => 1)).should_not be_valid
end 

Fork me on GitHub