ghoudiy's blog

By ghoudiy, 7 weeks ago, In English

cfkit is a lightweight and efficient CLI tool. It’s easy to use, fast and works across platforms.

It's written in Python. You can explore the source code on my GitHub repository: https://github.com/ghoudiy/cfkit/

Features:

  • Efficient Result Comparison: Compare floating-point numbers, allow any-order comparison, or use strict comparison.

  • High Traffic Resilience: Parses problem data even under server load.

  • Language Support: Compatible with all programming languages used on Codeforces.

  • Fetch Problem Samples: Retrieves sample test cases for problems.

  • Local Compilation and Testing: Compile and test solutions locally.

  • Template-Based Code Generation: Generate code with templates, including timestamps and author info.

  • Contest Problem Stats: Lists problem statistics for specific contests.

  • Enhanced CLI Output: Distinguish correct and incorrect results easily with colored output.

Installation

Ensure Python is installed on your system. Then, run these commands in your terminal:

  • pip install cfkit

  • cf config all

And your are ready to go!

Usage

cf run 2000a.cpp    Compiles and tests your solution locally,
                    fetching and parsing missing sample test cases,
                    then comparing your output to the expected results with highlighted differences.

Options:

-o: Accept answers in any order.
-c: Run only custom samples or use custom input without comparing results.
-s: Does not ignore extra spaces during comparison.
-n: Does not ignore extra new lines during comparison.
-v: Does not print input, output and answer.
-a: Does not print answers.

cf gen 2000a    Generates a code file from the default template.

How to Set Up a Default Template?

If you'd like to create a default template for C++ (for example), follow these steps:

  • Navigate to the template directory: $HOME/.cfkit/templates/cpp/
  • Create a file named default.cpp in this folder.
  • Inside default.cpp, write your desired C++ template code. This will be used automatically whenever you generate a new C++ file with cfkit.

In your template code, you can include various placeholders. (Read documentation here)

cf parse 2000   Fetch all sample test cases from a contest.

FAQ

Q: How do I add a new test case?
A: To add a new test case, create two files: inK.txt and outK.txt, where K is a number. If you're using Linux or MacOs, omit the .txt extension (e.g., in1, ou1, in2, out2). You can create additional test cases by increasing the value of K (e.g., in1.txt, out1.txt, in2.txt, out2.txt).

Q: How to update cfkit package?
A: pip install --upgrade cfkit

Q: How to change the current compiling or executing command in cfkit?

R: Go to .cfkit/languages.json in your home folder, find your language, and edit the command as needed.

Notes

  • Memory and time usage may not be precise.
  • If you're calculating memory and time usage, it's recommended to avoid spaces in file paths.
  • If you encounter errors during compilation or execution, navigate to $HOME/.cfkit/languages.json and modify the command as needed.
  • To customize the program’s behavior, run cf config edit. This will open the configuration file in your default text editor for easy adjustments.
  • To add new templates, navigate to $HOME/.cfkit/templates/LANGUAGE_FOLDER/ and create your template file there. When you run cf gen, cfkit will prompt you to choose a template if no default is set.
  • If you encounter an error during compilation or execution, you can modify the command in $HOME/.cfkit/languages.

Finally

I’m always open to feedback, suggestions, and collaboration! If you have any questions or want to get in touch, feel free to reach out:

Email: ghoudi.dev@gmail.com
Support: If you’d like to support my work and help me continue creating cool programs, you can do so here.
Looking forward to hearing from you! :)

Tags cli
  • Vote: I like it
  • +49
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ghoudiy (previous revision, new revision, compare).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ghoudiy (previous revision, new revision, compare).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone tested the program?

»
7 weeks ago, # |
Rev. 2   Vote: I like it +16 Vote: I do not like it

will it work during contests?

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I tested it, and it works perfectly (it parses from the mirroir website first, and then the official website if it fails)! (You only need to connect to the contest page once for this to work for all problem.) Alternatively, you can save the problem page (e.g., codeforces.com/contest/2000/problems) as an HTML file and pass it to the terminal using the -l option. This will parse all the test cases.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Is it clear or should i share a very short video how to do that?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Have you tested it in the current contest?

»
7 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

Would be great it if support submitting as well

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I actually writed the code of submitting the solution (and it is working), but not now

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Similar but much more feature rich tool already exist: cpbooster. Among other things, it works with almost all competitive programming platforms (via Competitive Companion browser extension), supports submitting, and has vim integration. :)

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I got this error g++: fatal error: cannot read spec file 'libsanitizer.spec': No such file or directory

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ghoudiy (previous revision, new revision, compare).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

thanks man