Programming Day with Harry & Nightmares with Ruby | Nathaniel Read

Programming Day with Harry & Nightmares with Ruby

I recently met up with Harry (@harryb0905) and we spent the day experimenting with a BlinkStick and a BBC Micro:Bit, which was pretty cool.

We tried to get Jekyll installed on Harry’s laptop, which caused a bit of a hassle as it turns out when installing Ruby through Homebrew we didn’t account for the fact that MacOS itself runs a version of Ruby. After ages of fighting frantically with the error below (first dealing with the fact that OSX 10.11 brought System Integrity Protection), we realised we could solve it by installing RVM (Ruby Version Manager).

Harrys-MacBook:Harry-Site HarryBaines\$ jekyll -v
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in`require'
from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.2.0/lib/jekyll/plugin_manager.rb:34:in `require_from_bundler' from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.2.0/exe/jekyll:9:in`<top (required)>'
from /usr/local/bin/jekyll:23:in `load' from /usr/local/bin/jekyll:23:in`<main>'

But once you install RVM, everything becomes plain sailing we discovered sudo curl -L https://get.rvm.io | bash -s stable --ruby then gem install jekyll and you’re done.



Blinkstick script

I’ve had a BlinkStick for a while, but hadn’t really purposed it but together, inspired by the BlinkStick documentation we wrote a script which authenticates with Gmail, then checks every 30 seconds to see if there’s any unread mail, if there is the LED will flash red three times. The script we created is below:

https://myaccount.google.com/security#activityimport urllib
import feedparser
import time
from blinkstick import blinkstick

username = "[email protected]"
password = "gmailpassword"

\_URL = "https://mail.google.com/gmail/feed/atom"
bstick = blinkstick.find_first()
greenCol = "#0AFC12"

class my_opener(urllib.FancyURLopener):

       def get_user_passwd(self,host,realm,clear_cache=0):
              return (username,password)

def auth():
'''The method to do HTTPBasicAuthentication'''
opener = my_opener()
f = opener.open(\_URL)
feed = f.read()
return feed

def readmail(feed):
'''Parse the Atom feed and print a summary'''
atom = feedparser.parse(feed)
record = len(atom.entries)

       print("")
       print(atom.feed.title)
       print("You have %s new mails" % len(atom.entries))


       if bstick is not None and len(atom.entries) > 0:
              bstick.morph(hex=greenCol)

       return record

if **name** == "**main**":
while True:
f = auth()
valOld = readmail(f)

              starttime = time.time()
              time.sleep(5.0 - ((time.time() - starttime) % 5.0))

              valNew = readmail(f)

              if valOld == valNew:
                     pass
              else:
                     bstick.pulse(name="green", repeats=3,
                                  duration=100)
                     bstick.morph(hex=greenCol)








              starttime = time.time()
              time.sleep(5.0 - ((time.time() - starttime) % 5.0))
              f = auth()
              readmail(f)