Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Configuration

Adithya Dsilva edited this page May 16, 2020 · 4 revisions

This wiki page sets down how you can configure the tool, for its optimal performance. All configurations are done through the command cf config.

Three configuration files are created in folder $XDG_CONFIG_HOME/cf/ (refer FAQ section) on your computer. These files are:

  • sessions.json - Stores your login details, along with the current sessions cookies.
  • settings.json - Your custom preferences of the functioning of the tool are saved here.
  • templates.json - Data related to your template source codes are saved and stored in this.

Configuring login credentials

This is the most important step that has to be done, to fetch contests in groups and private gyms as well as to submit source files directly from the terminal.

Your configured credentials are stored in the sessions file, and the password is encrypted using AES encryption. However, do note that, your account is considered compromised if the sessions.json file is taken over by someone else, as the password can be easily decrypted. The encryption has only little benefits over storing the password as plain text.

demo

Logging in is pretty simple! Selecting Login to codeforces from the menu that appears, you will be prompted to enter your login credentials. If login is successful, your session is saved with a expiration period of one month. Once session expires, the tool tries to automatically re-login using the saved login details.

Adding a new template file

Templates are very important configuration that should be completed, without which source files can neither be tested, nor can they be submitted to Codeforces through the tool.

This is because, the tool determines the compilation/execution commands to run the source file against the tests through the configured data in the template(s). Also, to submit the source file, the language id is necessary, which is also configured in the template(s) data.

demo

To add a template select 'Add new code template' from the selection list. You will have a series of prompts before you, which will guide you step by step in the addition of the new template.

First, select the language of the template file you wish to add. In my case (the GIF above), it was G++17 7.3.0. This will be the language all codes of this template will be submitted as, to the Codeforces server.

Next, enter the (relative or absolute, both work fine) path to the template file. In my case, the template file was stored at '~/Documents/template.cpp'. Make sure your entered path matches the OS specific path separator settings (/ on Linux/macOS and \ on windows).

This is what my sample the template.cpp file in the GIF looks like. For details on various variable placeholders available, visit the [Variables Reference](https://github.com/infixint943/cf/wik/Variables Reference#predefined-variables) section.

/*
Generated with (the amazingly, awesome) infixint943/cf tool
    Author  :   ${handle}
    When    :   ${date} ${time}
    Problem :   ${contest}${problem}
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    
    
    return 0;
}

Of course, you could define your own templates or choose not to use the placeholders at all.

Now, you'll be prompted to set the template alias. The alias is simply an unique name you choose to give this template, so that all future functions will refer to this template by it's alias. Be sure to give it an understandable name, as it may come handy.

In the example above, we named the template Default (C++). However, you are free to choose and give it any name you want!

Next, you have to configure the prescript. The prescript is what is run only once, before testing the source files against the sample inputs. Generally, the prescript is used for compiling the selected source file. However, in few languages, compiling the source code is not necessary to run it, so this space can be left blank and will be omitted.

In the above, the prescript was g++ -std=c++17 ${file} to compile the chosen source file. You could choose to add more flags, and could also set the name of the compiled binary file.

Next comes script. This is the command to run your compiled binary file / source code. This command will be run for each sample test case present. Note that, you need not redirect input or output, as they are auto redirected by the tool.

In the GIF above, the script was simply ./a.out which is the Linux way of executing compiled binaries. Python users could set the script to python3 ${file} which would execute their source file directly.

Final part, is configuring the postscript, which, similar to prescript, is run only once. It is executed after testing of source code against all sample tests is finished. This is generally to clean up residual files/binaries that might have been created that you wish to remove.

In the example GIF, the postscript to set to rm a.out, which deletes the compiled binary file (a.out) from the current folder. Again, as not all languages require generation of binary files to be executed, this field can be left blank too!

Removing added code template

Currently, there exists no way of editing a configured template configuration using the tool, so you will have to delete the template configuration and add a new one again. You could also choose to edit the templates.json file if you want to edit any template.

To remove an added template, select 'Remove code template' from the selection list. Another selection list is displayed, with alias names of all configured templates. Select the template alias you wish to delete and press ENTER. The template alias will then be deleted from the templates.json file.

However, note that the actual template file will be left untouched as it were.

Configuring miscellaneous preferences

This configuration serves to configure the internal workings of the tool up to some extent. All configurations in this section are saved to the settings.json file.

The currently supported configurations that can be modified are:

  • Configuring default template - If default template is configured, cf gen will generate the default template that you have set, without giving a prompt to select the desired template. You can definitely override this settings and bring up the prompt menu by passing the flag --all.
  • Running gen after fetch - If set to yes, the default template (configured in the previous option) will be auto generated for each problem fetched. Note that, the default template has to be configured for auto generation of template file to work.
  • Set host domain - Instead of fetching data from https://codeforces.com (the default option), you could configure the tool to fetch all data from an alternative domain (for example https://codeforc.es). Note that, this option is currently depreciated and may be removed in future releases.
  • Set proxy - As the name says, this tool allows you to configure proxy to be used by the tool. The proxy entered must satisfy format protocol://host[:port]. If not configured, the environment configured proxy will be used instead.