Stac Blog

December 8th, 2015 by Josh

The return of Leeds Digital Festival

Last Tuesday we attended an informal gathering upstairs at The Belgrave, for anyone who wanted to play a part in the planning of Leeds Digital Festival (LDF) 2016. ​

LDF aims to partner with Live at Leeds between 25th - 30th April 2016 to promote everything digital. Partnering with Live at Leeds will help promote technology in Leeds further by combining music and art with digital. ​

The open nature of the meet-up was reflected in the attendees; like-minded people who came together to discuss how we can demonstrate the digital expertise that Leeds has. Backed by a core steering committee, the festival will host a wide array of events across the city.

Here at Stac, LDF instantly caught our attention as we’re already involved with events in the technology sector in Leeds so we were keen to find out how we could contribute to the bigger picture. ​

After an hour or two of discussion hosted by Stuart Clarke, the evening broke into a social where everyone got the chance to network. It’s times like these when you realise how vibrant the digital community in Leeds really is. Running Hey! means we usually network with a lot of event organisers and businesses, but it was great to meet plenty of new faces (to us at least) who were interested in promoting Leeds’ digital culture.

We’re excited about the possibilities of what LDF can bring to (and export from) Leeds. If you’d like to find out more about the LDF, get in touch with Stuart or Josh. There’s already an active Trello board which we’re using to help plot out the different events and that allows businesses to let us know the services they can contribute. We hope that these things will combine to be a fantastic demonstration of what the city has to offer.

Alternatively you can check out @LeedsDigiFest16 on Twitter or leedsdigitalfestival.org.

November 4th, 2015 by Josh

Case Study: Sky

Early in 2015 Sky made a commitment towards expanding its technology hub to the North. With this expansion came a new set of challenges regarding resourcing and training a dedicated team in the area.

We were approached by Sky to help draw up and deliver a bootcamp for Ruby developers during their initial recruitment drive. This involved authoring a set of materials and workshops that could be open sourced and built upon by their developers. We were also tasked with assisting new waves of developers joining the company in getting up to speed with Sky's architecture and processes.

Sky enlisted our help due to such rapid growth in Leeds and wanting to respond quickly and efficiently to on-boarding developers. With our experience of the best development practices — and more specifically Ruby — we were a good fit.

The initial bootcamps were held between June and September, 2015.

Sky Bootcamp on GitHub

Overview

The bootcamp’s curriculum followed this loose outline:

  • Exercises: Introductory tasks such as opening up an interactive Ruby shell and object oriented programming
  • Workshops: Face-to-face workshops with candidates, highlighting different features and patterns found in common Ruby applications
  • Final Project: An end of course project allowing candidates to put their learnings into practice within the context of a real world application
  • Handover: Migrating the candidate from the bootcamp into a production squad. Sky use a similar engineering culture to Spotify

However, this framework was in place more as a point of reference than a strict linear path. We found a more informal course to be more inviting and intuitive to candidates who already knew how they approached learning and problem solving.

Process

Exercises were mostly unattended to allow time and mental space for candidates to discover a learning style that worked for them. Following each exercise they were also encouraged to request feedback and code reviews. We used industry standard tools such as GitHub to monitor and review candidates' progress. Forking from the main sky-uk/ruby-bootcamp repository allowed us to see work in progress, as well as providing a platform for us to review work in Pull Requests.

Workshops were more involved with us gathering candidates together for either live coding sessions or talks. These were always informal to encourage group discussion, and we found these to be the most effective tools for teaching candidates the "Ruby way" of doing things.

The final project was another useful tool for evaluating the sum knowledge from all exercises and workshops within the bootcamp. We found this to be a great talking point amongst candidates as well as a useful way to gauge who would work well in squads together.

DSL workshop on GitHub

Summary

We're incredibly proud of the work we did with Sky, and enjoyed helping them with their expansion to Leeds. We're excited about what it will do for the future of technology in the North.

The feedback we received from candidates was well balanced and positive, with Stac being praised for our support and expertise in teaching Ruby to newcomers and experienced developers in the language.

If you'd like to take advantage of the learning materials produced during this project, it's being actively developed over on GitHub.

May 15th, 2015 by Josh

Building a Slack slash command with Sinatra, Finch and Heroku

Slack is awesome. We use it on a daily basis to keep in touch with pretty much everyone. With all the positive press it's been having, we thought we'd see if we could create a simple bot which would respond to slash commands.

Overview

For the purpose of this post, we're going to write a bot which responds to questions about our Hey! events. Ideally, it will respond to the following sub-commands:

  • /hey when - When is the next event
  • /hey what - Who is speaking at the next event, and where can I find out more information on each talk
  • /hey unsupportedcommand - Respond to missing commands with a friendly error message

