Random Python and WSGI tip

In light of the fact that Python 2.x loses support...now, I've been upgrading some of my personal projects that I haven't done much with recently to Python 3.  One of them is a little web-based comic book reader I call Linga (I don't remember why) that I run on my home network.

Since my home server runs Ubuntu 18.04 LTS, where Python 2.7 is the default, this has been a bit of a pain.  Before doing the conversion to Python 3.x, I had Linga set up and working using MySQL and Apache with mod_wsgi.  But once I pushed the code for the 3.x version, everything broke.  After digging in, there were several problems I needed to correct:

  1. The default mod_wsgi install uses Python 2.7, not 3.6 like I want.
  2. My WSGI script uses execfile(), which no longer exists in Python 3.x.
  3. SQLAlchemy can't load the MySQLdb module.

Luckily, the solutions to these problems weren't particularly hard to find or implement.  With a little Googling (well, DuckDuckGo-ing really, but that doesn't have the same ring to it) and a little experimentation, I found the following fixes:

  1. The version of Python to use is hard-coded into the Apache module.  So to use Python 3.6 I just needed to install the Python 3 WSGI module with apt install libapache2-mod-wsgi-py3.
  2. Apparently the recommended replacement for execfile("filename") is exec(open("filename").read()).
  3. It seems that Zen of Python's saying that "There should be one-- and preferably only one --obvious way to do it" breaks down when it comes to connecting to MySQL, as there are apparently several client libraries available.  The solution that worked for me was to pip install pymysql and run pymysql.install_as_MySQLdb() in my WSGI script.  Having to call a method to turn on MySQLdb compatibility is annoying and seems a little hacky, but it works and it's not really a big deal.

With that, Linga now works just fine.  Maybe this will save someone else having to Google the answers to these questions as well.

UHK case

If you saw my review post, you know that I have an Ultimate Hacking Keyboard.  And that I love it.  It's an awesome keyboard.  In retrospect, I wish I'd ordered two of them at the crowd-funding price.

Over the holidays I took some time off and wanted to take my UHK home.  Because, you know, maybe I'd have a chance to actually use it.  The only problem with this is safe transportation.  My UHK has palm rests and I keep it in a "tented" configuration, i.e. split with the inner portion elevated.  To fit it back in the box it came in, I'd have to take off the feet and palm rests, which requires a screwdriver.  It's not really difficult, but takes a few minutes and it's kind of a pain in the neck to do.  This is actually the only thing I don't like about the UHK - you can't reconfigure it without changing a lot of screws.  (Though on the up side, the fact that things are screwed together makes the entire rig feel very solid.)

What I really needed was a carrying case.  Unfortunately, they don't sell one on the UHK site.  I briefly considered trying to make one, but wasn't sure I had the proper tools and, realistically, there was almost no chance I was going to find the time to do it.  Luckily, the UHK blog did the hard work for me and collected a bunch of examples of DIY cases submitted by users.  

My UHK in its new case

I ended up choosing the second option and buying this case.  It's a hard-shell case with some padding on the bottom and egg-carton foam on the top.  It's actually built for some form of min keyboard/synthesizer, but it's exactly the right size and shape for a UHK with the palm rests still attached.  It works perfectly, required zero work, and cost less than $20.

Thank goodness Star Wars is over

My company has this cool tradition - when a new Star Wars movie comes out, they buy everybody a ticket to it.  In fact, for the larger offices, they even buy out a theater, which is really cool.  So, naturally, this year they sent us all to see Star Wars: The Rise of Skywalker.  And you know what?  I kinda wish they hadn't.

Warning: Spoilers Ahead!

I give that spoiler warning even though I don't think it's actually possible to spoil the movie.  Seriously, it's that bad.  If you haven't seen it, don't bother.  It's so bad I think it actually made Revenge of the Sith look good.

Lest I be accused of unfairness, let me clarify that I did not go into this movie expecting to hate it.  I hadn't read any reviews or rumors about it, so I really didn't know what to expect.  I like the previous movies well enough and expected the same from this one.  I thought The Force Awakens was good and while The Last Jedi had some issues, I still enjoyed it.  I didn't see Solo, but I liked Rogue One a lot (in my opinion, it was the best of the new movies by far) and have been thoroughly enamored The Mandalorian.  So I like Star Wars.  But I'm not a die-hard fanboy.  I'm not really familiar with the books, comics, games, or any of the other extended universe stuff - just the movies.  So I'm not looking to pick this apart in light of other sources.  All I'm really expecting is a good movie.  If not a great cinematic masterpiece, at least an entertaining action film.

