LeetCode to GitHub Sync

Visakh Vijayan
2 min readNov 16, 2023

--

A big part of the software engineering interview process is to show off your skills and how disciplined you are with coding overall. One of the first things an interviewer assesses is the coder’s GitHub profile.

But let's face it. It’s not easy to keep an active commit history on GitHub every time and that actually gives a feeling that the person is maybe NOT so sincere with coding. Well turns out there is a small hack to overcome this. But hey it will require you to be sincere in another form though.

As a coder, you are expected to code on a daily basis if you want to crack that first sweet and exciting job of yours. And one of the best platforms is Leetcode. If you are regular on LeetCode, this GitHub action could help you to an extent.

Aim

As you crack those questions on LeetCode, the solutions will be copied over and committed to a public repository of yours. And by doing this, your commit history will get populated to this —

Steps

  1. Make a new repository and name it something unique. I used the obvious one — leetcode
  2. Now go over LeetCode and inspect the network tab. In the Request headers section, you will find two keys csrftoken and LEETCODE_SESSION. Copy those values.
  3. Now head over to the GitHub Secrets section of your repository under Settings > Security > Actions > New Repository Secret
  4. Copy the values into keys LEETCODE_CSRF_TOKEN and LEETCODE_SESSION respectively
  5. Now go to the Actions tab and create a workflow file. Go ahead and name it anything. I named it the obvious sync_leetcode.yml
  6. Now remove everything in that file and copy-paste this into it —
name: Sync Leetcode

on:
workflow_dispatch:
schedule:
- cron: "0 8 * * 6"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Sync
uses: joshcai/leetcode-sync@v1.5
with:
github-token: ${{ github.token }}
leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }}
leetcode-session: ${{ secrets.LEETCODE_SESSION }}
destination-folder: my-folder
verbose: true
commit-header: '[LeetCode Sync]'

7. Once done you are ready to go. Go to the Actions tab once again and you will be able to see your newly created workflow. Click on Run Workflow and wait for the magic to happen.

8. Once done, you will see the solutions from LeetCode appear in your repository folder-wise.

The best part is, it pulls all solutions from the past and creates commits on the solved date. So the commit history of your repository gets instantly populated. Pretty neat!

--

--

Visakh Vijayan

Techie from Kerala, India. Days are for coding, nights for weaving tales of tech, travel, and finance. Join me in exploring this multifaceted journey