Skip to content

Instantly share code, notes, and snippets.

@pk
Created May 27, 2014 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pk/0294cbe3cd8d14504fcf to your computer and use it in GitHub Desktop.
Save pk/0294cbe3cd8d14504fcf to your computer and use it in GitHub Desktop.
Privnote naive implementation
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'securerandom'
NOTES = {}
get '/' do
response = '<html><body>'
response << %Q{<h1>Create secret note</h1>}
response << '<form action="/note" method="POST" enctype="application/x-www-form-urlencoded">'
response << '<textarea cols="150" rows="30" name="note"></textarea><br/>'
response << '<button type="submit">Create</button>'
response << '</body></html>'
response
end
get '/note/:id' do |id|
note = NOTES[id] ? NOTES[id].to_s : 'Has been forgotten, like it would never existed...'
response = '<html><body>'
response << %Q{<h1>Your secret note</h1>}
response << %Q{<p>#{note}</p>}
response << '</body></html>'
NOTES.delete(id)
response
end
post '/note' do
id = SecureRandom.hex
note = params[:note]
NOTES[id] = note.to_s
response = '<html><body>'
response << %Q{<h1>Secret note created</h1>}
response << %Q{<p>Your secret note is be available at <a href="/note/#{id}">https://privnote.fry-it.com/note/#{id}</a> and will vanish when you tap that link...</p>}
response << '</body></html>'
response
end
delete '/note/:id' do |id|
NOTES.delete(id)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment