As a module for the screaming.computer, I'm tentatively calling it the Philos-o-matic: Affirmational Platitude Generator.
Hogwash that looks compelling
Seb Pearce describes how the idea came while watching a particular pseudoscience-advocate involved in a philosophy debate:
The thing that really impressed me, though, was his command of the vocabulary of woo... This word is a blanket term for pseudoscience, New Age thinking, dubious alternative medicine and other things that reek of the heady fumes of snake oil. ...
As I sat there listening to the debates, I thought to myself, “This all sounds like random sequences of buzzwords. I bet I could write code to generate it.” It seemed like not only a fun side project, but a great way to prove how easy it is to make hogwash that looks compelling. It might help show that it's the language games and emotions that lure people into this stuff.
The resulting script generates delightful pseudo-inspirational, pseudo-philosophical fragments of nonsense.
At a low level, the core code simply generates N sentences on a given topic from the available templates. My implementation follows a simple randomized structure:
- Optional: 1 sentence on a random topic
- Always: 3 sentences on a common topic
- Optional: 1 or 2 sentences on separate topics
The sentences themselves are templated, with random words inserted according to type.
"The goal of #fixedNP is to plant the seeds of #nMass rather than #nMassBad."
can become “The goal of ultrasonic energy is to plant the seeds of self-actualization rather than dogma.”
This is all fairly straightforward random-text-generation stuff, but I have to give kudos to the high-quality templates written by Seb Pearce — the resulting text is highly readable and often charming.
Receipt printer word wrapping
On the receipt printer and screaming.computer side of things, I finally wrote a multibyte-safe word-wrapping function; important for blocks of text since the receipt printer is only 32 characters wide at
(PHP has the wordwrap function, but it's no good for Unicode strings.)
mb_wordwrap function inserts a Unicode soft break (U+2028) at all potential wrap points (surrounding all hard breaks, following runs of whitespace, following runs of dashes/hyphens). The string is then exploded at the soft breaks and each chunk is added to the current line if it will fit. When a line gets too long, a hard break is inserted, then we make a new line and carry on with the next chunk.
Compare the default hard-wrap at 32 characters with the intelligent word-wrap:
We are at a crossroads of life-f orce and materialism. Bondage is born in the gap where passion h as been excluded.
We are at a crossroads of life- force and materialism. Bondage is born in the gap where passion has been excluded.
Again, this is all fairly trivial infrastructure code, but even ‘trivial’ code takes time to design and implement.
Unicode character mismapping
Some of the template strings contain curly-quotes, em-dashes, and other extended Unicode characters.
The escpos receipt printing library ostensibly handles the conversion from UTF-8 to the printer's various native codepages, however I've observed a few glitches where extended characters are printed incorrectly. (Often the right-single-quote U+2019 prints as an accented-lowercase-o for some reason).
A cursory glance at the
Printer::text function leads to the
EscposPrintBuffer::writeText function, which has some pretty inscrutable codepage-switching code.... I'll study this and debug it eventually, but not today.
In the meantime I yield to the code and simply replace the problematic characters with their nearest ASCII-equivalent.
Words to change your life
This concludes the initial implementation of module #3 for the screaming.computer! At this time, I feel it's important to recall the ancient wisdom:
It can be difficult to know where to begin. Entity, look within and empower yourself. How should you navigate this non- local solar system? By evolving, we believe.
Say it with me: “By evolving, we believe!”