Coding at the Castle

Posted on October 2, 2018 in Oxford

On Thursday 20th September, SYP Oxford hosted a special extended event which included a practical workshop element, as well as super presentations from our panel of speakers who were highly knowledgeable about both publishing and code! The event was a success, with a great turnout and lots of positive feedback on Twitter.
As coding is a relatively unfamiliar topic to many in publishing, many of the acronyms were baffling! Our speakers also mentioned lots of useful websites to check out if you’re interested in furthering your knowledge of code. In case you didn’t manage to jot them all down – or were unable to make it on the night – our speakers have written up a blog post with links to their slides and further resources.

 

Emma’s slides

Emma both wielded a stick and dangled some carrots in an attempt to provoke and inspire the full-house audience to improve their technical literacy.

Here are her slides. And here’s her code-as-poetry.

 

class Book
  def initialize(name:, jacket: :draft)
    @name   = name
    @jacket = jacket
  end

  def name
    @name
  end

  def jacket
    @jacket
  end

  def transmit
    Transmit
  end

  # :haiku:
  def send_if_approved
    if jacket == :approved
    	transmit.new([:everyone]).call
    else
      jacket_destroy
    end
  end

  # Read as:
  # if jacket approved
  # transmit new everyone call
  # else jacket destroy

  # :haiku:
  def jacket_destroy
    jacket == :destroyed
    puts "Destroyed #{Time.now}"
  end

  # Read as:
  # def jacket destroy
  # jacket equals destroyed
  # puts destroyed time now

end

class Transmit
  def initialize(recipients)
    @recipients = recipients
  end

  def recipients
    @recipients
  end

  def call
    send_the_jacket
    Log.new("Transmitted to #{@recipients.join(', ')} #{Time.now}")
  end

  private

  # :haiku:
  def send_the_jacket
    # TODO: need to write the code
    # 'twas ever thus
  end

  # Read as:
  # def send the jacket
  # to do: need to write the code
  # hash twas ever thus

end

class Log
  def initialize(data)
    @log = data
    puts @log
  end
end

# :iambic_pentameter_sonnet:
def send_the_jacket_to_the_shops(my_books)
  my_books.select { |book| book.jacket == :approved }.each do |book|
    book.transmit.new(
      # the aggregators
      [:nielsen, :bowker]).call
    puts "#{book.name} sent to aggregators all"
    book.transmit.new([:al_saqi, :kew, :five_leaves]).call
    puts "#{book.name} sent to some indies"
    book.transmit.new([:nbni]).call
    puts "Warehouse has got #{book.name}, one and all"
    book.transmit.new([:gardners, :bertrams])
    puts "Wholesalers have #{book.name} in the can"
    book.transmit.new([:ebsco] && [:jstore])
    puts "Academics have #{book.name} for sure."
    puts "Every bookstore all throughout the land " \
         "has #{book.name}'s jacket in their very hands"
 end
end

# Read as:
#
# Def send the jacket to the shops, my books
# My books, select book book jacket approved,
# Each do, book block, book dot transmit dot new.
# (The aggregators) Nielsen, Bowker, call
# Puts book name sent to aggregators all
# Book transmit new Al Saqi, Kew, Five Leaves,
# dot call /
#   puts Book name sent to some indies,
# Book transmit new NBNI dot call
# puts "Warehouse has got book name, one and all"
# book dot transmit dot Gardners, Bertrams,
# puts "Wholesalers have book name in the can"
# Book transmit new EBSCO and and JSTOR
# puts "Academics have book name for sure."
# puts "Every bookstore, all throughout the land"
# "has book name's jacket in their very hands"
# (end end)

my_books = []
my_books << Book.new(name: "Persuasion", jacket: :approved)
my_books << Book.new(name: "Lolita")
my_books << Book.new(name: "Possession")
my_books << Book.new(name: "Beowulf", jacket: :approved)
  • If you’re using Mac OS X, open up Terminal (Google open terminal mac) and type irb, then press enter.
  • If you’re using Linux, open up a shell (Google open shell linux), type irb and press enter.
  • If you’re using Windows, install Ruby, then open Interactive Ruby from the Ruby section of your Start Menu

You’ll be at a prompt, just like a a blinking cursor at the start of a Word document. It will look like this:

 

 

 

 

 

Paste all the code in to the irb window. Then press enter so that the irb console can accept the code, ready to execute it at your command.

You’ll see the prompt again. Paste in the following text to execute the commands.

send_the_jacket_to_the_shops(my_books)

Notice if anything happens, and read back through the code to see if you can follow what happened.

Then paste in the following text, press enter, and see what happens:

my_books.each { |book| book.send_if_approved }

Sara’s slides

Sara wowed folks with code that allows Harry Potter to defeat a dementor. Here are her slides.

Resources

Here are the resources we mentioned:

 

Emma and Sara have said they are very happy to offer support to anyone interested in learning code – feel free to reach out to them on Twitter.

The majority of this post first appeared on the Consonance blog.