Meme Overflow

A few months ago I was looking through questions posted to the Raspberry Pi Stack Exchange site. If you’re not familiar, Stack Exchange provides Q&A sites like Stack Overflow for specific areas, such as particular programming languages, technologies or other topics. And while observing the erratic nature of the way people post questions to the site, I thought “wouldn’t it be funny to take questions from Stack Exchange and put them on meme templates?” and it seemed like a trivial enough task to automate, so I started googling things, and typing stuff into a Python shell, and within an hour or so I had it working. The results were random and hilarious, as I expected.

Sometimes ideas like this seem simple in theory, but in practice there’s some complexity you didn’t think of that gets in the way. But with this idea, everything was smooth sailing. I found the Stack Exchange API easy to use, and came across the imgflip site, which provides an API. All I needed to be able to do was retrieve question titles from a particular Stack Exchange site, and to add text to a random meme template. Both of these things were trivial, and as I’ve done a lot of things using web APIs in Python lately, all the skills were well practised, which helps a lot.

Once the concept was proven, I decided to set up a Twitter account for the memes. I added code to tweet the images. Again, this is something I’ve done a lot of, so no hassle. I forget how long it took to get the app approved and the bot working, but before long, @pi_stack was tweeting out memes autonomously.

Hit and miss

Meme templates are chosen randomly, so obviously not every question / meme combination will work. Some will never be funny, some won’t be a good match, some will end up on a template that doesn’t really work. Over time I got to see which meme templates would never work, and blacklisted them. I also made sure that text was placed in the correct position for most effect: some templates work better with the text in the second or third position than the first – and as I only have one piece of text to add, this makes all the difference.

Later I decided to add some logic to choose the right meme template based on simple rules like “starts with X”, or to use a different template if it “doesn’t end in Y”. This seemed to make a big difference, though it’s still very hit-and-miss.

The test suite

I decided to create a test suite so I could more confidently make changes to the library without risking breaking things. Even though this is a silly side project, it’s been another way for me to exercise good practice which makes it easier when you need to do this stuff for real.

In gpiozero we have a mock pin interface which allows us to test the workings of the library without running on real Raspberry Pi hardware. And in the test suite we use patch to mock behaviour. I had to learn some new techniques for mocking things like web requests, image uploads and even tweets. I’m sure my methods are far from perfect but it’s a decent attempt with good coverage. Check out the tests and coverage.

Instances

I started with the Raspberry Pi Stack Exchange, and later added other instances:

If you’re not familiar with the concept of “world building”, it’s for people who are designing worlds for books, stories, games and such – and have questions like “What is keeping my Terror Bird from being the size of a T. Rex?” which are perfect for this project.

I’ve tried to set up more (there are so many great Stack Exchange sites) but Twitter is not letting me authenticate more accounts with the same mobile number.

Best in show

Here are some examples that worked well:

One of the best ones ever was extremely unlikely. It was a template that almost never works, because it really requires two pieces of text to make sense. But in this one case, it was perfect. In the RPi.GPIO library, Python warnings are switched on by default, and you have to turn them off. Most people find them annoying and include the line that disables them. The problem with Python warnings is that they look like errors/exceptions – people see red text and think there’s something wrong with their program – when really it’s working fine but it’s just letting them know something unimportant like they’ve already configured that pin. So someone on Raspberry Pi asked about the warning message, posting just the warning text (verbatim) as the question title, where the desired outcome is that no warning is output. And – by chance – this subtle genius comes out of Meme Overflow:

Another recent one was from World Building. Again, completely random:

Is anyone following?

The Stack Overflow bot is the most popular, with nearly 500 followers at the time of writing. Raspberry Pi and Ask Ubuntu have over 100 each.

Run your own instance

If you want to run your own bot following a particular Stack Exchange site, you can pip install memeoverflow and use the example script, following the simple guide.

If you want to run a modified version, you can either fork the project or subclass the provided class.

Mr President

Barcamp Blackpool 2012

This weekend was Barcamp Blackpool – held at the Norbreck Castle Hotel in North Blackpool. It’s the fourth event they’ve run since it kicked off in 2009 – and the second I’ve attended. Last year was great fun but I only stayed for the day – this time I stayed the night before and the night after, which exponentially increased the level of fun!

The pre-barcamp social was held at the West Coast Rock Café, where Robie and I had a “Big Pig” Burger and Ash had a 20oz steak. Don’t believe me? Here it is:

We had some laughs and I discussed music with Alex (aka “The Error Messages Guy”), which led to me debating with Mike about which Tony Hawk’s Pro Skater soundtrack featured the NOFX song The Separation Of Church And Skate.