I did not get what I was expecting.

On the up side, the special effects were top-notch, and the acting was generally fine given what the actors had to work with.  On the down side, everything else about the movie was awful!  The dialog was bad, but that's forgivable - this is Star Wars, not Citizen Kane, so you have to temper your expectations; the pacing was a mess, with suspenseful plot points that were resolved ten seconds later in the very next scene, like when you think Chewbacca is dead for maybe 30 seconds; the action scenes were a mixed bag, with some that were decent and others that were underwhelming, such as the big lightsaber duel on the ruins of the Death Star that actually inducing me to yawn.  But my main complaint was the story.

The plot of this film was just...impossibly bad.  And when I say that, I mean I actually find it hard to believe that it was written and approved by highly paid professionals working for a major studio with a huge budget.  It's the kind of story I would expect from a not-very-talented 13-year-old fan-fiction writer.  It's trite and uninteresting, full of holes and poorly motivated twists, loaded with plot points that don't really make sense, and littered with distracting and pointless "fan service" call-outs. 

Shadiversity has a good break-down of the plethora of problems with the plot, but I'll give a a short list of a few of my complaints.

  1. Palpatine?  Really?  Yes, the opening story roll, in the first 30 seconds of the film, reveals the twist that Emperor Palpatine is still alive and is planning to take his revenge on the galaxy.  It's never explained how he survived the Death Star or why he's been in hiding for however many years.  It wasn't alluded to in the previous movies, as far as I can tell.  But sure, why not?  Apparently they've just run out of original ideas.
  2. Another armada from nowhere?  The previous movies showed us the First Order, which apparently built a huge armada in the outer reaches of the galaxy and then started taking it over.  Well, apparently Palpatine did the same thing.  So now he has a gigantic fleet of Star Destroyers that also all have planet-killing lasers a la the Death Star.  Because...why not?  Apparently those are a dime a dozen now.
  3. Is it really that secret?  Palpatine built this fleet on the Sith home-world.  Much of the first half of the movie is spent trying to find the special navigation unit which will take the heroes to that planet so they can confront Palpatine.  Apparently only two of those units were ever made and they're the only way to get to the planet.  Kylo Ren has one of them and when he finds the planet, it's shown as being pretty much a barren wasteland with one big building (which for some reason seems to be floating about eight feet off the ground).  And yet they managed to build hundreds, if not thousands, of Star Destroyers here.  How?  Where did they get the resources?  And the crew?  So nobody can get there except for the tens of thousands of people who are responsible for those Star Destroyers?
  4. What's with the dagger?  The heroes find the coordinates at which to locate the above mentioned navigation unit inscribed on a dagger.  It must be an ancient Sith relic which will lead them to a long-forgotten temple or something, right?  Wrong.  It leads them to Endor and the wreckage of the Death Star.  So...that means that like 30 years ago, somebody knew that unit was in the Death Star and decided to...carve the coordinates on a dagger?  Why would you do that?  And then it turned out the dagger has some sort of pull-out thing in the hilt that allows Rey to match up exactly where in the Death Star the unit was.  No instructions on how to use that or where to stand to make it line up right - Rey just notices it's there and uses it at a random place.  The entire thing just makes no sense at all.
  5. What about that thing with Finn?  Two or three times they raised a point about Finn wanting to tell Rey about his feelings for her or something.  At least, I assume that's what it was.  It was one of those "he wants to say something, but never gets a good chance" things.  It comes up a few times and then they never do anything with it.  They just drop it and the movie ends without any attempt at a resolution.
  6. What happened to the Force?  The Force was always powerful and mysterious, but the previous eight movies established some precedents for the type of things the Force can do.  And that list did not include healing wounds, teleporting physical objects, or generating enough Force lightning to simultaneously attack an entire fleet of starships!  I'm not saying that new movies can't introduce new Force powers, it's just that this movie really piles them on.  It seems like at this point the Force has become "magic".  It can just do anything, for no reason, without explanation of how or why it's possible.

That's enough for now, but I could go on.  The entire movie is like this.  The characters are constantly doing things that don't make sense, seemingly at random, either to drive this ridiculous plot or as an excuse for some special effect.  And this goes on for over two hours!  There's no character development to speak of and the plot doesn't seem to develop so much as jump around.  It's as if they had a long list of things they were required to include in the movie and just tried to cram everything in without taking the time to make it work.  If it doesn't make sense, well, we'll distract them with this shiny new thing!  After a while, it becomes difficult to actually care about any of the characters or the story at all .  They just don't feel real enough to be interesting.

