Visual Selection

Posted on 2023-10-26 18:50 +0100 in Coding • Tagged with Python, evolution, biology, terminal, textual • 4 min read

Over the last few weeks I've had a couple of sessions of working on a library to wrap Plotext -- a popular terminal-based plotting library for Python -- so that it can easily be used in Textual apps; textual-plotext is the result.

I feel it's come together pretty well

But... I've been itching to find a reason to use it in a project of my own.

Meanwhile...

Back in the mid-2000s, when phpBB systems were still the fashion, I used to hang out on a site that was chiefly aimed at the atheist and secular humanist crowd. We'd get a good number of drive-by YEC types who'd want to argue (sorry... debate) and often talk nonsense about biology and the like.

Now, I'm no biologist, I'm no scientist, I'm just a hacker who likes to write code for fun and profit; so any time there was a chance to write some code to help illustrate an idea I'd jump at the chance. I forget the detail now -- this was back in 2008; 15 years ago as of the time of writing -- but one time I remember a conversation was taking place where someone was just flat out claiming that "random mutation" can only cause "loss of information" and could never lead to a "desired result", or some such thing.

If you've ever had, read or watched those debates, you'll know the sort of thing I mean.

So that got me thinking back then, could I write something that could give a simple illustration of how this doesn't quite make sense?

So I had a little hacking session and came up with some Ruby code1 that did what I felt was the job. You'd give it a phrase you wanted it to generate (a stand-in for the current "fitness landscape", in effect), it would then generate a totally random string of that length, and then would set about mutating it, finding mutations that were "fitter" than others (a stand in for selection), breed the best two so far (randomly copy one chunk from another to create a child), then repeat over and over.

When I first wrote it I wasn't sure what to expect; would it ever finish given a reasonably large target string?

It did.

It was fun to code.

It got posted to the BB and of course wasn't in any way persuasive to them (honestly I never expected it would be). I seem to recall it being hand-waved away with calls of there obviously being an intelligent designer involved2.

Anyway, the "meanwhile..." in this: a few times this year I've thought it could be fun to rework this in Python (it's really not that complex after all; just a string-chopping loop really) and use Textual to put a fun UI on it.

So, that's what I did, complete with textual-plotext plot:

Visual Selection in action

While, 15 years on, this isn't going to convince anyone of the underlying point, I think it does serve a good educational purpose. It shows that you can create a fun UI for the terminal, with Textual, with not a lot of code. It also shows off how you can easily create dynamic plots. Plus -- and I think this might be the really important one -- it shows you can write "traditional" tight-loop code in a Textual application and still have a responsive UI; all thanks to the worker API.

The heart of the code for this application is this:

environment = Environment("This is the target string we want to create!")
while not environment.best_fit_found:
    environment.shit_happens()

Sure, there's some detail in the Environment class, but you get the idea: while we've not hit the target, let life find a way. A loop like that would totally bog down an application with a UI without some other work taking place. With Textual and workers the resulting method in the application, complete with code to send updates to the UI, really doesn't look much different:

@work(thread=True, exclusive=True)
def run_world(self, target: str) -> None:
    worker = get_current_worker()
    environment = Environment(target)
    iterations = 0
    self.post_message(self.WorldUpdate(environment, iterations, *environment.best))
    while not worker.is_cancelled and not environment.best_fit_found:
        environment.shit_happens()
        iterations += 1
        if (iterations % 1000) == 0 or environment.best_fit_found:
            self.post_message(
                self.WorldUpdate(environment, iterations, *environment.best)
            )
    if environment.best_fit_found:
        self.post_message(self.Finished(iterations))

I honestly think the worker API is one of the coolest things added to Textual and I so often see people have real "woah!" moments when they get to grips with it.

Anyway... I've covered science, religion, and how Ruby is better than Python, so I'm sure I've annoyed almost everyone. Job done I guess. ;-)

If you want to check out the app itself there's a GitHub repo and it can also be installed from PyPi using pipx.

Expect it to be my tinker project of choice for a wee while; there's a couple of other things I'd like to add to it.


  1. Possibly unpopular opinion with some folk who will read this, but I've long been a fan of Ruby as a language and actually generally prefer it to Python. 

  2. Me, the coder. While utterly missing the point of a simple illustration, while apparently not understanding the concept of an analogy, I guess at least they felt I was intelligent? 


Constant Siri voice loss

Posted on 2023-10-20 13:04 +0100 in Tech • Tagged with Apple, iPhone, Siri • 1 min read

This seems to have started with iOS 17, and I can't narrow down the how and the when of it happening, but over the last week or so I've found that every couple of days Siri seems to lose their voice. By this I mean the high quality voice that's used when they speak seems to disappear. I notice this when I ask my phone or headphones a question or to do something, and I get a really low-quality voice that speaks back to me.

