Tag Archives: programming

LOLSpam Returns as a Super-Simple Mastodon Bot

Back when I was comparing social media archives, I considered resurrecting my old LOLspam project as a Mastodon bot. I never quite got around to it, partly because I was able to do most of what I wanted to automate using IFTTT, so I stopped investigating that last 5%.

Last night, I threw together a quick and dirty bot to post a random item from a text file in about 20 minutes.

Then I spent three hours going through the Twitter archive for @LOL_Spam, pulling out jokes that are too dated or cringeworthy. (I hope I didn’t miss any. It was midnight by the time I finished, and I was really tired!)

This morning I modified the script to take a second file as a queue for new items.

  • I can add new items to the queue file as I find them.
  • It’ll post from the queue on a schedule (using cron).
  • When it uses up the queue, it returns to posting random posts from the archive.

If you’re interested in funny/odd spam subjects (and you’re OK with swearing and occasional lewdness), check out @LOLspam@BotsIn.Space. You can follow from any Mastodon or other Fediverse account.

The script itself is called fedbotrandom. I wrote it in Perl, using text files, so I could just put it in cron on any *nix box instead of worrying about language/database support or installing a runtime or DB engine. I’ve made it really simple on purpose, and while I do plan on writing some better error handling when I have time, It’s already more complex than I wanted it to be!

You can find me on Mastodon at @KelsonV@Wandering.shop.

Groovy, null, and ‘null’

Groovy will let you call toString() on a null object. The result is the word ‘null’, which might be what you’re expecting if you know the object is null, but probably isn’t what you’re expecting if you don’t.

So if you’re, say, binding a SQL parameter and you forget to check for nulls like you would in Java, and you forget to use a null-safe operator like you should in Groovy, and you get a null value, what happens? Does groovy…

  1. Throw a NullPointerException like Java?
  2. Set the field to null?

Neither. It sets the field to the string ‘null’.

Make sure to use myVariable?.toString() instead of myVariable.toString() for cases like this!

cfspreadsheet + GetTempFile() = NullPointerException

Every once in a while I encounter a problem with something so blindingly simple that

  1. I can’t imagine I haven’t tried it before, and
  2. I can’t believe no one else has documented the problem either.

ColdFusion 9 and later has a tag called <cfspreadsheet> which makes it dead simple to read, update, or create an Excel file. Want to plug the results of a query into a spreadsheet? Literally one tag with just three parameters.

There’s also function GetTempFile() that will create a guaranteed unique file on the server that you can then manipulate.

The obvious solution if you want to create a spreadsheet to download is to create a temp file, write to it with cfspreadsheet, then serve it up.

<cfset filename=GetTempFile(GetTempDirectory()) >
<cfspreadsheet action="write" overwrite="true" filename="#filename#" query="myquery">
<cfheader name="Content-disposition" value="attachment;filename=MyFile.xls">
<cfcontent type="application/msexcel" file="#filename#">
<cffile action="delete" file="#filename#">

It turns out this won’t work. You’ll get a Null Pointer Exception in the logs. Not because of anything you’d expect, though…it turns out that cfspreadsheet is relying on the file extension, and since GetTempFile() gives you a file ending in .tmp instead of .xls, it isn’t sure what to do with the file.

Solution: Find some other way to name your temporary file, and give it an .xls extension.