Giter VIP home page Giter VIP logo

ankit's Introduction

ankit

πŸ”¨ CSV export tool for Anki.

Anki

leetcode2anki

leetcode2anki will print CSV data from your LeetCode repository and corresponding question data. It use SQLite to store LeetCode question data. If data is not exist, it will be fetched from LeetCode API.

Therefore, you need to import CSV to your Anki.

Export LeetCode Repository to CSV

leetcode2anki -lang golang > leetcode.csv

Customize for your repository structure

If your LeetCode repository is different from mine, you need to change question and code function in leetcode2anki/main.go:

My LeetCode Repository structure:

LeetCode
β”œβ”€β”€ 0003
β”‚Β Β  β”œβ”€β”€ code.go
β”‚Β Β  └── code_test.go
β”œβ”€β”€ 0004
β”‚Β Β  β”œβ”€β”€ code.go
β”‚Β Β  └── code_test.go
└── 0007
 Β Β  β”œβ”€β”€ code.go
 Β Β  └── code_test.go
func question(path string, info os.FileInfo) (leetcode.Key, error) {
	if path == "." || !info.IsDir() {
		return nil, nil
	}
	// only handle directory in repository
	id, err := strconv.Atoi(path)
	if err != nil {
		return nil, filepath.SkipDir
	}
	// identify leetcode question by id
	return leetcode.KeyID(id), filepath.SkipDir
}

func code(path string, _ leetcode.Lang) (string, error) {
	fset := token.NewFileSet()

	f, err := parser.ParseFile(fset, filepath.Join(path, "code.go"), nil, parser.ParseComments)
	if err != nil {
		return "", err
	}
	// start from import declarations, then format code
	var w strings.Builder
	if err := format.Node(&w, fset, f.Decls); err != nil {
		return "", err
	}

	return w.String(), nil
}

Python example:

LeetCode
β”œβ”€β”€add-two-numbers.py
β”œβ”€β”€reverse-integer.py
└──two-sum.py
func question(path string, info os.FileInfo) (leetcode.Key, error) {
	if path == "." {
		return nil, nil
	}
	// skip directory in repository
	if info.IsDir() {
		return nil, filepath.SkipDir
	}

	filename := filepath.Base(path)
	ext := filepath.Ext(filename)
	// only handle python file
	if ext != ".py" {
		return nil, nil
	}
	// identify leetcode question by title slug: filename
	slug := strings.TrimSuffix(filename, ext)
	return leetcode.KeyTitleSlug(slug), nil
}

func code(path string, _ leetcode.Lang) (string, error) {
	b, err := ioutil.ReadFile(path)
	return string(b), err
}

Import CSV to Anki

  1. Get Anki note type from Shared Deck.
  2. Import CSV file in Anki.

Import CSV

ankit's People

Contributors

invzhi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.