GithubHelp home page GithubHelp logo

chrise86 / shortener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bbtfr/shortener

0.0 1.0 0.0 12.91 MB

A Rails Engine that makes it easy to create shortened URLs for your rails application

Home Page: http://demo-shortener.herokuapp.com/

License: MIT License

shortener's Introduction

Shortener

Shortener is a Rails Engine Gem that makes it easy to create and interpret shortened URLs on your own domain from within your Rails application. Once installed Shortener will generate, store URLS and “unshorten” shortened URLs for your applications visitors, all whilst collecting basic usage metrics. Part of the code comes from jpmcgrath/shortener & johnthethird/shortener.


see the demo page via demo-shortener.herokuapp.com/ and the source code is here, github.com/bbtfr/shortener-demo

Overview

The majority of the Shortener consists of three parts:

  • a model for storing the details of the shortened link;

  • a middleware to accept incoming requests and redirecting them to the target URL;

  • a helper for generating shortened URLs from controllers and views.

  • a frondend build with backbone.js & bootstrap

  • clicks tracking & compiling statistics

Some niceities of Shortener:

  • The middleware does a 301 redirect, which is the recommended type of redirect for maintaining maximum google juice to the original URL;

  • A unique alphanumeric code of generated for each shortened link, this means that we can get more unique combinations than if we just used numbers;

  • The link records a count of how many times it has been “un-shortened”;

  • The link can be associated with a user, this allows for stats of the link usage for a particular user and other interesting things;

  • The model spawns a new thread to record information to the database, allowing the redirect to happen as quickly as possible;

Future improvements:

  • There has not been an attempt to remove ambiguous characters (i.e. 1 l and capital i, or 0 and O etc.) from the unique key generated for the link. This means people might copy the link incorrectly if copying the link by hand;

  • The shortened links are found with a case-insensitive search on the unique key. This means that the system can’t take advantage of upper and lower case to increase the number of unique combinations. This may have an effect for people copying the link by hand;

  • The system could pre-generate unique keys in advance, avoiding the database penalty when checking that a newly generated key is unique;

  • The system could store the shortened URL if the url is to be continually rendered;

  • Some implementations might want duplicate links to be generated each time a user request a shortened link.

Installation

You can use the latest Rails 3 gem with the latest Shortener gem. In your Gemfile:

gem 'jbuilder'
gem 'shortener', github: 'bbtfr/shortener'

# for the frondend
gem "backbone-on-rails"
gem "bootstrap-sass"

After you install Shortener run the generator:

rails generate shortener

This generator will create a migration to create the shortened_urls table where your shortened URLs will be stored, and it will also create a initializer file in config/shortener.

Then add those lines into your application.js & application.css

// javascripts
//= require bootstrap
//= require underscore
//= require backbone
//= require shortener

* stylesheets
*= require bootstrap
*= require shortener

And then edit initializer file config/shortener.rb, for example:

config.url_prefix = "/"

will match all the requests, or

config.url_prefix = "/s"

will match the requsets start with /s/ (eg: /s/abcde)

License

This project rocks and uses MIT-LICENSE.

shortener's People

Contributors

bbtfr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.