Skip to content

Instantly share code, notes, and snippets.

@iHiD
Last active June 10, 2017 15:05
Show Gist options
  • Save iHiD/e6c20655318fa66528ba to your computer and use it in GitHub Desktop.
Save iHiD/e6c20655318fa66528ba to your computer and use it in GitHub Desktop.
Baruco 2014 Live Coding Talk on Propono.
require 'propono'
Propono.config do |config|
config.access_key = "AKIAIPE2MSOM5ZFGQBCQ"
config.secret_key = "KMU2VcLmezHk9lZGiXumdmetO6wK5J9gdGr+APJl"
config.queue_region = "eu-west-1"
end
require 'twitter'
@twitter = Twitter::REST::Client.new do |config|
config.consumer_key = "OG9Zkag09onRe7b5ZLecO7HGb"
config.consumer_secret = "Z2sgexKehuSTc6zKNr8nl1ryb8DyuRUPUNr7wEn8c5Qoq4LSZl"
config.access_token = "15120222-J3y92zn5Oi7t3OgvcpBlH81voIkFA14PfcYQ6VYH7"
config.access_token_secret = "oZ9IcTOylqiSIN0dmg4hEZxLc1JIeXO0wSyAfco4n7xy5"
end
# http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
# http://bit.ly/baruco14
webpage = <<EOS
<html>
<head>
<style>img {width:100px;float:left}</style>
</head>
<body>
<div id="images"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var es = new EventSource('/stream')
es.onmessage = function(e) { $('#images').append('<img src="'+e.data+'"/>') }
</script>
</body>
</html>
EOS
require 'sinatra'
set server: 'thin', connections: []
get '/' do
erb webpage
end
get '/stream', provides: 'text/event-stream' do
stream :keep_open do |s|
settings.connections << s
end
end
require_relative 'config'
Propono.config.application_name = "baruco14-faces"
Thread.new do
Propono.listen_to_queue(:handles) do |handle|
src = @twitter.user(handle).profile_image_url(:bigger)
settings.connections.each do |c|
c << "data: #{src}\n\n"
end
end
end
require_relative 'config'
Propono.config.application_name = "baruco14-follower"
p "Ready to go"
Propono.listen_to_queue(:handles) do |handle|
p "Following: #{handle}"
@twitter.follow(handle)
end
require_relative 'config'
Propono.config.application_name = "baruco14-lists"
p "Ready to go"
Propono.listen_to_queue(:handles) do |handle|
p "Adding to list: #{handle}"
@twitter.add_list_member('iHiD', 'baruco-2014', handle)
end
require_relative 'config'
Propono.publish(:handles, ARGV[0], async: false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment