From 97722764e82b3748a6ec60574fd3d3752048c101 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 29 Dec 2023 16:16:25 -0600 Subject: Add command for creating table in README, add fish helper scripts --- README.md | 4 +++- sd-add.fish | 5 +++++ sqlitevi.fish | 4 ++++ test.py | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 sd-add.fish create mode 100644 sqlitevi.fish diff --git a/README.md b/README.md index e221ed5..f3f77e7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ This is a C port of [SD](https://git.exozy.me/a/SD), a very efficient (and a tin ## Usage -Flash cards are stored in the `cards` table of a SQLite database. There are four columns: `idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING`. The `idx` is a unique index for each card, starting at 0. The weight is how often the card should come up. The key and value are the front and reverse sides of the card. You can use the `sqlite3` CLI to create a card deck. You may be able to get twice as fast performance by enabling WAL with `PRAGMA journal_mode=WAL` because WAL only writes the content once instead of twice. +Flash cards are stored in the `cards` table of a SQLite database. There are four columns: `idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING`. The `idx` is a unique index for each card, starting at 0. The weight is how often the card should come up. The key and value are the front and reverse sides of the card. + +To create a card deck, use `sqlite3 cards "CREATE TABLE cards (idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING)`. You may be able to get twice as fast performance by enabling WAL with `PRAGMA journal_mode=WAL` because WAL only writes the content once instead of twice. Now build this project with `gcc sd.c segmenttree.c -o sd -lsqlite3 -O2 -march=native` and run `./sd` to enjoy a fast flash cards experience! The program will display the `key` of a randomly selected card. Press any key to show the `val` of the card. Now press either `y` or `n` depending on whether you got the card correct, and the program adjusts that card's weight. diff --git a/sd-add.fish b/sd-add.fish new file mode 100644 index 0000000..1b580a6 --- /dev/null +++ b/sd-add.fish @@ -0,0 +1,5 @@ +function sd-add + set cardfile cards + set idx (math 1+(sqlite3 "$cardfile" "select max(idx) from cards")) + sqlite3 "$cardfile" "insert into cards values ($idx, 256, '$argv[1]', '$argv[2]')" +end diff --git a/sqlitevi.fish b/sqlitevi.fish new file mode 100644 index 0000000..964e4f6 --- /dev/null +++ b/sqlitevi.fish @@ -0,0 +1,4 @@ +function sqlitevi + mv "$argv" "$argv.bak" + sqlite3 "$argv.bak" .dump | $EDITOR | sqlite3 "$argv" +end diff --git a/test.py b/test.py index 451b403..e600853 100644 --- a/test.py +++ b/test.py @@ -3,7 +3,7 @@ import sqlite3 con = sqlite3.connect("test.db") con.execute("PRAGMA journal_mode=wal") cur = con.cursor() -cur.execute("CREATE TABLE IF NOT EXISTS cards (idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING)") +cur.execute("CREATE TABLE cards (idx INTEGER PRIMARY KEY, weight INTEGER, key STRING, val STRING)") for i in range(10**8): cur.execute("INSERT INTO cards VALUES(?, ?, ?, ?)", (i, 1, i, i)) con.commit() -- cgit v1.2.3-70-g09d2