Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lcsp

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lcsp

  • 1.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

lcsp

GitHubActions codebeat badge Gem Version Gem Downloads

About

A tool for showing and counting solutions from LeetCode.

How to use

Installation

Download gem from RubyGems
$ gem i lcsp
As local installed gem

Build and install gem from sources:

$ gem build lcsp.gemspec
$ gem i lcsp

Print solution

You need to provide 3 arguments for run print command:

ParameterDescriptionExample
userGitHub user namefartem
repoRepository nameleetcode-ruby
numberNumber of problem11

One of valid input variants be like:

$ lcsp print --user=fartem --repo=leetcode-ruby --number=11

Count solutions

You need to provide 2 arguments for run count command:

ParameterDescriptionExample
userGitHub user namefartem
repoRepository nameleetcode-ruby

One of valid input variants be like:

$ lcsp count --user=fartem --repo=leetcode-ruby

Clean local cache

Just run next command from any folder:

$ lcsp clean

Contacts

You can see actual author contacts by following command:

$ lcsp author

Version

If you need to check installed version of lcsp, run from shell:

$ lcsp author

How to write your own LCSPFinder

Read before start

lcsp works with custom finders - classes that should placed in your project and that will perform search locally.

You need to write finder classes in Ruby because only this format accepting right now, but all work around search and parse for your repository you can place in classes/scripts/files in any other programming language.

One of the correct and working example available by this link.

Template class

path and number are default parameters that are presenting for every repository. This arguments describes user needs and gives you parameters to search.

# frozen_string_literal: true

module LCSP
  # Solutions finder.
  class LCSPFinder
    # @param {String} path
    # @param {String} number
    def initialize(path, number)
      @path = path
      @number = number
    end

    # @return {String}
    def solution
    end
  end
end
Reference class example
# frozen_string_literal: true

module LCSP
  # Solutions finder.
  class LCSPFinder
    # @param {String} path
    # @param {String} number
    def initialize(path, number)
      @path = path
      @number = number
    end

    # @return {String}
    def solution
      dirs = []
      fill_directories(@path, dirs)

      dirs.each do |directory|
        ::Dir.foreach(directory) do |entry|
          return "#{directory}/#{entry}" if entry.start_with?(@number)
        end
      end
    end

    # @param {String} path
    # @param {String[]} dirs
    def fill_directories(path, dirs)
      ::Dir.foreach(path).reject { |name| name.start_with?('.') }.each do |entry|
        unless ::File.file?("#{path}/#{entry}")
          dirs << "#{path}/#{entry}"
          fill_directories("#{path}/#{entry}", dirs)
        end
      end
    end
  end
end

How to write your own LCSCCounter

Read before start

lcsc works with custom counters - classes that should placed in your project and that will perform count locally.

You need to write counter classes in Ruby because only this format accepting right now, but all work around search and parse for your repository you can place in classes/scripts/files in any other programming language.

One of the correct and working example available by this link.

Template class

path are default parameter that are presenting for every repository. It is a path to repository in cache.

# frozen_string_literal: true

require 'find'

module LCSC
  # Solutions counter.
  class LCSCCounter
    # @param {String} path
    def initialize(path)
      @path = path
    end

    # @return {Integer}
    def count
      dir_sub = "#{@path}/lib"

      easy = find_for_dir("#{dir_sub}/easy")
      medium = find_for_dir("#{dir_sub}/medium")

      easy + medium
    end

    private

    def find_for_dir(dir)
      ::Find.find(dir).count { |file| ::File.file?(file) }
    end
  end
end
Reference class example
# frozen_string_literal: true

module LCSC
  # Solutions counter.
  class LCSCFinder
    # @param {String} path
    def initialize(path)
      @path = path
    end

    # @return {Integer}
    def count
    end
  end
end

Contributors

  • @fartem as Artem Fomchenkov

FAQs

Package last updated on 06 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc