Use sd binary in same directory as scripts instead of needing to pass path to sd binary

This commit is contained in:
Anthony Wang 2024-01-30 21:59:19 -05:00
parent 33b76d4106
commit a5bfafa8a7
Signed by: a
SSH key fingerprint: SHA256:B5ADfMCqd2M7d/jtXDoihAV/yfXOAbWWri9+GdCN4hQ
4 changed files with 10 additions and 4 deletions

View file

@ -6,11 +6,11 @@ This is a C port of [SD](https://git.exozy.me/a/SD), a very efficient (and a tin
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.
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 double the 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.
There is also a Python GUI which requires PyQt6. Run it with `python main.py PATH_TO_SDC_BINARY`. You can optionally pass additional flags to SDC. Alternatively, there is a Tkinter GUI, `python tkinter.py PATH_TO_SD_BINARY`, that only requires the Python standard library but does not support Wayland. The GUIs are not compatible with the original unmaintained SD which lacks noninteractive mode, but it would be easy to add that to SD.
There is also a Python GUI, `main.py`, which requires PyQt6. This script invokes the `sd` binary in the same directory as the script with the command-line flags that were passed to the script. Alternatively, there is a Tkinter GUI in `tkinter.py` that only requires the Python standard library but does not support Wayland. The GUIs are not compatible with the original unmaintained SD which lacks noninteractive mode, but it would be easy to add that feature to SD.
It should also be fairly easy to write your own SD clone or GUI, so if you write one, I'd be glad to link to it here.

4
main.py Normal file → Executable file
View file

@ -1,3 +1,5 @@
#!/usr/bin/python
import subprocess
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
@ -14,7 +16,7 @@ class SDGUI(QMainWindow):
# Start SD
self.proc = subprocess.Popen(
sys.argv[1:] + ['-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE
[sys.path[0] + '/sd', *sys.argv[1:], '-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
# Display key

2
test.py Normal file → Executable file
View file

@ -1,3 +1,5 @@
#!/usr/bin/python
import sqlite3
con = sqlite3.connect("test.db")

4
tkinter.py Normal file → Executable file
View file

@ -1,3 +1,5 @@
#!/usr/bin/python
import subprocess
import sys
import tkinter
@ -12,7 +14,7 @@ root.title('SD GUI')
# Start SD
proc = subprocess.Popen(
sys.argv[1:] + ['-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE
[sys.path[0] + '/sd', *sys.argv[1:], '-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
# Display key