Upgrade to Pro — share decks privately, control downloads, hide ads and more …

madscribes and online mentoring

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

madscribes and online mentoring

I gave this talk at the monthly Seattle.rb meetup on 5/6/15. I talk about code from a Ruby on Rails game I've been working madscribes.com. I go over how we can use time ranges as hash keys and how to implement realtime chat with websockets. I then talk about my positive experiences with online mentoring.

Avatar for Todd Lynam

Todd Lynam

May 05, 2015

Other Decks in Technology

Transcript

  1. How to play Create or subscribe to a story Each

    person submits a sentence Vote on the sentence you like Highest voted sentence is added to story
  2. Range Objects Need <=> First and last objects comparable with

    <=> (10 <=> 20) == -1 (20 <=>10) == 1 (10 <=> 10) == 0
  3. Range: include? vs cover? include? numerics: compares first and last

    values <=> O(1) iterates over each value O(n) cover? compares first and last values <=> O(1)
  4. Hashes Can use any object as keys symbols, strings, numbers,

    time, etc How about using time ranges as keys?
  5. Hash with Time Range h = {Time.now.yesterday..Time.now.tomorrow => "Gumby Time”}

    h.find { |time_range, _| time_range.cover? Time.now} “Gumby Time”
  6. Since 1.9.2 Time.succ is Obsolete Range#include? requires succ implemented 1.succ

    == 2 Date.today.succ == Date.tomorrow Time.new(1).succ != Time.new(1) + 1 include? can’t treat Time as numeric and use <=>
  7. Websockets Server can send browser data without being asked Acts

    like HTTP message then upgraded Offers encryption Rails 5 support through mysterious Action Cable
  8. f

  9. Improvements Single thread for db connection to notify all subscribers

    @subscribers hash holds code blocks to be run on notify Mutex prevents multiple database listen threads
  10. What’s a Mutex Mutex otherwise known as a semaphore Forces

    block of code to run sequentially Comparable to database locking Without mutex, threads can update shared variables
  11. End Result Two threads per web socket One is listening

    for browser messages One is sending keep-alive pings One thread for database listening Ability to fit on a free Heroku instance