- Podcasts
- Python Bytes
- #38 Hacking Classic Nintendo Games with Python
#38 Hacking Classic Nintendo Games with Python
Python Bytes
- August 9, 2017
- 25 min
- Episode 38
About this episodeTopics covered in this episode: [more] Hacking Classic Nintendo Games with Python Bokeh Mosh (mobile shell) (bonus) Twilio Voices Extras…
- [more] Hacking Classic Nintendo Games with Python
- Bokeh
- Mosh (mobile shell)
- (bonus) Twilio Voices
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#38 Hacking Classic Nintendo Games with Python
Hey, Brian. Hey. Now, you also worked with Michael on the Python Entrepreneur course, right? Yeah, exactly. And I've been on Michael's podcast a couple of times, so he's always a great interviewer. Yeah, I was having trouble not grinning and laughing during that, because I'm usually waiting for Michael to get done with the intro.
Yeah, so I was at PyCon this year. I try never to miss it. I would unfortunately miss PyCon last year, and I vowed never again, because it's just my favorite event every single year. So I caught this talk. This is actually my colleague Sam Agnew's talk, which was called Hacking Classic Nintendo Games with Python.
And the gist here was he was using a Nintendo emulator named FCEUX. I actually don't know if that has a better pronunciation or whether people say it by the letters all the time. But he used that in order to change old school Nintendo games he was playing and interact with the audience during that PyCon talk.
It was pretty awesome. I missed it. So tell us a little bit more about this hacking Nintendo games. Yeah, sure. So Sam was inspired by the PyNES project. And he basically saw that you could use Python to interact with Nintendo games. And since he grew up on playing the old school NES Nintendo system, he wanted to use some of the old games that he had.
And then he created a Python application that attendees at the talk could text in different hex codes. And he was playing the game while attendees were changing the game on him. So it was kind of like adding cheat codes to the game while he was playing. So it was really cool to see sort of how he was able to interact with the audience, but also play some games that kind of brought out a little bit of the nostalgia factor.
Oh, that's cool. Yeah, I'll have to check that out. And the one other thing I really liked about it was he made certain topics that sound pretty intimidating, like hex editing memory values into what I think is a relatively beginner-friendly way to introduce it. He basically takes the hex memory values, explains what they do, and then you can see the results when you edit the values.
Like there was a game running, and we were watching the time left. He paused the game. Yeah, in Super Mario Brothers, the first one. Yeah, Super Mario Brothers. And then he changed the time back down to like zero, and suddenly, you know, his character died. And he said, okay, so that's how you hack it.
Yeah, so the emulator itself, there's multiple emulators you can use in order to run NES games. But the one that he was most comfortable with actually had embedded Lua in order to script editing the hex memory values. So really, Lua was only being used to input the hex values into the memory and then read from a file that Python was writing to.
Cool. I love that the Python talks are recorded. And to be honest, when I was there, I didn't go to very many talks, but I just spend the year between Pycons just watching all of the old ones. Yeah. So, yeah. So, Nick. That's awesome. Speaking of conferences, I wanted to bring up an article that Eric Holscher put out just recently.
And apparently, he brings it up at the beginning of his talks a lot, and he calls it the Pac-Man rule at conferences. And it's just a short little article, but I really like the visual of the little Pac-Man with a little gap. So the idea, and I'm just going to quote exactly what he says, is when you've got a bunch of people in a group, like when you're meeting new people at conferences or something, to make sure that there's a gap.
So when standing in a group of people, always leave room for one person to join your group. Leaving room for new people when standing in a group is a physical way to show an inclusive and welcoming environment. And just the whole idea, I know that I started out totally as an introvert because I got into programming, not because I really enjoy hanging out with people.
So it is a stretch for a lot of people, including myself, to try to go up to new groups of people and join conversations. And I thought this was a great tip to, when you're having a conversation in a group, to make sure that you're physically showing and visually showing that you're welcoming new members.
Yeah, I agree. It's almost like pattern matching for developers. When there is a, when there's room for one more person, you feel much more comfortable with just sort of approaching the group and, and asking people what they're talking about. So I think it's really good advice, both on the side where you're in a group already, but also when you're not in a group that, Hey, there's, there's some people that may want to talk to you and they've left you a spot at the table or where they're standing.
So Eric did a great job on this. Yeah, I think it's great. That was just a short one. And, you're going to talk about something that I really haven't had a chance to play with yet. And that's except for, I've had a chance to mispronounce it on this podcast and it's bokeh. Yeah. So if you take a look at the website, it actually can be pronounced two different ways, bokeh and bokeh.
So chances are you pronounced it correctly. You just thought you incorrect. We were incorrect in your pronunciation, but bokeh. I usually just say bokeh is a, is a Python data visualization library. And the output is designed for presentations in web browsers. So you don't have to write any JavaScript.
So, if you've ever used D3 JS, which is a fantastic data visualization tool, it's got a really steep learning curve. So if you really have just spent a lot of time in Python land, you can use bokeh to generate. These amazing data visualizations that are rendered in the browser. and you don't have to write any JavaScript yourself.
So that's one thing that I love about this, this library. And so I highly recommend you check it out because it just had a new release, which was, V 0.12.6. Just back in June. And it had a whole bunch of improvements and they're, this development team is doing an amazing job and they're gearing up for a 1.0 release, which I think is just going to make it.
If I'm doing something that's like super early, I'm doing exploratory data analysis. Whereas bouquet is sort of the building a beautiful dashboard and you want bar charts. So you want some sort of interactive visualization that you can then have end users be working with. Okay. I think that's a great explanation.
So yeah, I'll have to check this out. Yeah. So, and that's, and that's bouquet. And, and I actually, what's, what's funny is we, it always goes back to PyCon. I found out about this library at PyCon in 2015. Sarah Bird, who works on the core library, gave a fantastic talk where she essentially built an entire data visualization map, geomapping data visualization, like during her talk.
So if you have to have a connection to another instrument to run command line commands and you, now we live in a time where we've often work on laptops. And then you close your laptop and go home or go somewhere else and open it up again, that connection's gone and you've got to reestablish your SSH.
And there's also, you know, there's other problems with, with SSH, with keystroke, when you're displaying the interactiveness. And Mosh is an attempt to basically go down all the way to the protocol layer and redefine what gets transferred back and forth. There's a YouTube video that we're going to link to that it's actually, it's back from 2012.
And it's very convincing as to why we would want to do mobile applications differently than we've done them in the past at just the byte level. I'm just kind of wondering if people use, are using it. And that's just why I brought it up is it looks cool. I want to try it. I wonder if anybody else has used it.
And I haven't used Mosh myself, but it seems like SSH is a protocol that was designed to disconnect every single time I'm trying to write some code in front of an audience. So I will definitely have to check this one out, especially when I'm doing live code demos, because when your SSH connection drops in front of an audience and you've got to reconnect, it can be, it can be a real pain.
So this is pretty awesome. And the video actually is of a, he's doing a, there's, I don't know who's in the presentation, but there's a person presenting and they, they're connected to another system. And right in the middle of typing a command, he changes his wifi connection to a different connection.
And it just works. It like fixes itself. So it's cool. It's great. This is great having you on because you're talking about just about a bunch of things I've never, I've never used, but definitely heard about. And well, hopefully I get you excited enough to use them because there's some of my favorite tools.
And the next up is a Pelican is full stack on use doing, do you use Pelican for full stack? I do. Yeah. So a full stack Python, people luckily noticed that it's pretty snappy and that's because it's not, it has no database backend. It's all just a bunch of flat files that are served up by a content delivery network.
And that's all generated. I don't handwrite HTML, at least not for fun. I generate that with Pelican, which is a static website generator. So the way that I think about it is like static website generators basically have, I would say like three parts. You have your content, which might be written in restructured text or markdown, some sort of markup format.
It can also be other formats like XML or JSON, really any sort of output that you want. That is a file format, but I output HTML and then you can take those HTML files and you can host them anywhere. So the power is you have all your content in the markup format. So it's not like you're, again, modifying HTML directly.
The static site generator does all the work for you with its, well, what are called generators. The Python code creates, takes in the input and then outputs those, those file formats. And then you can just, you can host them anywhere. So the way that I think about it is that it's a, it's kind of like a throwback to the early days of the web when everything was like really snappy.
It was because you weren't connecting to databases via web application. It was just because you were being served up a single file or some multiple files that are basically just flat files. Yeah. There may be some Pearl on the back end, but. One of the things that's great about Pelican is, so it's, it's in under active development.
And so the latest releases version 3.7.1, 3.7.0 was released at the end of 2016. And that was like a major bump with a lot of good Python three compatibility. In fact, I only use Python three six with Pelican now. It works fantastic. So it's ready to go Python three out of the box and it's had a bunch of major work done to it.
A lot of bug fixes recently. So under active development, that's one of the things there's so many static site generators that are out there. It's relatively easy to create one as sort of a side project. But this one has been around for a long time. So I started using Pelican probably six, seven years ago now, and I still highly recommend it, which is if you're a developer and you've been using a tool for that long, I feel like that's a pretty good sign that it's a, it's a stable foundation.
Yeah, definitely. I don't know if you remember what it was like when you first started using it though. So if I wanted to pick it up and maybe say like, let's say I've got like some, I wanted to create internal to a company. I wanted to create a little site to, I don't know, document some process or something.
And, wanted to spin up a Pelican site, with a bunch of documents, I guess, in it. Is that something that's going to take a long time to learn how to use or is it pretty quick to pick up? No, it should be pretty quick. I mean, a lot of people think that static site generators just kind of for blogs, which is sort of the original purpose of a static site generator.
When they first, when some of the first ones came out, they were mostly used with like a blog format, but you can create any type of website with a static site generator. And you can even, even create like single page applications if you combine it with some sort of JavaScript framework on the front end.
Wow. Okay. And then Pelican will, actually generate the boilerplate that you need with the Pelican quick start program. And then you, you have your first static site. Actually, you could probably have your first static site within five minutes and then you can start customizing it and have something that you could deploy very quickly after that.
Well, that's definitely fast enough. And is your, is the tutorial, have, talk about, I guess it probably doesn't matter which Markdown you use. If you use Markdown or restructured. Yeah, I actually, I use Markdown on full stack Python, but on my personal site, mattmckai.com, I use restructured text.
You can kind of just take anything as input and it'll use that. It doesn't have to be segmented by projects. Does it tell by the extent file extension or something? Do you know? Yeah, you can, well, in the configuration settings, you can tell, you can tell Pelican which file formats you want and also which extensions.
So if you don't want to pick up your restructured text files, you can just have it pick up the Markdown ones, but you can, you can configure all that stuff in the, in the configuration files. It's pretty, pretty extensible. Nice. Okay. So the last topic I want to talk about was something that just helped me just now.
So in the last episode, I announced that I'm no longer writing the book, the book being Python testing with pytest. It's what I've been working on for like a year, but I was wrong. because right after I, we recorded that and I handed in all my documents to my editor, the pytest team came out with another version, the pytest 3.2.0.
And I did, I had just recent, just like the week before retested all of my, examples in 3.1.3. So what do I do? And what I'm doing is, just making sure they all work. So right now I'm, I'm going through all of the book again. And instead of having to do this every time I've decided I'm going to build a test framework to not a framework, but I'm going to build a set of tests that check the, all of the examples.
And make sure that the output is similar enough to the output I describe in the book so that it doesn't confuse somebody when they have a new version. And one of the things I'm using is a, is a tool called pytest watch. It's a pytest plugin. It's great because I've just got two windows open in, in two terminal windows while I'm editing these tests.
One of the terminals is running pytest 3.1.3. And one of them is running pytest 3.2 in two different virtual environments. And I've got pytest watch just looking at the directory. And every time I hit save on the tests, both of them go off and run. And eventually when I get all done with this, I'll probably convert it to talks or something so that I can run them all the time.
And it's a, it's a plugin that is used for the intended uses for testing plugins. But it's also used by the test code for pytest itself. And it allows you to run a pytest session and capture the output and ask things about it. Like was the string in there and how many passes, fails, skips, things like that are in there.
So, you know, 170 minutes, but. Any way to speed that up or you're, you're, you're happy. You're happy with it right now. There probably is. The, the slow part really is just the me looking at it. I could probably automate the whole thing and get it done faster. But I also want to be reading the book and while I'm putting these together to make sure that, because there's sometimes there, there'll be, you know, something minor, like, I guess not really minor differences, but I don't really want to just say I want the exact same output because if they added, you know, a period here or there, that's not that big of a deal.
So Twilio for folks who, who don't know, it, makes, makes it easy for developers to add communications, like phone calling, messaging and video to their applications. so if you've ever wondered, you've gotten, you know, you're working on a feature and, you're in the middle of a sprint and your user story says, okay, send a text message to somebody like, well, how do I do that?
How do I like interact with this global telecom network? Well, you could do that really easy with Twilio is API. So yeah. So that's my, my day job. So in addition to working on full stack Python, I work at Twilio, which has been, which has been really great. I've been there for almost four years now.
That's great. And, you're also working on, there, a project called Twilio voices. Yeah. So Twilio voices is something, a new project I've been working on and it's, probably of interest to listeners because we pay developers $500 for each published technical blog posts that they, they have on the Twilio blog.
The way that I see it is like the 500 bucks is a good way to get past the procrastination stage of writing a blog post. And then we promote that blog post to everyone in our different channels. So a lot of times these blog posts can be read by tens of thousands of people. For example, there was one called a wedding at scale, how I automated my, with Python and Twilio and Google.
I mean, basically it was a developer who was talking about how he automated all the text messaging and communication for his wedding through a Python script that he wrote, which was a really cool story. So the whole idea behind Twilio voices is people have all these awesome hacks and applications that they've built.
Tell us a story about it and show us how show readers, how to build what you built. It doesn't have to use Twilio can be basically just any, any code that you've created, as long as it's a, if it's a cool story or a good tutorial. So it doesn't have to be pushing Twilio. It can be just about anything.
no, cause we're a company for developers by developers for developers. and we've always been that way. So whether you're using Twilio or not, we want to see the code that people have written. And, one thing that's really great about this is every post goes through a rigorous review process, like an outline review, voice review, tech review to make sure all the code works.
So that like people who write these blog posts, make sure that their output is like the best that they've ever created, which has been really cool to see people say like, I never could have written a blog post that was like this polished. So we, we kind of put it through the, through the ringer to make sure that it's, the highest quality post.
Happy to do it. Thank you for listening to Python Bytes. Follow the show on Twitter via at Python Bytes. That's Python Bytes as in B-Y-T-E-S. And get the full show notes and links to things we talked about on the show at Python Bytes.fm. If you have a new story you'd like featured, just visit Python Bytes.fm and send it our way.
