9 votes

What programming/technical projects have you been working on?

This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

3 comments

  1. archevel
    Link
    I am back home in a cabin by small lake. Outside it is about minus 20-15°C. Very cozy all in all. For a while now I've been playing around with pdf generation. I became interested in it because at...

    I am back home in a cabin by small lake. Outside it is about minus 20-15°C. Very cozy all in all. For a while now I've been playing around with pdf generation. I became interested in it because at work someone cobbled together what in my eyes seems lime a monster in order to generate a fairly simple receipt as a pdf. We have a react frontend. When someone wants a receipt the frontend asks the backend for it. The backend reads out some info (some json data) and saves it for five minutes in a cache with a UUID as a key for the lookup. Then it makes a request to another service running in a different container with the key as the sole parameter. In this "pdf" service playwright is installed so as a request comes in, a chromium instance is launched (possibly an instance is reused) and pointed to the frontend domain with a special document url containing the key. So now the whole frontend app is loaded in the chromium instance, then the special document route is navigated to. The component for the document route sends a request to the backend with the key which reads the json info out of the cache and returns it. The component then renders the content based on the json data. When the document is fully loaded playwright then invokes the browsers print capability and returns the binary stream. The stream comes back to the backend which passes it back to the original requestor the user in the frontend. Phew....

    Anyway, this all has prompted me to dig into the pdf spec to understand it a bit better and essentially find a nicer way of generating the desired content. So I first found the rust crate lopdf and have managed to use it to generate a simple pdf with some non-ascii text and some images. I then started looking at rolling my own layout handler (wrapping text inside some bounds, basic table layouts etc). The wrapping of text is particularly interesting since now I need to figure out the size of text strings (which may vary depending on font) and see if it needs to be split and where best to do that. However, I just now found a few additional crates like genpdf which seem capable of handling all that and much more! So it is a bit bitter sweet. I wanted to get more proficient in rust while building a clean library for handling pdf generation. But, since there already exists one I'm probably better off just building on that one. On the plus sid, this means I can probably get something nice working fairly quickly and slap it behind some webserver.

    4 votes
  2. zoroa
    Link
    An OBS script that automatically records Valorant games. I've been playing too much Valorant lately. It's a game where: You work with limited knowledge (you don't always know where your opponents...

    An OBS script that automatically records Valorant games.

    I've been playing a lot of too much Valorant lately. It's a game where:

    • You work with limited knowledge (you don't always know where your opponents are)
    • The action is very quick.

    So it's really isn't always obvious what mistakes you've made in the moment. Open Broadcaster Software (OBS) was recommended as a way to screen record games so you could look for mistakes later. I liked the workflow, but would often forget to start or end the recordings manually.

    I used techchrism/valorant-autorecord to have this happen automagically, but eventually ran into some issues:

    • It's a separate program that I have to remember to open, and often would not.
    • It would crash, or not behave as I would expect in some somewhat common situations (a match is created but never starts because someone disconnects, trying to record a game that has already started, etc...)

    I would've normally just submitted some pull requests to the original project, but I had some time on my hands for winter break and decided to write my own version knowing that:

    • OBS is very extensible. It has a plugin system (C/C++), embedded scripting support (Lua or Python), and exposes a websocket that can remotely control a session.
    • Valorant will broadcast some information about the game state over a websocket.
    • I'd end up spending way more time getting PRs merged than rewriting from scratch.
    • I could fix bugs and add some features I wanted.

    I ended up writing a python script that would listen for messages from the Valorant websocket, and using OBS's python bindings to start and stop recordings for games. The script gets loaded on startup, so I never have to remember to do it myself.


    Aside: I unexpectedly had to get a much better understanding of async Python. The websocket client I was using gave me trouble using their synchronous API, but their async API worked fine. Of all places, an R&D team at the British Broadcasting Corporation (BBC) published a series of articles that I found really helpful in getting a more complete picture at how async Python works: https://bbc.github.io/cloudfit-public-docs/

    3 votes
  3. thanhnguyen2187
    Link
    I'm working on an offline-first code snippet manager named Crypta. I created it to scratch my own itch: having a place to quickly copy and paste text, with encryption/decryption for sensitive...

    I'm working on an offline-first code snippet manager named Crypta. I created it to scratch my own itch: having a place to quickly copy and paste text, with encryption/decryption for sensitive data.

    After making a rudimentary offline-first version works, I'm working on a more sophisticated data persistence strategy: in-browser SQLite (wa-sqlite) and HTTP-exposed SQLite (sqliterg) wrapped by Drizzle.

    You guys can try the application here: https://thanhnguyen2187.github.io/crypta. The source is available at: https://github.com/thanhnguyen2187/crypta

    2 votes