sagethesagesage

Driven largely by a staunch refusal to learn anything too new, I've decided to try my foolish hand at writing one of these “static site generators”. That is to say, I've decided to pretend a task is very very simple, and pray that my needs never outgrow my mediocre bash skills.

Basically, I'm tired of writing brackety tags everywhere, so I have a little converter from plain text to HTML. There's a template.html file and an index.template.html file. The first is the basis for individual posts, and the second is used to generate a list of links to each post.

This script is incredibly naive. It more or less copy pastes the text in a given post file straight into the body of the template.html file. But it does use the first line of the file as both the header and the name of the link, which is kinda fun. And I can just add HTML tags wherever I want, if I do feel like adding some flair.

At some point, I could try to convert this into a real project with my dear friend Rust, but for now that's 2 hard.

The best part of this whole thing is that I don't even have a way to host it, yet. So for now, write.as, whoo!

#100DaysToOffload

I wanted this post to be longer, but instead I added comments to my code. So here's the script so far:

#!/bin/bash

## Replace backticks with <div>
# cat test | sed 's/`\(\w\)/<div>\1/g' | sed 's/\(\w\)`/\1<\/div>/g'

# Delete old versions of pages
rm pages/*

# Folder with plaintext posts
cd posts

# Accrue link text
links=""
for f in `ls -t`; do
    # First line is the title
    title=$(head -n 1 $f)

    # Stupidly replace newlines so sed can process them
    content="<p>$(tail -n +3 $f | tr '\n' '~' )"

    # Convert two once-newlines into paragraph tags
    content="$(echo "$content" | sed 's/~~/<\/p>\n<p>/g' | sed 's/~/\n/g' | sed '$ d')"

    # Replace the #title and #content markers with the new strings
    template=$(cat ../template.html)
    output=$(echo "${template/\#content/$content}")
    output=$(echo "${output/\#title/$title}")

    # Save this text into a new html file,
    # named after the original post text
    echo $output > "../pages/${f}.html"

    # Append a link to the new page
    links="$links<a href=\"pages/$f.html\">$title</a><br>"
done
cd ..

# Insert link text into index template
index=$(cat index.template.html)
index=$(echo "${index/\#links/$links}")

# Create index file
echo $index > index.html

My partner's been running with a 2015 MacBook Air for a few years now, but it's no longer doing what she needs. That is to say, it rapidly converted from “ok” to “very stinky” over the last year-ish. YouTube videos stutter. It's madness. We even re-installed MacOS, and no dice. An upgrade was in order, and with all the remote work stuff, it needed to be a sizeable one.

Now, my current laptop is a Dell Precision M4700 from early 2013 (that I bought in 2018). It's a fat boy. Nearly an inch and a half thick, and not exactly chamfered. Priorities for that purchase include: number of hard drive spots, number of RAM slots, can play Factorio.

My partner did not want a Dell Precision M4700. She has frivolous requirements like “battery life more than an hour”, “un-terrible webcam”, and “less than 6 pounds”. This narrowed down the options significantly. Of course, what narrowed it down more was that I insisted on finding something with swappable RAM and storage, but I stand by that.

The search for new technology is kinda fun, but I spent way too much time on it, and it got to be pretty draining. There exist far too many devices with good specs and terrible trackpads. We also try to buy used where possible for not-being-wasteful reasons, but her work uses very poorly-optimized software, so we bit the bullet and found something new.

And when I say “we”, I mean “she”. I spent hours on the search (and picked up plenty about the current laptop “market” or whatever) but ultimately she found it, tucked away on a manufacturer's website. I gave it the know-it-all computer-guy seal of approval, and we ordered. It looks pretty cool, and should totally blow mine out of the water.

But it hasn't arrived yet, so maybe it's terrible.

#100DaysToOffload

PS: For those interested it's an Inspiron 15 5000 with the Ryzen 5 4500U.

Listen, if I had to pick a language to write a decent program in, I'd want to use something like Rust. It behaves in more or less all the sane ways I want a language to behave. Python's nice and quick for Python-y stuff, and Javascript is Javascript, etc. But for some reason, I just like C.

I've written something of an implementation of Lisp for my Pebble smartwatch, which I named PebbLisp. I'd love to have written it in Rust, to get some more practice with it, but it was a real pain in the tookus to get compiling for the watch, and I gave up. So, C.

I'll never act like C is a perfect language. Many, many, stupid memory leaks could've been avoided with something smarter. For some reason, though, it's just fun to work with. PebbLisp involves some dancing about with pointers, and includes a homegrown tagged-union setup. There are parts that are probably very ugly to more practiced eyes, and correcting unexpected behavior is a nightmare, but coding it leaves me downright giggly sometimes.

The Object struct in PebbLisp has three parts:

struct Object {
    Type type;
    union {
        ...
    };
    Object *forward;
}

The Tag

The first part is the Type of the Object. This is just an enumeration with all the possible types that a PebbLisp object can be. It's the tag of our tagged union. Already I like it far more than is warranted. One number is a front for every possible type? Incredible!

The Union

The second part is, of course, the union itself. I've cut it out here, but there are members of the union for integers, pointers to strings, function pointers, etc. Unions are also something I treasure. The famous issue with unions is trying to keep track of what state any given union is actually in, and god help you should it ever be interpreted incorrectly. That's why it's fun, though. Coding a consistent way to access a union feels like cracking open the secret door of programming.

The Pointer

Finally, Object *forward: something that traditionally might be named cdr (which I had to look up, because I'm really not enough of a Lisp guy). In Lisp, everything is a list. An object with forward == NULL is a list of length 1. An object that points to another object is a list of length 1 + listLength(forward), aka itself plus the rest of the list.

So much code in PebbLisp is dedicated to making sure that this value is never incorrect, duplicate, or useless. A cloneObject() function exists largely because copies of individual objects can't keep this address. I'd love to use our friendly neighborhood assignment operator: =, but C doesn't allow operator overloading. But cloneObject() was fun to write, somehow!

C

Anyway, this has already run too long. Point is, C doesn't care what you do with data. And for some reason, it's fun to redo decades of other people's work in a project no one asked for. I highly recommend it.

#100DaysToOffload

I own far too many phones because I'm a nostalgic nitwit and I never manage to get rid of the old ones. Some were broken and replaced, and some were lost to carrier-switching. Two phones I purchased just for fun. One was a Galaxy SII, for toying with PostmarketOS. The other is the worst smartphone I've ever owned: the Alcatel OneTouch Pixi Pulsar.

The Pulsar is small, slow, has a locked bootloader, is stuck on Android 4.4.2 (3 years old when I bought it) and is locked to Tracfone. Why did I buy this piece of junk? Because it cost $4.83, after taxes, shipped overnight. I know carriers discount devices so you'll buy their service, and it's a piece of junk, but still.

I tried a few of my main apps. Tusky is incompatible, but Fedilab runs okay. Slide for Reddit works alright but has some bizarre behavior when switching between activities (or fragments or whatever they are). The only camera is obviously hideous and rear-facing. During an unrelated nostalgia kick I read the entirety of two Goosebumps books using Librera Pro, which worked well.

Anyway, it's pretty terrible. I had some fun experimenting with it, as a what's-the-worst-hardware-I-can-live-with test, but it's pretty rough. If it had a little more space and the software was a smidge newer, I might be able to get by.

That said, consider giving this experiment a try. I wouldn't recommend going and buying something you don't need — it feels wasteful, now — but if you've got an old phone in a drawer somewhere, pull it out. Boot it up and see how it compares to your current device.

And then, if you're anything like me, sell the damn thing.

Yeesh.

#100DaysToOffload