Holly's Briars

There are 7 entries to read containing the #programming tag, with the newest being first. Have fun!


Click on a #tag to jump to that post category, or go here to visit the archive.


Stopwatch, a Rust Crate

  • 2024-01-15
  • 22:02

I made a stopwatch crate for Rust. This exists because I added an existing stopwatch crate to a project and my cargo.lock had a bunch of unnecessary new entries due to dependencies so I wrote one in pure Rust.

I will not be posting it on crates.io for several reasons:

  • Name collision with stopwatch
  • Supply chain attacks are a thing and people need to stop relying on centralised distribution
  • Git is always up-to-date, and you can choose a version from a commit hash

Usage is simple

let mut stopwatch = Stopwatch::new();

stopwatch.start();

// Do a long running task
std::thread::sleep(Duration::from_secs(5));

stopwatch.stop();

println!("Operation complete in: {}", stopwatch);

Source and complete instructions are available in the git repository

Surprisingly enough (even to me), the license is CC0.

Email me with any bugs. :)


Switching to Zola

  • 2023-08-22
  • 20:47

I've been feeling like I'm hitting limitations on berrygen's capabilities. For example, I was unable to generate a feed of posts without manually making the links in a Markdown document. Since the requirements are so rigid, I think that my only way forward was to use a batch script to pipe the output file back into itself repeatedly. At the time of writing, there are 48 (now 49!) entries on this site. That would mean I need to process the same file 49 times, appending a shortcode at the end for the next post to render.

Once that was done, there was still the case of pagination. I had no access to the collection of objects without first generating a page with a collection of objects, and then using that as a source for the next pass, which eventually brought my project out of scope. That means only one thing. My implementation was far too inefficient and unwieldy.

In my search for a decent static-site generator using only Rust, I found Zola, which is powered by Tera. Some initial tests using my existing template were rather successful since Tera is inspired by Jinja2, and I was using minijinja in berrygen. There were some errors related to shortcodes, and the output was almost identical, with mine being cleanly formatted. The frontmatter (or grey-matter, in my case) needed adjusting, and I had to import the entries from jrnl and process those as individual files. Zola also allows me to use extra frontmatter that isn't serialized to a struct. I couldn't figure out how to implement that in my own implementation without crashes or forcing the user into an extremely tight box, even when parsing the extra frontmatter as a HashMap.

Once I had my posts formatted and exported from jrnl, Zola just worked. I don't mean it just worked, it worked even after deviating from the "Getting Started" guide and immediately jumping into making my own template, unlike Hugo, which had a gosh-darn stroke out of the box without any sort of helpful error messages. I discovered that sometime in June when I was helping a good friend setup his art portfolio.

All in all, this whole thing was a learning experience. Not every project will be a success, nor will every project get finished or published "because it needs to be".


berrygen - SSG in Rust

  • 2023-08-17
  • 11:21

Good morning! I'm working on something called berrygen. It is a Rust application that generates static websites, utilising most of the code from livejrnl-rs. It is yet again powered by minijinja under the hood.

In its current form, this website is being generated from Markdown files in a directory. Each file is passed to berrygen using a shell script to loop through the files in the directory. There is no support for jrnl and there will not be. I am dropping jrnl support because I write most of my entries in Obsidian. When the time comes, I will be writing an exporter to export the jrnl files to be used with berrygen.

Any posts before this one will be from the import. I will publish the source when it is in a state to be shared.


Man Pages

  • 2023-08-06
  • 13:51

No one writes good man1 pages anymore, myself included.

What is a man page? For the young and uninitiated, it is short for manual page. They are The Sacred Texts of the digital world. They can tell you exactly how to use a program and it works anytime, anywhere, even offline, in your terminal.

To get started, type man man and enjoy your new adventure.

Welcome back. I was looking at cargo --help today and was thinking about how much cleaner it would be if man cargo had this information instead of it all being in the command-line help.

~ ❯ cargo --help
Rust's package manager

Usage: cargo [+toolchain] [OPTIONS] [COMMAND]

Options:
  -V, --version             Print version info and exit
      --list                List installed commands
      --explain <CODE>      Run `rustc --explain CODE`
  -v, --verbose...          Use verbose output (-vv very verbose/build.rs output)
  -q, --quiet               Do not print cargo log messages
      --color <WHEN>        Coloring: auto, always, never
  -C <DIRECTORY>            Change to DIRECTORY before doing anything (nightly-only)
      --frozen              Require Cargo.lock and cache are up to date
      --locked              Require Cargo.lock is up to date
      --offline             Run without accessing the network
      --config <KEY=VALUE>  Override a configuration value
  -Z <FLAG>                 Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
  -h, --help                Print help

Some common cargo commands are (see all commands with --list):
    build, b    Compile the current package
    check, c    Analyze the current package and report errors, but don't build object files
    clean       Remove the target directory
    doc, d      Build this package's and its dependencies' documentation
    new         Create a new cargo package
    init        Create a new cargo package in an existing directory
    add         Add dependencies to a manifest file
    remove      Remove dependencies from a manifest file
    run, r      Run a binary or example of the local package
    test, t     Run the tests
    bench       Run the benchmarks
    update      Update dependencies listed in Cargo.lock
    search      Search registry for crates
    publish     Package and upload this package to the registry
    install     Install a Rust binary. Default location is $HOME/.cargo/bin
    uninstall   Uninstall a Rust binary

See 'cargo help <command>' for more information on a specific command.

A well-written man page would present this without needing extra command line flags (--list or cargo <command> --help), and also without the user needing to scroll up to read the available options. A well-written man page would allow for far greater flexibility in documenting the individual switches and commands, with the ability to provide usage examples, a more in-depth description of each option, and provide recommended defaults (if any).

Since my favourite markup language is Markdown, I did some searching to see how I could create man pages with Markdown and stumbled upon a blog article by Brandon Rozek that utilises Pandoc and also this article by Lars Wirzenius on how to write them by hand without Markdown.

Armed with this knowledge, I'm going to create man pages for my existing projects. I think I will go the Pandoc route. I can't wait! 💖

footnotes




Peace

  • 2023-02-05
  • 21:49

🎵 Music: Nirvana - Stain

I'm feeling pretty peaceful and rather productive at the moment. I cleaned up Obsidian, got some game dev mechanics implemented, browsed the Internet for some time, shaved my face and legs, and learned how to use Mermaid which is a diagramming and charting library that's built into Obsidian. As a result of falling down the Mermaid rabbit hole, I've been writing some UML diagrams for my software projects. My next few diagrams will be state diagrams, and then the flowcharts. I'm looking forward to learning how to use this. Obsidian is far more powerful than I thought. 😁

As an added bonus, I can include the diagrams when I work on the documentation. 😄


Delays

  • 2023-01-27
  • 21:31

I planned to post the LiveJrnl source today but I had a last minute change in mind.

I did post the .gitignore and README, however. On Sunday I will make some changes to the script to generate the RSS from a second script. I don't feel comfortable having one script generate both files. Unix philosophy and all that.