The voice itself seems to be a version of the voice I normally use, but like it's using an on-device much-cut-down version. If I go into the settings to check what voice is selected, it's the one I normally use, but it wants to download it again.

Downloading the voice all over again

Sure enough, once the download is complete all is good again. I've not kept track of when it happens -- and I think I should from now on -- but it feels like it happens every couple of days; I almost always notice it first thing in the morning, the first time I ask the phone or the headphones something.

I hope it is some sort of iOS 17 weirdness and is gone when 17.1 turns up.


A new guitar

Posted on 2023-10-20 08:39 +0100 in Life • Tagged with music, guitar • 3 min read

This one has been brewing for a year, more or less. Now that I commute into and back from Edinburgh most days of the working week, I find myself walking past a couple of music shops. Seeing these reminds me of the days, back in my 20s, when I mucked around in a couple of bands and had fun making noises on a bass guitar. Since that time I've also owned a cheap six string electric, which is currently in storage (and has been since 2016) and an acoustic, which I have with me but I live in an apartment building and I'm not an arsehole so I never play it.

So, yeah, walking past those shops has made me want to muck about on a guitar again. I've never properly learnt the guitar, I've just managed to learn enough chords to make some noises I like for my own amusement, but even then I've not picked one up since around 2016 and what little I do know is very rusty.

Add to the above: earlier this year I was at a friend's and admiring her collection of bass and six string guitars and picked a couple up and realised I could not play anything. It had been too long, I'd lost most muscle memory and coordination, and what little knowledge I had.

So this made me want to fix this even more.

Given the apartment thing I decided on a plan: how about I get an eclectic, and then some sort of amplification that would always rely on headphones? Given such a setup I could knuckle down and try and learn properly.

So, this week, being on holiday, I told myself I'd pop into Edinburgh one day and have a look at my options; perhaps even come home with something. Yesterday was that day.

It didn't quite go to plan, but the outcome was that I ended up with something to play.

My new Höfner

So, on getting into the shop, and explaining what I was after and why to the chap in there, I tried the usual Stratocaster and Telecaster thing. Both were fine (I think I liked the feel of the Telecaster more in my hand). I had one eye on a Les Paul too, but never tried that. What I did see though was this rather lovely black Höfner.

Now, of course, it's hollow body, so sort of has that acoustic thing going on. This isn't what I wanted for playing in an apartment. But I had to try it anyway. As soon as I started dabbling I was sold. The sound was enough that it would be easy to pick up and play without having to faff with amplification of any sort, on the other hand it was nowhere near as loud as my acoustic. I felt like it bridged the gap between easy to pick up, and versatile enough should I ever want to plug it into something.

And... let's be honest: it was black. Sooooo black. I like black.

Long story short... it had to come home with me!

As mentioned earlier: most of my guitar stuff is still in storage, from when I moved to Scotland, but I did find my old tin of plectrums and the tuner.

Standard guitar kit

(Yes, the tin was once mine and was once full; the early 90s were a different time)

I even found one of my old stands, that I've had since around 1991! So now it's set up in my living room, next to the PCVR rig, ready to go at a moment's notice.

On its stand, ready to go

This is my plan now: each weekend I aim to put in at least an hour a day of practice, to try and get my fingers up to strength again, and to build up the muscle memory of where the strings are, to get the coordination between both hands, etc. I'm also going to be working through beginner's lessons from a tutor application. I'm going to treat this like I'm the complete novice I am and slowly work on improving.

There's no end goal; other than just get proficient enough that I can muck about on my own and be happy that I can play the sorts of things I want to be able to play.

Also, it's good to learn new stuff, especially new stuff that isn't just more coding.


I got a YouTube play button!

Posted on 2023-10-18 19:07 +0100 in Creative • Tagged with YouTube • 2 min read

According to YouTube I joined up on 2006-09-04. I don't think that's quite correct. I did have a Google Video account from very early on, and uploaded a couple of things, and it got ported to a YouTube account when Google discontinued the original video service and settled on YouTube post-purchase. So I guess, in some respects, it's kind of correct.

For most of that time I had hardly anything on there. Couple of videos to do with the weather station I ran for a few years, some things related to my photography, couple of things related to hacking with code; that's about it.

Then, a couple or so years back, when I got heavily into PCVR gaming, I started to record my gaming sessions and upload them.

As of the time of writing there are 1,109 videos in the PCVR playlist, and around 1,300 videos on my channel in total.

As for subscribers... eh, come on, few people are really interested in watching some old bloke stumble around in VR, and I was very late to the game anyway. But, apparently, around 350 lovely folk care enough about my nonsense to subscribe.

