> ## Content Index
> Fetch the complete content index at: https://cosh.nitk.ac.in/ghost-blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# CodePal
- URL: https://cosh.nitk.ac.in/ghost-blog/codepal/
- Published: 2022-03-21T13:23:47.000Z
- Updated: 2022-03-22T06:19:25.000Z
- Author: Aditya Chirania
- Tags: VS code

# Motivation

CodePal was originally proposed as a year-long project in IEEE-NITK by a team of 5\. The motivation behind this was the huge number of students and competitive programming enthusiasts on the Codeforces platform who used VS code. We pictured various features which, if provided to a user in the text editor, would save a lot of time during a contest and add great convenience while solving problems after a contest. Today, as of 28th January 2022, CodePal has over 1254 active users and has had a total of 2900 downloads. The long-term goal is to support all popular programming platforms and to provide more reliable tools to programmers to reduce their manual efforts.

# Introduction

CodePal is a Visual Studio Code Extension to help **Codeforces** Users **Code with Convenience**. This extension is specially for people who want to save time in a live Codeforces contest and up-solve problems comfortably. This extension responds quickly to users. It can swiftly filter through the problem list by specifying tags and ratings, create folders for contests and problems containing sample tests of each problem in them and compile and run tests automatically. For added convenience, we’ve created features to directly open problem statements and submission pages on the default browser.

# ****Brief Overview of Technologies Used**

## ****NodeJS**

