github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

leah / tinytinyurl

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 41
    • 3
  • Source
  • Commits
  • Network (3)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: 61e59ce

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A very very simple sinatra app for shortening URLs. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

first. a tiny url thing. 
leah (author)
Fri Apr 10 00:15:22 -0700 2009
commit  61e59ced74d04e7d46e090b2faee35cdc1970972
tree    4a346b1967e7d9c03a78dc840277c092753ba1b0
tinytinyurl / tinytiny.rb tinytiny.rb
100644 44 lines (39 sloc) 0.894 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#tinytiny.rb
# My first Ruby/Sinatra app, a URL shortener.
# by Leah Culver (http://github.com/leah)
require 'rubygems'
require 'sinatra'
require 'sequel'
 
# Base36 encoded
BASE = 36
 
configure do
  DB = Sequel.sqlite
  DB.create_table :tinyurls do
    primary_key :id
    String :url
  end
end
 
get '/' do
  # Form for entering a fatty URL
  <<-end_form
<h1>Tiny tiny URLs!</h1>
<form method='post'>
<input type="text" name="url">
<input type="submit" value="Make it tiny!">
</form>
end_form
end
 
post '/' do
  # Put the fatty URL in the database and display
  items = DB[:tinyurls]
  id = items.insert(:url => params[:url])
  url = request.url + id.to_s(BASE)
  "Your tiny tiny url is: <a href='#{url}'>#{url}</a>"
end
 
get '/:tinyid' do
  # Resolve the tiny URL
  items = DB[:tinyurls]
  id = params[:tinyid].to_i(BASE)
  url = items.first(:id => id)
  redirect url[:url]
end
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server