Overall, I regard this film as a disaster.  It's the first Star Wars film I can remember watching and not enjoying.  It has caused me to officially lose all respect for J. J. Abrams.  There were actually several sections where I actually started getting bored and wished it would just end.  If you haven't seen it, then don't.  It was a waste of two and a half hours.

Voice recognition can't spell big words either

Pro-tip: the voice recognition feature on your phone is not as smart as you.

Here's the situation: I was reading a political philosophy article that was discussing some ideas of Karl Marx because I was a philosophy major and this is the sort of thing we do in our free time.  Anyway, for some reason I wanted to look up the term "bourgeoisie".  The article didn't use that term, but it came to mind and I wanted to see if my understanding of how Marx used it was correct.  So I started typing the word into Duck Duck Go on my phone and suddenly realized - I don't know how to spell it.  (In my own defense, the word originates in French, which is notorious for spelling things in a way that is not intuitive to native English speakers.  Especially the ones who don't speak French.)

So, being a card-carrying computer geek, what do I do?  In a fit of blind optimism, even though I know better, I push the "microphone" button on my virtual keyboard!  I might not know how to spell "bourgeoisie", but I do know how to pronounce it.  Why struggle trying to figure out the spelling when I can just say it and let Android do the spelling for me?

Yeah, that didn't go so well.  Apparently Google voice control doesn't even know that word.  I tried several times and the closest it got was the quasi-phonetic spelling "booshwazee".  Although, oddly enough, searching Duck Duck Go for "booshwazee" actually does show the results for "bourgeoisie".  So in that sense, I guess it did work.  Kind of.  But not really.

Moral of the story: don't count on your apps to be more literate than the average user, especially in a multi-lingual context.  In retrospect, this should have been obvious.  What was I thinking?

The Joy of Gaming With Your Child

For this Christmas post, I wanted to share an experience from a couple of weekends ago that I hope will be entertaining, especially for any parents out there.  Let me set the scene.

As you may know, I have a young child - a seven-year-old son.  Like many (if not most) little boys, he really likes video games.  We limit his screen time, usually to an hour a day, but we allow him to choose what he wants to do with it.  He can watch TV, or use his Kindle, or, on the weekends, play the Wii.  (Not WiiU or Switch - just a plain-old Wii that we've had forever and barely used before he was born.)

Important background information: While my son is generally a very happy child, he's growing and losing teeth at the moment, so he's a little...difficult on some days.

So on this particular Saturday, around 3:30 in the afternoon, my son announces that he hasn't had his electronics yet today and would like me to play Wii with him.  OK, that's fine. Usually he wants to play Mario Kart or Super Smash Brothers, but the previous week he discovered Super Mario Wii, so that's what he wants to play.

Super Mario Wii box art Super Mario Wii box, courtesy of WikiMedia

This is bad news.  Why?  Because inexperienced seven-year-olds and platformers don't mix well.  His hand-eye coordination is still developing and he doesn't really "get" the puzzle aspect of platforming.  So, needless to say, he doesn't do very well.

Now, in the good old days of the original Super Mario Brothers, this would not have been a problem.  He would die quickly and then I'd take my turn and we'd go back and forth.  But Super Mario Wii is a cooperative multi-player game, so you actually both play at the same time.  And not only is it cooperative, but the players can interact with each other, meaning that you can bounce off another player's head, or push them along the screen.

At this point you might see where I'm going.  I'm sure this can be a very fun way to play, but when you're playing with someone who can't really control their character and doesn't fully understand the objective of the game, this is a recipe for frustration.  I end up playing the same levels over and over because my adorable and wonderful child whom I love very much keeps getting in my way and getting us both killed.

Fortunately, on this particular day I had the foresight to grab that bottle of Jack's Abbey bourbon-barrel aged lager wine that's been in the refrigerator for the two months (as I mentioned in my fitness post, I don't drink much these days) before I sat down to play.  That helped me get through the gaming session and see the humor in the situation.  But on those days when things aren't going well or I didn't get much sleep, these sessions can be very trying.

But at least he's having fun and hopefully building some good memories.  And he is improving, slow but sure.  So I'm glad we can do this together, even if it's not always easy.  Thus is parenthood.