Better sort by rating with Spree and spree_reviews

The blog post How Not To Sort By Average Rating continually pops up and got me thinking about how we currently implement sort by rating. We currently use spree_reviews for capturing ratings and it takes a very simplistic approach to storing the average rating for a product:

This exact scenario is mentioned in the blog post above:

Why it is wrong: Average rating works fine if you always have a ton of ratings, but suppose item 1 has 2 positive ratings and 0 negative ratings. Suppose item 2 has 100 positive ratings and 1 negative rating. This algorithm puts item two (tons of positive ratings) below item one (very few positive ratings). WRONG.

A better solution is using a Bayesian estimate which actually takes the number of reviews into consideration. This is how IMDB currently create their top 250 movie list:

weighted rating (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C

where:

* R = average for the movie (mean) = (Rating)
* v = number of votes for the movie = (votes)
* m = minimum votes required to be listed in the Top 250 (currently 1300)
* C = the mean vote across the whole report (currently 6.8) for the Top 250, only votes from regular voters are considered.

With that, it’s fairly simple to approximate with spree_reviews. Just be sure to recalculate all your product ratings.

Into the abyss

Beware that, when fighting monsters, you yourself do not become a monster… for when you gaze long into the abyss. The abyss gazes also into you. Friedrich Nietzsche

Zen and Happiness

There is no need to start happiness after 20 years. You can be happy right now, even when you are not a Partner or don’t drive a Porsche. Things change to easily. You can get sick. You can get fired. You can burn out (if you follow all these items I guess likeliness is low).

Until these bad things happen, just work as well as you can and have fun with doing it. No reason to look at the gains of the colleagues. No reason to think about the cool new position which you didn’t get.

After all, you will reach something. You’ll end up with nice memories, maybe a good position – and 20 excellent years. Every day is a good day.

Zen Monks are not to shy with their work too. They get up at 4am (sometimes earlier, sometimes later, depends on the convent) and start meditation and work (they even consider work meditation practice). They have stuff to do like cleaning the toilets. Or working in the garden. Or as a Tenzo, they cook. They do it with all the care they can get. What ever they do, they do it without suffering and they are (or should be) happy, because every second, even the second where they are cleaning toilets, is a second of their life.

Even pyramids get lost, after a long time. Do you know the names of the people who build up a pyramid? And if you do, is it important that you know? It’s not. Pyramids are there, or not. Nothing special.

From the The 10 rules of a Zen programmer. A post I’ve read many times as there are so many gems within it.

The technical debt of your former self

As we mature and become better developers there’s a funny case of code we previously wrote taking on a certain amount of technical debt purely because we have more experience and knowledge on how to tackle the same problems. We’ve all been there, having gone back to look at code we thought was great at the time to only wonder what the hell we were thinking, or gone back to reduce a long method to a single line. Technical debt is inevitable if we continually seek to improve our skills.

First things first

I have a small check list of things I aim to do every day. This includes things like meditate, write, vlog, foam roll/stretch etc. The problem is I put off the majority of them until late at night and on most occasions end up skipping them in favour of going to bed. While I get to say I got some of the things done, I’m still treating them as an after thought to the rest of my day. Really what I should be doing is putting first things first and getting these things done before I do anything else. Why am I putting things like browsing the news, Reddit and YouTube first? I tell myself “Well I’m just getting started, I need to ease myself into it”, but really that is just an excuse to put things off. So from now on I’m going to start putting first things first.

Not so remote

Fostering a team feeling when everyone is remote can be extremely difficult. It’s easy to feel like you are working in a total silo, and can be made worse if everyone is spread across distant timezones. Being able to function as a team is a key component to project success. Feeling isolated and alone when problems come up can make work frustrating and stressful at times. Here are a few ways to try and overcome that:

  • Try and arrange core hours where the whole team is available and together on Skype/HipChat/Slack.
  • A weekly call with everyone to update on work, issues and client feedback.
  • A daily call between project managers and members of the team to chat about current progress and the project as a whole.
  • Code sharing sessions. Show code to other members on the team and explain what features are and how you’ve gone about implementing them.

Move fast and break things

I was thinking about the “Move fast and break things” approach to projects this morning. A few projects I’m currently working have been moving at a snails pace and the longer projects go on and the bigger they get before being launched fills me a certain kind of dread. I feel really comfortable launching with a few half baked features rather than everything in one big bang. When there are so many moving parts in a launch, no matter how much you test, real users are going to find problems, and trying to keep on top of them can drive you insane. It’s the difference between trying to steer a small sail boat vs a cruise liner. If you start small you can probably respond quickly to change and get to where you want to go than if you launch big and try and change course later on.

Now I don’t condone breaking things, but I do agree with the idea of moving fast and staying agile. So just “Move fast”, that’s all you have to do. Accept that things will break and things will need improving.

“A good plan violently executed now is better than a perfect plan executed next week.” – George S. Patton

Generate a random email address in TextExpander with Ruby

Made this short snippet to help generate random email addresses using TextExpander. Set the snippet content type to “Shell Script” and paste in the following. You’ll need Ruby installed which comes with most modern versions of OSX.

The snippet will generate a different address every minute and copy it to your local clipboard incase you want to paste it in again. It also uses YOPMail which you can check for emails too.

Update: I have a new post on how to do the same using AppleScript.

Hard Deadlines

On almost every single project I’ve worked on, hard deadlines have nearly always been the cause of any stress or frustration that arises. One day you’re asked to make rough estimates and then next thing you know they become pegged to a date in the future that you must meet at all cost (But you said you think it would only take X days!). Even worse is when someone non-technical makes the estimates for you and passes them down from on high (Look, this is the all the time we have, I’m sure you’ll be fine!).

Why do we still insist on having hard deadlines? Yeah I know, we asked for more features but now the project is “late” so you’ve failed to do your job. Yet, if the deadline wasn’t concrete, the project would have more features then initially scoped and delivered in a timely fashion, you’re a success!

New features are always requested, changes are always wanted and bugs will always be found. If everyone just accepted (understood) that writing software isn’t exact science then we’d all have a lot less stress to deal with and we can stop feeling like a failure for not meeting that pie-in-the-sky deadline.

Battling Procrastination

It makes no sense to leave the Dark Woods in favor of the Dark Playground—they’re both dark. They both suck to be in, but the big difference is the Dark Woods leads to happiness and the Dark Playground leads only to more misery. But the Instant Gratification Monkey isn’t logical and to him, the Dark Playground seems like much more fun.

An absolutely brilliant two part series on procrastination. My most hated enemy.

Part 1: Why Procrastinators Procrastinate
Part 2: How to Beat Procrastination

Accessing Spree routes from outside a controller

Some custom reports I was adding to Spree required links back to the products being listed. Accessing the Spree routes is slightly different to accessing normal Rails routes from outside a controller/view:

When to speak up

“Rooting for your team to fail is as bad as it sounds. Even if you said early and often that this path was a stupid one, that this destination makes no sense–if you’re on the plane, if you’re in the meeting, if you decided to play the game–then once the journey starts, your job is to get us there, safe and sound.”

I’m 100% guilty of this. I will bitch and moan like there’s no tomorrow and often when it’s too late to actually do anything. It’s better to make the most of a bad situation rather than doom everything to failure. It’s not helpful and doesn’t do anyone any favours.