Age of Slackbot

Slack is great. We use it as our primary source of communication between the team and, whilst the majority of the time it is used as an elegant middle ground between knowledge store and constructive discussion, it occasionally descends into a barrage of absurdity and internet humour gifs, usually at the hands of giphy.

For those not familiar with slack, there are two great things about it. Its integrations, and giphy. You can plug almost anything in and out of slack, github notifications, exception notifications, custom webhooks, it’s incredibly flexible. Then there’s giphy. Type /giphy followed by some words and it will return a gif related to those words. It’s always a gamble on whether giphy nails the context of your conversation or not, which is a large part of the fun.

Slack has a personality, it’s almost like a member of the team in itself. What it lacks is a physical body. So I decided to create one.

The Hardware

Fortunately I had a previous robot I could salvage for creating a Slackbot. An arduino with a motor shield held the brains, while a base with two motors with encased gear mechanisms and two wheels provided adequate mobility for a small desktop robot but this wasn’t going to be enough.

slackbot

A Raspberry Pi would give Slackbot enough brain power to handle talking to the internet and processing commands before passing them off to the arduino to interface with the hardware. I flashed the arduino with the standard Firmata library and used an arduino_firmata gem for Ruby to allow the Raspberry Pi to communicate with any pin on the arduino, giving me simple ruby methods to use to fire the motors and other hardware on command.

A speaker and touchscreen were added for interaction and a fresh install of Raspbian had been patched with touchscreen drivers, Slackbot was alive. Alive but braindead.

The Software

This post is a work in progress and will be updated as the build progresses…

One Week on Joylent

Rob Rhinehart is a software developer who created a drink that has been the centre of much debate and controversy over the past year. The idea is simple; what we eat gets broken down into nutrients and chemicals and the body is pretty indiscriminate about how it obtains these. So why not just give it what it wants and be done with the hassle of cooking, balancing meals and tracking your nutrition? Why not work backwards, and throw all the ingredients your body needs to survive into one tasty (debatable), beige shake and live off that instead of food?

Watch their creepy ass Orwellian video above.

I must admit, I’m fond of the concept. Not only because of the time it would save me, but because of the granular control of your diet. No longer are you overshooting your sugar intake because of the ludicrous amount of sugar in modern foods, or lacking in essential nutrients because of you’re just winging it all the time. It’s the perfect daily intake, everyday. You literally cannot eat anything healthier. In theory.

Rob dubbed his shake Soylent (http://www.soylent.me/) after the 1973 Soylent Green adapted from the book Make Room! Make Room!

But there’s an issue. Soylent is only available in the states, but never fear, the recipe has been detailed on Rob’s website allowing the product to be picked up and spun into action for the EU by an ex-drug dealer in Amsterdam named Joey for his company Joylent (http://www.joylent.eu/). Wonderful.

15 meals for €30. How could I resist?

For the next (working) week I’d give up food entirely. Living on 3 meals a day (approx 2100 calories) of a whey, oatflour, soyflour, maltodextrin and other assorted chemical mix.

Concerns

I must admit I am favouring the original Soylent in my mind as Rob is constantly working hard to refine his formula and catch anything he has missed in making Soylent a 100% complete sustainable nutritional replacement for food. The inclusion of maltodextrin as source of carbohydrates is something the concerns me a touch as maltodextrin has a high gycemic response, meaning it breaks down to release sugar into the blood relatively quickly, causing insulin spikes. However Rob writes well informed posts about maltodextrin being coupled with oatflour for slow releasing sugars. Afterall, the body needs both. He also writes that Soylent’s overall glycemic response is within the normal acceptable levels.

Another concern is the lack of chewing. Some take up chewing gum to keep their facial muscles in good working order, but the real issue is that chewing holds the function of releasing enzymes as part of a pre-digestion stage of breaking food down in the mouth. Enzymes that Soylent potentially lacks. In fact, a study has linked long term feeding on powdered food with hypoglycemia and signs of systematic illnesses in mice (source: http://www.sciencedirect.com/science/article/pii/S0024320514003610). I guess in theory I could raise concerns with any food. I could talk about the carcinogenic nature of some foods, the effects of refined sugars, the list goes on. The fact is, Soylent isn’t as bad as it sounds. While you may not be replacing your entire intake with it just yet, I’m fond of it’s convenience for a quick meal on the go or when you have nothing in.

This post is a work in progress and will be updated as my trial continues.

Branded Emails with Devise

I’ve been working on some email notifications for both admin and client recently and needed some nice branded emails instead of the default plain text ones that rails gives you. So for this post, we’ll look at how to create branded emails for your own mailers, and carry the same design over to our Devise emails for when a user signs up.

Firstly, lets create a template. I used a free responsive email template generator I found online to create my template and tweaked it accordingly. Responsive templates can be a hassle, so save the time and get one from someone who knows what they’re doing and adapt it to your needs.

I put this in a file in my layouts folder called mailer.html.erb and edited the template to have a <%= yield %> tag where my content would be.

Now we can use our mailer template for any emails from a mailer we’ve created. We can use them on a per method basis, or, as I prefer, we can just set it as a default template for our class to use. For instance, in the top of my admin_notification_mailer.rb, just below the default from setting, we can add:

To use our mailer layout. Rails is smart enough to know to look in the layouts folder for this. But what about getting Devise to adopt this same template?

Simple. In our config/application.rb

Now anything we send from Devise will automatically use the ‘mailer’ layout we created.

Validating Booleans

I came across a little gotcha today and thought it would be nice to start a series of ‘One Minute Rails’ posts. The idea is they’re super short, practical posts that you can digest within a minute and gain a practical piece of knowledge or insight that you can take away and apply to whatever you’re working on.

I was working on an application today where the Users model called for an admin boolean and I wanted to make this a required field for all users, so I stuck on the standard…

…and my test were still failing even though I knew admin was now a required field, or so I thought.

To understand why presence: true doesn’t work for boolean fields, we have to take a peak at how Rails is validating these fields. Rails’ way of validating presence is to use .blank? to check if something is blank, but if you try this on a false value ( false.blank? ) it returns true, confirming that the field is blank and failing validation miserably. The trick is to check that the boolean field is either one of an array of specified values. We can do this using inclusion like so…

You’re not just limited to true and false here, you could have a string field and check that only specific values are valid, like colours;

A simple trick that will save you some serious frustration on those boolean validations.