- Node.js is an open-source, cross-platform, back-end, [JavaScript](https://en.wikipedia.org/wiki/JavaScript?ref=cosh.nitk.ac.in) runtime environment that runs on the [V8 engine](https://en.wikipedia.org/wiki/V8%5F%28JavaScript%5Fengine%29?ref=cosh.nitk.ac.in) and executes JavaScript code outside a [web browser](https://en.wikipedia.org/wiki/Web%5Fbrowser?ref=cosh.nitk.ac.in). Node.js lets us use JavaScript to write command line tools and for [server-side scripting](https://en.wikipedia.org/wiki/Server-side%5Fscripting?ref=cosh.nitk.ac.in)—running scripts server-side to produce [dynamic web page](https://en.wikipedia.org/wiki/Dynamic%5Fweb%5Fpage?ref=cosh.nitk.ac.in) content before the page is sent to the user’s web browser. In our case, to the VSCode editor.
- It is only with NodeJS we can perform API calls to Codeforces to get all the features of our extensions. We also use NodeJS to scrape data from the internet.

## ****Codeforces API**

- The [Codeforces API](https://codeforces.com/apiHelp?ref=cosh.nitk.ac.in) is extremely useful and the bulk of our features perform API calls to Codeforces to get useful information.
- But it does not provide everything. Our extension uses a small amount of web scraping of the Codeforces website to get the data the API does not provide for example test cases for a problem.
- The documentation of the Codeforces API is small but clear.

## ****TypeScript**

- [TypeScript](https://www.typescriptlang.org/?ref=cosh.nitk.ac.in) is a typed superset of JavaScript that compiles to plain JavaScript. It offers classes, modules, and interfaces to help you build robust components.
- TypeScript code is transformed into JavaScript code via the TypeScript compiler or [Babel](https://babeljs.io/?ref=cosh.nitk.ac.in). This JavaScript is clean, simple code which runs anywhere JavaScript runs: In a browser, on Node.JS or in apps. In our case, the final JavaScript file will run on Node.JS.
- Since there is compilation, TypeScript makes it much easier to debug your code compared to JavaScript.

## ****VS Code API**

- This is the main reason why VS Code is popular. The [VS Code API](https://code.visualstudio.com/api?ref=cosh.nitk.ac.in) has a plethora of useful features that not only give us a lot of control over the environment but also make it quite easy for us to understand and code.
- The organized tree-view, context menus, key-bindings, input boxes etc, are some of the API features that have been used in this extension.
- It cannot be stressed enough how important and useful VS Code API TypeScript documentation is. It is concise, clean and extremely informative. It was heavily referenced in this project.

# ****Challenges Faced**

We started with a team of 5, in which 3 of the team members had no idea about JavaScript or VS Code. To start off we focused on learning the basics to start approaching the project. The most crucial things we focused upon were:

- JavaScript, TypeScript and their differences
- Asynchronous Programming (async/await, Promises and Callbacks)
- Understanding how the event queue and the call stack worked in JavaScript
- VS Code API Documentation

We also had no idea about whether to start building the extension in Typescript or JavaScript. TypeScript was a language we had only known to be similar to JavaScript but had no idea about what it specifically was. Further, we approached authors of other extensions like [CPH](https://marketplace.visualstudio.com/items?itemName=DivyanshuAgrawal.competitive-programming-helper&ref=cosh.nitk.ac.in) on the VS Code Marketplace to educate ourselves more about this choice. We learned that TypeScript was JavaScript with enforcement of data types and as codebases grow larger, it becomes very difficult to trace errors without the enforcement of types.

Next, we also had only limited public APIs offered by the Codeforces platform. The features we wanted to support weren't all available. Hence we decided to combine the usage of web scraping and API calls to build our extension. We also utilized the way we processed our API responses to bring out useful information for a user. For example, we needed to show users indications of which problems they had attempted and which they hadn't. We accomplished this with the help of an API response containing all available problems on Codeforces and a response containing all submissions statistics of a user.

Apart from fetching useful information for the user, we also had to create reliable tools within the extension (ex: automatic code execution and testing, stress testing) that could save ample time for a user.

We were keen on making our extension as swiftly responsive as possible and had to make sure we optimize any processing we do to achieve the same.

Since we planned to publish our extensions and were hoping for external contributors as well we created a CI/CD pipeline to ensure uniform code style (using linter) as well. We published a blog on Codeforces about our extension to promote and receive valuable feedback about it. Based on the feedback we received we made subsequent releases to support more features and languages in our extension.

When creating a project that relies on scraping from external sources, it is important to note that the maintainers have to be responsive to any changes the external sources make (although not frequent) to their sites. For instance, Codeforces included an RCPC token wall sometime after we had published our extension (more info here: [https://codeforces.com/blog/entry/80135](https://codeforces.com/blog/entry/80135?ref=cosh.nitk.ac.in)). This basically means that the codeforces website checks for RCPC cookies before returning any public information also. This is to help against Denial of Service Attacks. Hence if RCPC cookies were not set in any HTTP request, codeforces would send back a HTML file containing sufficient information to calculate (using slowAES decryption) and set an RCPC cookie for subsequent requests. Hence our extension had stopped responding when this check was added. Hence we had to release subsequent updates that would calculate and set this cookie before scraping from codeforces.

There was also an instance when we noticed Codeforces had been adopting a different naming convention for their HTML divisions on their older problem pages. Hence the maintainers must respond quickly in projects to do with scraping and make their project be up to data and in sync with the external source.

# Demo

****Enter Handle in settings and view problems, contests and profile, with submission status on each problem.**

![](https://cosh.nitk.ac.in/ghost-blog/content/images/2022/03/gif1.gif)

****Create Problem/Contest Folders inclusive of all sample tests, compile and run automatically, get comprehensive verdicts and view problem statements and submission webpages.**

![](https://cosh.nitk.ac.in/ghost-blog/content/images/2022/03/gif2.gif)

****Filter Through Problems.**

![](https://cosh.nitk.ac.in/ghost-blog/content/images/2022/03/gif3.gif)

****Stress Testing your Code.**

![](https://cosh.nitk.ac.in/ghost-blog/content/images/2022/03/gif4.gif)

# ****Languages Supported**

- C++ (compiler : g++)
- C (compiler : gcc)
- Java (compiler : javac)
- Python
- Note : You may add additional compilation flags through the codepal settings (example : -std=c++14) and also choose between python, python2 or python3 depending upon the python command you use on your system to run.

# ****Operating Systems Supported**

- Windows
- Linux
- MAC

# ****Conclusion**

Building a VS Code extension is a great way to understand how such a popular code editor like VS Code works.

- You can install our extension [here](https://marketplace.visualstudio.com/items?itemName=IEEE-NITK.codepal&ref=cosh.nitk.ac.in).
- Please do try it and give your feedback. If you face issues or bugs, please file an issue [here](https://github.com/IEEE-NITK/CodePal/issues?ref=cosh.nitk.ac.in).
- To know more about CodePal and its codebase, you may visit its public repository [here](https://github.com/IEEE-NITK/CodePal?ref=cosh.nitk.ac.in).

# ****Maintainers**

- [Aditya Chirania](https://github.com/adityachirania?ref=cosh.nitk.ac.in)
- [Niranjan S Yadiyala](https://github.com/niranjansy?ref=cosh.nitk.ac.in)
- [Praveen Reddy](https://github.com/lomadapraveenreddy?ref=cosh.nitk.ac.in)
- [Chaithanya Shyam](https://github.com/Dragonado?ref=cosh.nitk.ac.in)
- [Janmansh Agarwal](https://github.com/Janmansh?ref=cosh.nitk.ac.in)