Skip to content

Instantly share code, notes, and snippets.

@philhawksworth
Created March 7, 2011 12:35
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 philhawksworth/858447 to your computer and use it in GitHub Desktop.
Save philhawksworth/858447 to your computer and use it in GitHub Desktop.
require 'base62'
...
# mint a URI for a lolly
post '/mint' do
message = params[:message].gsub(/'/,"''")
db.execute( "insert into lollies (message, image) values ('"+ message +"','#{params[:lolly]}')" )
if request.xhr?
id = db.execute( "SELECT last_insert_rowid() FROM lollies" )[0].to_s()
id = id.to_i.base62_encode
#prepare a clip and link to tweet.
link = ' http://vlolly.com/'+id
if message.length + link.length > 140
link = '...' + link
end
clip = escape(message[0, 140 - link.length] + link)
'<div>Here\'s your link, send it to someone who deserves some sugar <a href="/'+id+'">http://vlolly.com/'+id+'</a></div><div> Or perhaps you might like to <a href="http://twitter.com/home?status='+clip+'">tweet it.</a></div>'
else
erb :yours
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment