Developer Diary, European Day of the Righteous
Today, in a self-explanatory part of the world, people celebrate the European Day of the Righteous, originally a memorial for the Armenian Genocide, but now more broadly honoring people who have taken stands against authoritarians or crimes against humanity.
While we talk about code, we should also all aspire to taking similar stands. As I often mention, because we often see this situation, it doesnât generally take much actual resistance for authoritarians to walk away, so even small acts to help people canâat least in theoryâmake a difference.
Morning Dashboard
I concluded last weekend that I need more calendars on my Morning Dashboard. I donât use the dates for anything, yet, but watching the ebb and flow of the various cycles interest me on a peculiar level. As a result, I added the Islamic, Tibetan, and Ethiopian calendars.
I then took on a small project that Iâve wanted to kick around for a while. As readers may know from my things that work post late last year, I type up a quick journal entry every night as a memory aid, reviewing what I worked on, watched, ate, and otherwise spent my time, along with any miscellaneous thoughts that the day might have brought up. I donât do much with those files after writing them, so they have always seemed ripe for analysis.
I decided to start with word count and sentiment, the total sentiment per word, specifically.
As you might already know, sentiment doesnât necessarily map to mood, especially for someone like me, who has a habit of describing things as ânot goodâ or ânot bad,â which muddles word-by-word sentiment. However, this information does turn up some interesting ideas to investigate further. For example, check out my older analysis of sleep time.
While they donât match perfectly, do you maybe notice the suspicious items on these charts? You canât and shouldnât need to see the dates, but a couple of days before Christmas, I wrote the highest-sentiment journal entry, despite its brevity, and then I slept the longest that I have for three months. The broad shape of the graphs generally match, but the next time something distinctive happens on both brings us to about a week ago, when I wrote the journal entry with the lowest sentiment, followed by the second-shortest time asleep. I could pick out a few more close correlations, but as I said earlier, the correlation on these two items seems strong enough to warrant some investigation on their own.
Now, correlation doesnât equate to causation. I donât believe that writing an angry or disappointed journal entryâmuch of which probably hinges on what I think about what I watch on television, since that probably includes the most emotional languageâleads to a bad nightâs sleep. It could happen, sure, that harsh words work me into an insomniac lather. But more likely, something causes both my mood (to the extent that sentiment maps to mood) and sleep schedule to shift. Regardless of whether I have found causation, though, I probably have something that I should work on, even if it involves something as minor as breaking my habit of hedging how I write about my assessment of things, or accelerating my time to dropping television shows that I donât immediately find myself enjoying.
In fact, in the spirit of full disclosure hoping to help someone in the future, without bothering with what I watched, I present relevant phrases from my assessment of those shows on that may have contributed to low sentiment.
- Not bad
- Nothing exciting
- It really annoys meâŚhalf-asses theseâŚ
- Enough going on, certainly
- âŚsomeone who he doesnât constantly complain toâŚheâs an assâŚProbably not
This goes back to what I said about the sentiment words probably resting heavily on my media consumption. I watched five things (television shows, movies, and/or videos, but definitely on my television), of which I had harsh things to say about two, ambivalent reactions that include literally negative words for another twoâthe algorithm would consider ânot badâ as two negative words, rather than a slightly positive phraseâand one ambivalent and oddly cryptic comment. I see three possibilities, here. First, maybe my phrasing really does weigh on my mind, when I go to bed. Second, I donât like these shows all that much, and should stop watching anything open-ended that I donât loveâŚwhich probably makes sense, regardless of the effect on sleep. And third, something happened that both put me in an uncharitable mood for the shows and later disrupted my sleep.
Anyway, I get excited about this sort of thing to a rather embarrassing degree. Part of me wants to check this new data against weather, communications, social media, and moreâŚ
Mastodon Tool Trunk
It took me more than long enough to get around to it, but I finally got my Mastodon scheduler script working, though based on my changes, I couldnât tell you if my problem came from my procedure, a server glitch, or my code.
To spare you the long storyâIâll probably write something up on using the Mastodon API, soonâI would frequently receive an error telling me ârecord not found.â That seems like a problem somewhere, since the âpost a statusâ endpoint doesnât list an HTTP 404 code as a possible output.
While I need to investigate further, I suspect that my use of an âidempotency IDâ might have sidelined me, again, either because I misused it or because the server had problems. Itempotency refers to (idempotent) operations, where you can apply them repeatedly to your system stateâusually a database, these daysâand not worry if youâve made repeated changes. We care about idempotency in distributed systems, where the connection might drop, without you knowing exactly where the operation interrupted; for idempotent operations, you retry without checking, because it wonât do any damage. For example, you generally idempotently delete things, but you canât idempotently give someone money, because you canât delete a record âtoo many times,â but you can transfer the wrong amount of money by repeating a payment. In Mastodonâs case, the API makes posting optionally idempotent, by allowing the application to provide the ID to say that it should treat all the toots identically.
In any case, I suspect that my idempotency ID might not have had any content in it, leading to âcollisionsâ with every other ID for an empty message. Fixing a typo or two, adding a delay before sending the media and toot, and updating my test script to include the current time in my test message seems to have fixed everything.
Did I say fixed? No, not quite. I mean that fixed the ânot foundâ error.
Once I cleared the idempotency problem, I discovered that my toots wouldnât post with the images attached. After more research than I honestly care to admit, I discovered that I had overcomplicated things by trying to explicitly set the parameters as HTTP form data. Doing so creates a request body that looks like a URL query string, such as status=Hello, Fediverse&cw=Greetings
. For reasons that I donât understandâor care about, at the momentâthe server only pulls certain information out of such a request, and ignores the rest.
Instead, I needed to format the request parameters as a JSON object. That, as it turns out, takes care of itself, for the most part.
response = http.request request, parameters.to_json
Now it picks up my media_ids
property, and therefore attaches images to toots. This weekâs pre-scheduled toots all come from scheduling with this script, in fact, so please contact me if you see one of them go rogue.
Entropy Arbitrage
GitHub - jcolag/entropy-arbitrage-code
As mentioned last week, if you follow me on social mediaâand really, why wouldnât you?âyou might have noticed that the last week or so of announcement posts across Buy Me a Coffee â, Mastodon , Diaspora , Post.News, Cohost, and Spoutible now bear some resemblance to each other, plus or minus message lengths and URL previews. If youâve investigated this furtherâor if you remember last weekâs postâyou might also have noticed that new blog posts also carry that âteaserâ blurb.
As a result, I have updated my build script for the blog, so that it adds that blurb to the announcements. Most of the platforms require me to manually create the post, because they havenât published an API, yet, but this process at least helps me to not scramble at the last minute to think of something to say when I send the e-mail notifications through Buy Me a Coffee, for example, then feel guilty that I didnât bother to write anything useful on Mastodon, where I have my largest audience.
Next
Now that I seem to have a handle on posting to Mastodon through the API, I need to start parsing my Friday posts to provide the parameters used by the script. As Iâve mentioned, I can probably âparseâ fairly loosely by checking lines. Each entry in the source file for the posts includes, at most, the following.
- A second-level header (
##
) with the time and date when I expect the toot to appear. - A content warning, as a Liquid tag that I call
cw
. - A header image, as a Liquid tag that I call
embed
. - The optional article link, including the headline, URL, and news source, as a Markdown link.
- The quote that gives the general idea.
- A citation for the quote, as a liquid tag that I call
cite
. - The hashtags that I connected to the article.
- Anything that I have to say.
Some of those have blank lines following them. Not all entries have every line. In fact, I donât think that any entry has every line. For the most extreme, the âquote of the dayââfor lack of a better name to pin on themâgenerally get by with only the header, the quote itself, the citation, and the hashtag. I could add a content warning to certain quotes, but I have yet to find one where the quote might reasonably bother someone; someone talking about bigotry doesnât count. By contrast, the articles donât have any citation. It shouldnât take much work to take those lines, remove the Markdown/Liquid overhead, turn them into a command-line for the Mastodon scheduler script, and reset on the next heading.
I may need some trickery to avoid the âbonusâ articles, but Iâll have to see how that goes.
Oh, and I want to clean up the scheduler, too. I see some places where I can improve that code without much work.
In addition, now that my Morning Dashboard has three graphs in it, maybe I should ditch the cutesy HTML-and-CSS bars and replace them with something like D3.js? I like D3 a lot, and it would enable me to add axes and trend-lines to the graphs. But Iâd also need to either maintain the library with the project, or rely on downloading it from a CDN, and neither of those sounds appealing.
Credits: The header image is European Day of the Righteousâ logo by Ruggibrante, made available under the terms of the Creative Commons Attribution Share-Alike 3.0 Unported license.
By commenting, you agree to follow the blog's Code of Conduct and that your comment is released under the same license as the rest of the blog.
Tags: programming project devjournal