Nowhere near enough for a YouTube play button, that's for sure. Only... I now have a play button!

YouTube Lego Play Button

I mean, sure, I have to build it myself...

YouTube Lego Play Button

...but it's something to show for all my efforts, I guess. ;-)

YouTube Lego Play Button

As for how I got it: presumably anyone/everyone with a YouTube account with some content got the offer of goodies (I also got offered free coffee, sausage rolls, socks, and a bunch of other stuff I've forgotten), and I was lucky to claim one of these almost the instant the email turned up.

It's very likely the only YouTube play button I'll ever receive. I think it will take pride of place on my desk.


LinkedIn is useless

Posted on 2023-10-16 14:16 +0100 in Tech • Tagged with LinkedIn • 2 min read

I have a LinkedIn profile more by accident than on purpose. For most of that site's early days I just ignored it, even needing to go to the trouble of aggressively marking emails from it as spam as it seemed to want to turn itself into some sort of online networking cult, encouraging folk to send invites to their contacts, or worse. But after job-seeking in late 2017 the recruiter who found me the position I took up asked if I might join up and endorse him or some such nonsense and, at the time, I thought what the hell.

Since then though I've mostly found it useless, and at times straight up horrific. Don't even get me started on how a previous employer's push to make everyone use their profiles as more company branding created a perfect pool for people to go phishing in, while at the same time IT were on a phishing-awareness push; a perfect illustration of how some people lose their minds when it comes to that site.

The last year though, while working in a more FOSSy world, I've started to dip my toe back in when it comes to linking to what we're building with Textual. As such, I drop into the app once or twice a week and look to see what other folk might be talking about too.

During a recent dip in I saw this:

A suggestion from LinkedIn

Huh! Okay! That... that's actually kind of sensible! While I'm nowhere near looking for anything else to do, showing off the public projects you care about seems like a good idea. GitHub repos can be a good CV, I believe.

So I click through...

The project add form

And that's where it all falls apart. Pretty typical for LinkedIn I'd say. Name, description, obsession with skills, obsession with building up a social graph. But...

No link to the repo.

No.

Link.

To.

The.

Repo. O_o

o_O

I can't even.


Going full Apple search

Posted on 2023-10-14 08:39 +0100 in Tech • Tagged with Apple • 2 min read

For as long as I've had a smartphone -- so ever since the HTC Magic was released -- I've used whatever search tool Google have had available as my way of searching for stuff from my phone. Even when I made the switch to the iPhone, back when the iPhone 11 was around, I still installed and used the Google Search app.

Since jumping ship from Android to iPhone, I've followed the usual track that some do of "embracing the ecosystem", and it generally has paid off. The more I lean into "the Apple way", the more stuff actually does work together and work together well (I won't say "it just works", because that can sometimes so very not be true, but really I do find that Apple's ecosystem is more coherent and more stable than the one Google provided). But searching for stuff... that stuck with the Google search app.

So, more as an experiment than anything else, starting this morning I've removed the Google search app from the home screens of my iPhone and my iPad and I'm going to force myself to use Spotlight to do all my searching, and see how I get on with it.

Searching with Apple

Of course, when it comes to searching for stuff on the web, it's not going to make a whole heap of difference; it's sill going to end up searching with Google, but I do like the idea of search leaning into what Spotlight knows about my stuff too.

Also, on my phone at least, it has the added benefit of freeing up a slot in the dock at the bottom of the home screen.


astare v0.8.0 released

Posted on 2023-10-10 21:42 +0100 in Python • Tagged with PyPi, Python, coding, Textual • 1 min read

textual-astare is another Textual-based Python project that I've developed in the last year and I don't believe I've mentioned on this blog. Simply put, it's a took for viewing the abstract syntax tree of Python code, in the terminal.

astare in action

I've just made a small update to it this evening after someone asked for a sensible change I've been meaning to do for a while. When I first read the request I was going to look at it next week, when I have some time off work, but you know how it is when you sit at your desk and have a "quick look".

So anyway, yeah, v0.8.0 is out there and can be installed, with the main changes being:

  • Updated textual-fspicker
  • Updated textual
  • Made it so you can open a directory to browser from the command line.
  • Made opening the current working directory the default.
  • Tweaked the way dark/light mode get toggled so that it's now command-palette-friendly.

I think the code does need a wee bit of tidying -- this was one of my earliest apps built with Textual and my approach to writing Textual apps has changed a fair bit this year, and Textual itself has grown and improved in that time -- but it's still working well for now.


All green on GitHub

Posted on 2023-10-01 09:14 +0100 in Coding • Tagged with GitHub • 2 min read

In about a week's time I'll have had a GitHub account for 15 years! I can't even remember what motivated me to create one now, but back in October 2008 I grabbed the davep account...

Making my account

...and then made my first repo.

First repo made

My use of the site after that was very sporadic. It looks like I'd add or update something once or twice a year, but I wasn't a heavy user.

First few years

Then around the middle of 2015 I seem to have started using it a lot more.

The next few years

This very much shows that during those years I was working on personal stuff that I was making available in case anyone found it useful, but also leaning heavily on GitHub as a (a, not the) place to keep backups of code I cared about (or even no longer cared about). Quite a lot of that green will likely be me having a few periods of revamping my Emacs configuration.

The really fun part though starts about a year ago:

Working on FOSS full time

It's pretty obvious when I started working at Textualize, and working on a FOSS project full time. This is, without a doubt, the most green my contribution graph has looked. It looks like there's a couple of days this year where I haven't visited my desk at all, and I think this is a good thing (I try really hard to have a life outside of coding when it comes to weekends), but I'm also delighted to see just how busy this year looks.

I really hope this carries on for a while to come.

Apparently, as of the time of writing, I've made 12,588 contributions that are on GitHub. What's really fun is the fact that my first contribution pre-dates my GitHub account by 9 years!

My very first contribution

This one's pretty easy to explain: this is back from when I was involved with Harbour. Back then we were using SourceForge to manage the project (as was the fashion at the time), and at some point in the past whoever is maintaining the project has pulled the full history into GitHub.

My contribution history on GitHub is actually older than my adult son. I suspect it's older than at least one person I work with. :-/ 1


  1. I'm informed that this isn't the case2; apparently I'm either bad at estimating people's ages, or bad at remembering them; or both. 

  2. Although it's not too far off. :-/ 


Mandelbrot Commands

Posted on 2023-09-29 12:42 +0100 in Python • Tagged with PyPi, Python, coding, Textual • 2 min read

I don't think I've mentioned it before on this blog, but some time back I decided it would be fun to use Textual to write a Mandelbrot explorer (simple Mandelbrot explorers have been another one of my favourite known problem to try an unknown thing problems). Doing it in the terminal seemed like a fun little hack. I started off with creating textual-canvas and then built textual-mandelbrot on top of that.

Not too long back I added a "command palette" to Textual (I'd prefer to call it a minibuffer, but I get that that's not fashionable these days), but so far I've not used it in any of my own projects; earlier today I thought it could be fun to add it to textual-mandelbrot.

Mandelbrot commands in action

Most of the commands I've added are trivial and really better covered by (and are covered by) keystrokes, but it was a good test and a way to show off how to create a command provider.

Having started this I can see some more useful things to add: for example it might be interesting to add a facility where you can bookmark a specific location, zoom level, iteration value, etc, and revisit later. The command palette would feel like a great way to pull back those bookmarks.

What I really liked though was how easy this was to do. The code to make the commands available is pretty trivial and, I believe, easy to follow. Although I do say so myself I think I managed to design a very accessible API for this.

There's more I'd like to add to that (the Textual command palette itself, I mean), of course; this was just the start. Support for commands that accept and prompt for arguments would be a neat and obvious enhancement (especially if done in a way that's reminiscent of how commands could be defined in CLIM -- I remember really liking how you could create self-documenting and self-completing commands in that).

All in good time...


Apple Design

Posted on 2023-09-23 08:10 +0100 in Tech • Tagged with Apple, iOS, iPhone, design • 2 min read

As someone who started out in the Android ecosystem when it came to smart phones -- starting out with a HTC Magic and going through a few different phones before settling on Pixels (until I finally jumped ship to iOS in 2020) -- I have to admit that there's always been something nice about the design of iPhones. iOS, less so... My first exposure to iOS was back in 2015 when I got an iPod, and I wasn't terribly impressed. It looked okay, but it felt so far behind Android in terms of functionality.

Much has changed and improved since then. These days, 3 years into being totally consumed by the Apple ecosystem (one day I should write a post about how comprehensively I've moved over), I'm won over and I like how iOS works now.

Except this...

Bad design

That thing where, when you're in one app, it will show the most useless link "back" to another app, and in doing so bump the time up and out of the way a little. Like, seriously, compare it to when the app link thing isn't there:

Good design

Once you see it, you can't unsee it.

Toggle of the two images

After all this time you'd think they would have found a less janky way of doing this; perhaps even simply removed it (I can't remember the last time I needed or wanted the ability to go "back" an app like this, especially not with the bottom-of-screen swipe gesture being a thing). If nothing else you'd think that, by now, they'd have found a way of doing it that doesn't look so terrible.

The "eh, let's just shove it here" approach that seems to be on display here almost reminds me of the "time wiggle" that used to mildly annoy me back on my iMac.