Giter Site home page Giter Site logo

url-shortner's Introduction

URL Shortener

A simple CLI tool that takes in an arbitrarily-long URL and will shorten it for the user. Subsequent users can then give the short URL back to the tool and be redirected to the original URL.

Overview

  • Written in Ruby.
  • Uses the launchy gem to allow us to pop open the URL in the browser without actually building in the browser.
  • To see how it works:
    • make sure PostgreSQL is running.
    • run bundle install from within the project directory.
    • run ./setup.
      • if you get a permission error, run chmod +x setup and then ./setup again.
    • run rails runner bin/cli.
    • when prompted for an email: enter one of the emails already in the database, which you can find in db/seeds.rb.

Features

  • Tracks clickthroughs for business analytics.
  • Allows users to choose from a set of predefined TagTopics for links (e.g., news, music, etc.).
    • Allows users to search for the most visited links by topic.
  • Spam protection: users cannot submit more than 5 URLs in a single minute.
  • A premium option is available for users: the number of total URLs non-premium users can submit is limited to 5.
  • Stale URLs can be purged from the database with the ShortenedUrl::prune method or by running the Rake Task prune.rake in lib/tasks.

Concepts (personal use)

  • building a CLI tool
  • launchy gem
  • Base64 encoding (SecureRandom)
  • Associations
    • join table
    • dependent: :destroy
  • ActiveRecord methods
    • exists?
    • ::create! vs ::new & #save! -> use create instead of new/save syntax in factory methods because the other class calling the factory method will get returned to it a "true" instead of the object
    • #attributes
  • lazy evaluation of ActiveRecord::Relation objects
  • ActiveRecord Query Interface
    • select
      • distinct chained onto select
    • where
      • find, find_by, find_by_#{attribute}, etc. all return the first matching instance from the DB, where returns a collection of instances, regardless of the number.
    • joins
    • group
    • limit
    • order
      • Rails 6 will need us to wrap our raw SQL in Arel.sql
  • ActiveRecord time methods
    • Using the created_at column to interact with Time objects
  • ActiveModel::EachValidator
    • custom url validation
  • client-side email validation
  • rails runner: loads the Rails environment for us, so we'll be able to use classes without requiring them explicitly. It also connects to the DB so we can query tables
  • creating a Rake task

url-shortner's People

Contributors

sashadev-sky avatar

Stargazers

 avatar

Watchers

 avatar  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.