Tools

To achieve this we're going to use a few free tools:

  • Sinatra - A Ruby DSL for creating web applications
  • Finch - A great tool for exposing local sites to the Internet
  • Heroku - Cloud hosting platform, deployed to via Git

You can find the Sinatra code for this post on GitHub.

Steps

Firstly we're going to write a simple Sinatra application to respond to Slack requests. At its most basic, it will receive a question from Slack which it needs to then return a plain text response.

We'll create a Gemfile to tell Ruby about our dependencies:

source 'https://rubygems.org'

gem 'rack'
gem 'sinatra'
gem 'foreman'

We've also added Foreman here which we'll want to use when we deploy the application to Heroku.

Next up we'll write a basic version of our application, we'll put the contents into a file called config.ru (a Rack config file).

require 'sinatra'

post '/' do
  text = params.fetch('text').strip

  case text
  when 'when'
    'TODO'
  when 'what'
    'TODO'
  end
end

run Sinatra::Application

Right now, this takes the incoming text parameter (the command typed by the user that Slack sends), and responds with some placeholder text depending on the sub-command.

Now let's see if we can get Slack talking to this application. Run the application with the following command from the project directory:

bundle exec rackup config.ru

Assuming everything has worked correctly, you should see something like:

[2015-05-14 17:41:14] INFO  WEBrick 1.3.1
[2015-05-14 17:41:14] INFO  ruby 2.1.1 (2014-02-24) [x86_64-darwin14.0]
[2015-05-14 17:41:14] INFO  WEBrick::HTTPServer#start: pid=57001 port=9292

This is where Finch comes in. We need to expose this application to the Internet so Slack can talk to it.

Once Finch is installed, we'll tell it to forward your local application to an external URL which we can give to Slack:

> finch forward localhost:9292

→ Requesting connection... ✔
→ Establishing secure connection... ✔

The following sites are now being forwarded. Press CTRL+C at any
time to end your session:

--------------------------------------------------------------
| Public URL                         | Private URL           |
--------------------------------------------------------------
| https://cream-uneven.usefinch.io   | http://localhost:9292 |
--------------------------------------------------------------

Great, we're all set to configure Slack. Under your own Slack account, visit /services/new/slash-commands to add a new command, and configure it as below.

Setting up a Slack integration

When that's all saved, you should be able to test out your slash command integration! Try typing the following into any slack channel:

/hey when

And you should get back TODO. It works! Let's improve our application a little further.

require 'sinatra'

InvalidTokenError = Class.new(Exception)

post '/' do
  raise(InvalidTokenError) unless params[:token] == ENV['SLACK_TOKEN']

  user = params.fetch('user_name')
  text = params.fetch('text').strip

  case text
  when 'when'

    <<-TEXT
The next Hey! event will be held on the 20th May from 7:30pm at The Belgrave in central Leeds.

Hopefully see you then #{user}!

https://heyst.ac/
TEXT

  when 'what'

    <<-TEXT
The next Hey! event has two lectures planned. The first one is with Rich Fiddaman discussing everything hospitality. The second is with Matt Dix discussing Leeds Indie Food Festival.

https://heyst.ac/lectures/a-pint-with-the-pub-landlord

https://heyst.ac/lectures/kickstarting-a-city-wide-food-festival
TEXT

  else

    'Unknown command :cry:'

  end
end

run Sinatra::Application

We've added a few things here:

  • Some real copy for the when and what sub-commands
  • We're raising a custom error if the request isn't coming from Slack. We can verify this by checking the request contains a private token that only you and Slack know about
  • We're also dealing with missing commands by falling back to a friendlier error message

Now when you type /hey when you should see something like this:

Working slash command

And if you mistype a command:

Missing command

Deploying to Heroku

Now we've got our application working and tested, we need to push it to Heroku. First create a Procfile so Heroku knows how to run the application:

echo 'web: rackup config.ru' > Procfile

Then add everything to Git and push it:

git init
git add -A
git commit -m "Initial commit"
heroku create
git push heroku

The heroku create command should return the URL your application is available at. Now your application is hosted! All that's left to do is change the URL in the Slack slash command settings and you're good to go.

Future Improvements

A few potential improvements to this application could be:

  • Remove the hard-coded event information. This would ideally pull from a Hey! API
  • Embed more information about the events in the what command
  • Add another sub-command to subscribe to the Hey! mailing list directly from Slack

We hope you've found this brief tutorial useful, let us know how you're using slash commands in the comments.