Skip to content

Commit

Permalink
slides for scotruby
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Apr 9, 2011
1 parent 40d6e07 commit d61008d
Show file tree
Hide file tree
Showing 33 changed files with 5,854 additions and 3 deletions.
5 changes: 5 additions & 0 deletions config.ru
@@ -0,0 +1,5 @@
require 'showoff'
require './example'

use Example
run ShowOff
115 changes: 115 additions & 0 deletions example.rb
@@ -0,0 +1,115 @@
require 'sinatra/base'
require 'capture_stdout'
require 'escape_utils'
require 'slim'
require 'sass'
require 'coffee-script'
require 'eventmachine'

class EventSource
include EventMachine::Deferrable

def send(data, id = nil)
data.each_line do |line|
line = "data: #{line.strip}\n"
@body_callback.call line
end
@body_callback.call "id: #{id}\n" if id
@body_callback.call "\n"
end

def each(&blk)
@body_callback = blk
end
end

class Example < Sinatra::Base
scope, line, subscribers = binding, 1, []
enable :inline_templates, :logging, :static
set :public, File.expand_path('../public', __FILE__)

def escape(data)
EscapeUtils.escape_html(data).gsub("\n", "<br>").
gsub("\t", " ").gsub(" ", "&nbsp;")
end

get '/events.es' do
content_type request.preferred_type("text/event-stream", "text/plain")
body EventSource.new
subscribers << body
EM.next_tick { env['async.callback'].call response.finish }
throw :async
end

get('/events') { slim :html }
get('/events.js') { coffee :script }
get('/events.css') { sass :style }

post '/run' do
begin
result = nil
stdout = capture_stdout do
result = eval("_ = (#{params[:code]})", scope, "(irb)", line)
line += 1
end
stdout << "=> " << result.inspect
rescue Exception => e
stdout = [e.to_s, *e.backtrace.map { |l| "\t#{l}" }].join("\n")
end
source = escape stdout
subscribers.each { |s| s.send source, line }
''
end
end

__END__

@@ script

$(document).ready ->
input = $("#input")
log = $("#log")
output = (str) ->
log.append str
log.append "<br>"
input.attr scrollTop: input.attr("scrollHeight")

$("#form").live "submit", (e) ->
value = input.val()
$.post '/run', code: input.val()
output "&gt;&gt; #{value}"
input.val ""
input.focus()
e.preventDefault()

src = new EventSource('http://localhost:9090/events.es')
src.onmessage = (e) -> output e.data

@@ html
html
head
title brirb
link href="/events.css" rel="stylesheet" type="text/css"
script src="/jquery.min.js" type="text/javascript"
script src="/events.js" type="text/javascript"
body
#log
form#form
| &gt;&gt;&nbsp;
input#input type='text'

@@ style
body
font:
size: 200%
family: monospace
input#input
font-size: 100%
font-family: monospace
border: none
padding: 0
margin: 0
width: 80%
&:focus
border: none
outline: none
10 changes: 9 additions & 1 deletion intro/00_intro.md
Expand Up @@ -6,6 +6,14 @@
!SLIDE bullets
# Me #

* Potsdam/Berlin, Germany
* [rkh.im](http://rkh.im/), [github/rkh](http://github.com/rkh), [@konstantinhaase](http://twitter.com/konstantinhaase)
* Student at Hasso Plattner Institute
* Ruby dev at [Finnlabs](http://finn.de)
* Sinatra, Rubinius, Rack

!SLIDE bullets smallcode
# Me #

* Sinatra, tons of small libs
* Tilt, Rubinius, Rack, Rails, ...
* ![almost-sinatra](almost-sinatra.png)
Binary file added intro/almost-sinatra.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions public/jquery.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion showoff.json
@@ -1,5 +1,5 @@
{
"name": "No Title",
"name": "Real Time Rack",
"sections": [
{ "section": "intro" },
{ "section": "slides" },
Expand Down
Binary file added slides/Y-U-NO-have-memes-in-there.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d61008d

Please sign in to comment.