alexpovel
Joined 6 years ago
Joined 6 years ago
For fun, I had put together a GitHub bot for this purpose a while ago. It indexes all existing issues in a repo, creates embeddings and stores them in a vector DB. When a new issue is created, the bot comments with the 3 most similar, existing issues, from vector similarity.
In theory, that empowers users to close their own issues without maintainer intervention, provided an existing & solved issue covers their use case. In practice, the project never made it past PoC.
The mechanism works okay, but I've found available (cheap) embedding models to not be powerful enough. For GitHub, technology-wise, it should be easy to implement though.
For a tool I’m writing, the tree-sitter query language is a core piece of the puzzle as well. Once you only have JSON of the concrete syntax trees, you’re back to implementing a query language yourself. Not that OP needs it, but ast-grep might?
cat file.py | srgn --py def --py identifiers 'database' 'db'
will replace all mentions of `database` inside identifiers inside (only!) function definitions (`def`) with `db`.An input like
import database
import pytest
@pytest.fixture()
def test_a(database):
return database
def test_b(database):
return database
database = "database"
class database:
pass
is turned into import database
import pytest
@pytest.fixture()
def test_a(db):
return db
def test_b(db):
return db
database = "database"
class database:
pass
which seems roughly like what the author is after. Mentions of "database" outside function definitions are not modified. That sort of logic I always found hard to replicate in basic GNU-like tools. If run without stdin, the above command runs recursively, in-place (careful with that one!).Note: I just wrote this, and version 0.13.2 is required for the above to work.
It allows you to grep inside source code, but limit the search to e.g. “only docstrings inside class definitions”, among other things. That is, it allows nesting and is syntax aware. That example is for Python, but the tool speaks more languages (thanks to treesitter).
https://github.com/alexpovel/srgn/blob/main/README.md#multip...
Caught me.
> And how is it less tedious to have to select previously typed text all the time?
This is tedious, but I have that automated (AutoHotKey). So a single, AHK-managed hotkey does the equivalent of:
CTRL + SHIFT + HOME
CTRL + C
feed into tool, paste back
CTRL + V
So once done writing, I press that single button and it's done (CTRL+SHIFT+HOME select all text from cursor to beginning). To me, that's a better tradeoff than fiddling with compose keys, which I find to break flow. For very short text, compose key is possibly better; but again, once in AHK, it's a single shortcut. So once more than 1 compose key combination is needed, it's "worth it". But you're right: this is a custom setup and might not work for everyone.[0]: https://github.com/alexpovel/srgn/blob/0008cce1c71f0d83f6a31...
It grew out of a niche, almost historical need: using a QWERTY keyboard, but needing access to German Umlauts (ä, ö, ü, as well as ß). Switching keyboard layouts is possible but exhausting (it's much more pleasant sticking to one); using modifier keys is similarly tedious, and custom setups break and aren't portable.
So this tool can do:
$ echo 'Gruess Gott, Poeten und Abenteuergruetze!' | srgn --german
Grüß Gott, Poeten und Abenteuergrütze!
meaning it not only replaces Umlauts and Eszett, it also knows when not to (Poeten), and handles arbitrary compound words. Write your text, slap it all into the tool, it spits out results instantly. The original text can use alternative spellings (ou, ae, ue, ss), which is ergonomic. Combined with tools like AutohotKey, GUI integration through a single keyboard shortcut is possible. See [0] for a similar example.A niche need I haven't yet come across someone else having as well! (just the amount of text explaining what it's all about is saying a lot in terms of specificity...)
The tool now grew into a tree-sitter based (== language grammar-aware) text manipulation thing, mostly for fun. The bizarre German core is still there however.
[0]: https://github.com/alexpovel/betterletter/blob/c19245bf90589...
Thank you for the feedback! That sounds good, I'll add that.
I've spent a lot of time trying to find similar tools, and even list them in the README, but `AST-grep` did not come up! I was a bit confused, as I was sure such a thing must exist already. AST-grep looks much more capable and dynamic, great work, especially around the variable syntax.
Idea: renders your resume as pretty terminal output. Others can view it in their own terminals:
curl -L ancv.io/heyho
Pipe to a pager for best viewing. Yes, it's just a nerdy gimmick with almost no real use!I provide a GCP-hosted server that works off GitHub gists (where your resume can live in JSONResume form). However, self-hosting is a first-class citizen and easy to use as well.