In the morning we strolled downstairs for breakfast and headed over to the event where people started to congregate. Seeing the familiar faces and a few new ones, I chatted away. I noticed Freaky Clown had arrived, so I went over to introduce myself. I saw him speak at Hack To The Future and we’ve chatted via email and twitter but never properly met. He’s a very interesting guy – a grey hat hacker who goes by an alias. He works in penetration testing and computer security and takes an interest in lock picking. He blogs about his findings at The Grey Hats. He had been observing me throughout the day and watched me enter my phone’s unlock pattern, and told me he had. He also went round stealing people’s identities:

Following an intro talk from the utterly amazing organisers Lally and Les, the board kicked off and began to fill up. Failure on the part of Ash, Robie and me meant that none of us had, as we intended to, prepared a talk to give, so we just waited to see what other people were talking about. I browsed the board and saw a few interesting topics but with getting tied up in conversation with various people – including my old friends from Magma, I didn’t make it along to any talks in the morning. While chatting with Jack, I spontaneously decided to put down a talk I’d given at the first Manchester Raspberry Jam, but unfortunately I didn’t have the slides with me – so I’ll save it for another time. While chatting, Martin brought up the fact that (in his opinion) I want to swap my Android phone for an iPhone, and I explained to the group that it wasn’t true, and obviously they all played along saying I had an iPhone.

In fact in the end I only made it along to two talks – both by Freaky Clown. The first about image manipulation (detecting nippes in a folder of photos, etc.) and how easy it is to find out where someone lives by the EXIF data embedded in the photo file; the second on how he hacked the world in 7 seconds. Both excellent talks – I highly recommend you go see him talk if you ever get the chance. During his first talk my phone bleeped and he jokingly referred to it being my iPhone. Hilarious, FC. Following the closing remarks where I picked out raffle tickets for prizes (Android phone holders) and Gemma (who was the previous organiser) thanked Les and Lally, we headed to the bar. Drinking commenced, followed by dinner.

During Alex’s comedy act in the evening (involving vintage computer games) I was asked to go up to the front to demo a game of music management game Rock Star Ate My Hamster on his ZX Spectrum – a game brought out the year I was born – 1988! I got up to the front to play on it, sat down at the keyboard and realised I’d left my phone, tablet and netbook on the table. I had been sitting next to Freaky Clown. He’d seen me enter my unlock patterns and passwords that day so he could probably get in to them with ease. I was somewhat concerned. When I got back I expressed my concern (admitting my foolishness) and he said he wouldn’t do anything like that…

This was followed by more drinking and a couple of games of Werewolf:


I’ve never played Werewolf before, and the rules weren’t explained before we started playing, so I had a really weird experience. Things happened, I didn’t really follow why. People accused each other of being werewolves, rapists and other things, and some people seemed to get voted out of the game. Every time I shut my eyes I had no idea what, if anything, was supposed to happen. It reminded me of the sorts of games we played in Cub Scouts (wink murder, that sort of thing) but because things happened when my eyes were shut I couldn’t really figure it out. Every time I shut my eyes I had to convince myself this wasn’t some elaborate trick where I was being trolled by Ash, Martin and the others. I was eventually “killed” and left the game at that point. I went over to Tim to demonstrate my Rubik’s Cube solving ability, and went on to rejoin the group for a second game. I kept quiet most of the game while I tried to work out what was going on. It got down to there being four of us and I felt like I had to say something, so I sounded my view that of the two other people than Ash and me, one of them had aired deductive reasoning and the other only spoken up with jokes and messing around, but said it in a really vague way that Ash didn’t get, so they ended up voting to out the other one and if I’d have managed to get my point across I’d have been proved right and we’d have won. I understand the game better now and look forward to playing again. After that, I had my sexuality questioned by Martin’s girlfriend and we talked about Adventure Time. I then solved the Rubik’s Cube so fast it fell apart in my hands:


A few people asked me what the reason behind the emerging micro meme ‘MORNING BEN’ they had witnessed on Twitter. I explained the full story to a few people over the weekend – it starts with a few of us noticing that someone, who shall remain anonymous, always taking the opportunity to put me down and correct me over the tiniest detail, and us joking that if I were to say ‘Good morning’ and it was 12.00 or 12.01 this person would leap at the chance to say I was wrong. So Farkie started saying ‘MORNING BEN’ to me at 12.00 every day. And then Martin saw it, and did the same (not knowing the in-joke), and other people would see one of the tweets, at various times of the day, and do the same. Then a few more people tagged on, assuming the joke was just to say good morning to me in the morning. So now, most days, I get a bunch of tweets with ‘MORNING BEN’. Usually in the morning, which is ironic. And with the iPhone thing that’s now caught on, why not add that in? And call me a hero, like the papers did last week:

Had a fantastic weekend – great to catch up with friends and meet new people. I really feel at home at places like Barcamp, where people share my sense of humour and geekery! Where would I be without it? Probably here.