aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2023-12-29 16:16:25 -0600
committerAnthony Wang2023-12-29 16:16:25 -0600
commit97722764e82b3748a6ec60574fd3d3752048c101 (patch)
tree61b6fe63c227693ee407d146f683d375e3df6414
parent63f04f004110ecabfb5ec32408e77055a62a9122 (diff)
Add command for creating table in README, add fish helper scripts
-rw-r--r--README.md4
-rw-r--r--sd-add.fish5
-rw-r--r--sqlitevi.fish4
-rw-r--r--test.py2
4 files changed, 13 insertions, 2 deletions
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()