pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Ruby pastebin - collaborative debugging tool View Help


Posted by monitron on Wed 22 Apr 05:31
report abuse | download | new post

  1. require 'rubygems'
  2. require 'twitter'
  3. require 'serialport'
  4.  
  5. ser = SerialPort.new("/dev/cu.usbserial-A6007Db4", 9600)
  6. httpauth = Twitter::HTTPAuth.new('username', 'password') # Should use OAuth
  7. twitter = Twitter::Base.new(httpauth)
  8. ser.read_timeout = -1 # Don't block waiting for new data
  9.  
  10. tweets = [
  11.           "Are you yelling because you're losing or winning? I honestly can't tell.",
  12.           "Aren't you people supposed to be working?",
  13.           "Is someone having a baby in here?"
  14.          ]
  15.  
  16. ser.read # clear out any cruft on the line
  17. puts "Ready..."
  18.  
  19. while true
  20.   data = ser.read # This returns any serial data available or "" if none
  21.   unless data.index("LOUD").nil?
  22.     puts "Loudness Detected!"
  23.     twitter.update(tweets[rand(tweets.size)])
  24.     puts "Cooling off for 10 minutes"
  25.     sleep 600
  26.     ser.read
  27.     puts "Cleared. Done cooling off"
  28.   end
  29.   sleep 10
  30. end

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post