Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changing direction...

  • Loading branch information...
commit 07b0bd17dac561382acc8e935ee3b4fd89d92762 1 parent 94725e8
@aaronlerch authored
View
2  Gemfile
@@ -2,6 +2,4 @@ source 'http://rubygems.org'
gem 'sinatra'
gem 'slim'
-gem 'redis'
gem 'json'
-gem 'rest-client'
View
73 app.rb
@@ -1,72 +1,21 @@
require 'sinatra'
require 'slim'
-require 'redis'
require 'json'
-require 'rest-client'
-require 'cgi'
-
-configure :development do
- uri = URI.parse('redis://localhost:6379')
- REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
-end
-
-configure :production do
- uri = URI.parse(ENV["REDISTOGO_URL"])
- REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
-end
-
-helpers do
- def parse_urls
- urls = {}
- for param in (request.query_string || '').split("&")
- values = param.split("=")
- next if values[0].nil? or values[1].nil?
- url = values[0].downcase
- next if url != 'url'
-
- urls[CGI::unescape(values[1].strip)] = nil
- end
-
- return urls
- end
-
- def resolve_url(url)
- resolved_url = url
- RestClient.head(url) do |response, request, result, &block|
- resolved_url = response.headers[:location] if response.code == 301
- end
- return resolved_url
- end
-
- def browser
- return "chrome" if request.user_agent =~ /chrome/i
- return "firefox" if request.user_agent =~ /firefox/i
- return "safari" if request.user_agent =~ /safari/i
- end
-end
+require 'base64'
get '/' do
slim :index
end
-get '/expand' do
- urls = parse_urls
- return if urls.empty?
-
- keys = urls.map { |key,value| "url:#{key}" }
- resolved_urls = REDIS.mget *keys # <- mget takes params, not an array
- REDIS.multi do
- urls.each_with_index do |pair, index|
- if resolved_urls[index].nil?
- resolved = resolve_url(pair[0])
- urls[pair[0]] = resolved
- REDIS.set "url:#{pair[0]}", resolved
- else
- urls[pair[0]] = resolved_urls[index]
- end
- end
- end
+get '/elongate' do
+ content_type 'application/json'
+ {
+ :original_url => params[:url],
+ :elongated_url => Base64.strict_encode64(params[:url])
+ }.to_json
+end
- content_type :json
- urls.to_json
+get '/:longurl' do
+ url = Base64.strict_decode64(params[:longurl])
+ redirect url
end
View
BIN  public/chrome-ext.png
Deleted file not rendered
View
BIN  public/firefox-ext.png
Deleted file not rendered
View
102 public/index.css
@@ -0,0 +1,102 @@
+body {
+ font-family: "HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif;
+ background-color: #fff;
+ padding-top: 60px;
+}
+
+#elongate {
+ margin-left: 10px;
+}
+
+.container {
+ text-align: center;
+ width: 960px;
+ margin: auto;
+}
+h1 small {
+ font-size: 0.4em;
+ font-style: italic;
+}
+.lengthen {
+ margin: auto;
+ padding-top: 50px;
+ width: 800px;
+}
+.lengthen p {
+ font-size: 26px;
+}
+input {
+ margin: 0em;
+ font: -webkit-small-control;
+ color: initial;
+ letter-spacing: normal;
+ word-spacing: normal;
+ line-height: normal;
+ text-transform: none;
+ text-indent: 0px;
+ text-shadow: none;
+ display: inline-block;
+ text-align: -webkit-auto;
+ -webkit-appearance: textfield;
+ padding: 1px;
+ background-color: white;
+ border: 2px inset;
+ border-image: initial;
+ -webkit-rtl-ordering: logical;
+ -webkit-user-select: text;
+ cursor: auto;
+ margin: 0;
+ vertical-align: baseline;
+ height: 35px;
+ padding: 4px;
+ font-size: 25px;
+ line-height: 35px;
+ color: #333;
+ border: 1px solid #888;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+ -webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
+ -moz-transition: border linear 0.2s, box-shadow linear 0.2s;
+ -ms-transition: border linear 0.2s, box-shadow linear 0.2s;
+ -o-transition: border linear 0.2s, box-shadow linear 0.2s;
+ transition: border linear 0.2s, box-shadow linear 0.2s;
+ -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
+ -moz-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
+ box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
+ width: 600px;
+}
+
+/* Google CSS Buttons */
+
+a.button {
+ color: #6e6e6e;
+ font: bold 20px Helvetica, Arial, sans-serif;
+ text-decoration: none;
+ padding: 15px 20px;
+ position: relative;
+ display: inline-block;
+ text-shadow: 0 1px 0 #fff;
+ -webkit-transition: border-color .218s;
+ -moz-transition: border .218s;
+ -o-transition: border-color .218s;
+ transition: border-color .218s;
+ background: #f3f3f3;
+ background: -webkit-gradient(linear,0% 40%,0% 70%,from(#F5F5F5),to(#F1F1F1));
+ background: -moz-linear-gradient(linear,0% 40%,0% 70%,from(#F5F5F5),to(#F1F1F1));
+ border: solid 1px #dcdcdc;
+ border-radius: 2px;
+ -webkit-border-radius: 2px;
+ -moz-border-radius: 2px;
+ height: 18px;
+}
+a.button:hover {
+ color: #333;
+ border-color: #999;
+ -moz-box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2) -webkit-box-shadow:0 2px 5px rgba(0, 0, 0, 0.2);
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
+}
+a.button:active {
+ color: #000;
+ border-color: #444;
+}
View
BIN  public/safari-ext.png
Deleted file not rendered
View
BIN  public/title.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
59 views/index.slim
@@ -1,32 +1,21 @@
doctype html
html
head
- title uniformresourcelocatorelongator.com :: the worlds most annoyingly long-named URL expander!
- css:
- body {
- font-family: "HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif;
- background-color: #fff;
- padding-top: 60px;
- }
- div#container {
- text-align: center;
- width: 960px;
- margin: auto;
- }
- h1 small {
- font-size: 0.4em;
- font-style: italic;
- }
- .upgrade {
- margin: auto;
- width: 400px;
- }
- .upgrade p {
- font-size: 26px;
- }
- div#extension {
- padding-top: 100px;
+ title uniformresourcelocatorelongator.com :: combating short URLs since 2012
+ link href=url("/index.css") rel='stylesheet'
+ script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript
+ javascript:
+ function do_elongate() {
+ $p = escape($.trim($('#url').val()));
+ if ($p === '') { return false; }
+ // TODO: get the elongated URL via ajax
+ return false;
}
+
+ $(function() {
+ $('#elongate').click(do_elongate);
+ $('#elongate-form').submit(do_elongate);
+ });
javascript:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-361923-7']);
@@ -37,19 +26,9 @@ html
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
body
- #container
+ .container
img src="/title.png"
- #extension
- - if !browser.nil?
- a href="#"
- img src="/#{browser}-ext.png"
- - else
- .upgrade
- p
- | Browser extensions are available for
- a href="https://www.google.com/chrome" Chrome
- | ,
- a href="http://www.mozilla.org/firefox" Firefox
- | , or
- a href="http://www.apple.com/safari/" Safari
- | - consider upgrading your browser!
+ .lengthen
+ form#elongate-form
+ input#url type='text' placeholder='Enter a URL to elongate'
+ a#elongate.button href='#' E l o n g a t e
Please sign in to comment.
Something went wrong with that request. Please try again.