Code Monkey home page Code Monkey logo

ip_tracker's Introduction

Ip Tracker

Track and rank requesting IPs with Ruby.

Discussion

  • What would you do differently if you had more time? If had more time, I would also write a small Sinatra Web API just for providing a more real-life example and shipping this tracker as ruby gem to be imported in the Sinatra API.

  • What is the runtime complexity of each function? request_handled(ip_address]) => O(1)

count_entries(ips) => O(n2)

top100() => O(log n)

clear() => O(n)

  • How does your code work? My code work as object-oriented entity that is stores all requested ips in an attirbute called ips, and has instances methods implementing each one of the requirements. Besides, the method for ranking the 100-most frequent ips follows a concurrent approach in batches to deal with millions records in a quikier way. Moreover, added in auxiliary method to the raking for a better separation of concerns.

  • What other approaches did you decide not to pursue? I decided to not pursue an entirely concurrent-approach, which means that I could have made the ip storing and clearing as concurrent as the raking method is, but the gains in doing it seemed to be not much significant.

  • How would you test this? I would test this by writing benchmark comparisions. I could implement tests like that by writing specific test cases with RSpec.

Setup

# install ruby 3.0.2
bundle install
bundle exec rspec spec/tracker_spec.rb # for testing

Run

irb
require_relative './tracker'
tracker = Tracker.new
tracker.request_handled('145.87.2.109')
tracker.top100()
tracker.clear()
tracker.top100()

ip_tracker's People

Contributors

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