 Next, we have ENDs who, amongst other contributions to our community, has helped raise the utilic kiln quotient. Yes, ma'am. Who's one of two. And for some reason, he decided not to worry his kiln while talking. I think there might be some cartwheels, so that is maybe a good thing, maybe not. Either way, ENDs. My slide's visible behind me. Hey, alright. Nothing says confidence like a ransom note. Here's a little more of a stated title. You guys start to count down the clock, because I feel like I'm going to run out of time and finish early. So the title of this talk, Playfulness at Work, is sort of a two-fold meaning. There's the angle of being playful, having spirit of playfulness while at work, and then there's the angle of the way playfulness works on us and on our co-workers, on our teams. So it's sort of being the talk in both of those senses of the word. We'll get to that a little bit. First thing I really like to do is, and this is the least original slide in this entire conference, because we've already seen it just like this yesterday. But I think that's a sign that speakers and attendees are really pleased and enjoying themselves. Would you guys give me a hand and join me in thanking our hosts, the city that we're in and Rubius, the code here. They made so much software. This is just the scrolling list of the software that Rubius... If you use Ruby, somebody in this town has written something that makes your life better in all probability. And wow, it just goes on and on. I'm going to talk about just real quick a couple of these that I'd really like to share with the Seattle community. And that's the chain of code flogging tools, flay, flog, heckle. These things will watch for that cyclomatic complexity that we've heard about earlier in your code. They will mutate your code and inject bugs into it and see if your tests catch it. Has anyone not used one or all of these or some combination? If you haven't, feel free to catch me up in the hall. I would be happy to embarrass myself by showing it to you on my own code. I think you can feel a lot of words. And now on to the talk. So I work at Techtronix, we're a hardware company. We make these oscilloscopes. I find it satisfying. There's something physical about this actual device that comes out and its ability to appear into the invisible world of electrons and see what's going on inside a circuit. So from that point of view, it's really gratifying. It is a big code. We've heard about Ruby in the Enterprise. Anybody work at Big Co's? I couldn't see all the hands yesterday because I was in the audience. So yeah, there's a certain set of trade offs you make when you're working at Big Co. A few aggravations and Ruby is one of my vehicles for keeping sane in that department. And that's part of what I'll be talking about today. And I think the need to stay motivated, stay passionate, stay sane is something that applies no matter what kind of company we work at. So why this talk? And in particular, you know, why Ruby? Why don't I use some other vehicle to carry out all the little blue code tasks that I need at work? Sometimes the... So I'm supposed to be writing, you know, not only like a vetted firmware, but sometimes, but what I'm really supposed to be doing, as we heard from Richard yesterday, what we're really supposed to be doing is making something that makes someone's life better. Supposed to be making something that sells a call for somebody. Yes, sometimes that means writing a vetted code. Sometimes it means writing a Ruby script. Sometimes it means slapping a web front in on some data. Sometimes it means writing a document. Sometimes it means writing nothing at all. Nothing at all. Stupid sexy flanners. So I know I'm not the first person to have the world's most interesting man in a slide. I wrote this before I saw that slide, but, you know, in keynote, you can't delete slides. You can only just keep adding new ones on in the end. This was originally supposed to be a lightning talk, but it's up to 70 slides now, so... So anyway, sometimes Ruby is the right tool for making something happen, even if, you know, my company doesn't even know I'm doing it. So that's why we do this, right? And all these sorts of questions, why Ruby? Why this talk? Why bother Ruby? I feel like these questions are leading somewhere. And so I thought back to this great little essay I read when it came out back in 2004. And has anyone read wearing Ruby slippers to work, the old essay by Why the Lucky Stiff? So this was at a newer time for Ruby. Fewer people had heard of it, especially in, you know, the Enterprise. And so this was a way of sneaking Ruby in to keep yourself happy and motivated and sane in your job. And he was going at this for the point of view of, like, directing through log files and doing little blue code tasks. And Ruby's fantastic in that kind of stuff, but we're not stuck there anymore, right? We saw yesterday that Ruby's one of the top 10, top 20 languages. People have heard of Ruby. You're not going to get funny looks when you say, I'll just use Ruby for that. And so now I'd like to move into the more specific portion of the talk and show, like, four little vignettes of specific things you can do with Ruby to help make your life better at work. And really this is, these are based on things that we've done at work that have just, we needed to do some task and we did it. But what I'm really hoping is you can see some library that I mentioned in passing here that may be self-sum need for you and be able to apply it. So I'll be talking about four different vignettes. One's dealing with crusty data formats in a lighthearted way. Another is scripting other people's software, whether they know that you are or not. A third one, sharing code with co-workers. And the fourth one, sharing code with honest-to-goodness people who give you dollars and want some software. Okay, ready? Let's talk about data formats first. In any big enough company or company to run long enough you're going to have piles of little ad hoc files where everybody maybe started pasting log results into a file where they started tracking their hours in a file and it just sort of organically grew up or maybe it's a weird file you got from a customer or something that there are a lot of times you need to crack open some weird piece of ad hoc data. And Ruby provides great tools for doing that. So I'm going to just sort of make up my own ad hoc format. So you heard of Task Paper, the to-do list tracker. Yeah, they use a plain text format called Task Paper and I'm going to take everything good out of that format and just talk about a tiny subset out of it just so we can have something to throw our code examples at. So it's just a to-do list. The item is a dash in a space and it can contain subtests and that'll keep us pretty plenty busy for the next few minutes. There are a lot of new tools in Ruby to do this. I'm going to talk about Parslet. The neat thing about Parslet is unlike so many other parsing tools you don't have to run a generator. You don't have to write your grammar in some other format and then generate your final Ruby or C or whatever code. You just express your grammar right there in Ruby and Parslet will give you sort of a raise in hash tables representing the structure of your document. So just as an example, here's one task, the input line here in the middle and we expect it to come out with a task called Task and a tag here and I'm using many tests by the way because we're in Seattle. So here is the rule that satisfies that. I've copied the task up here so we can see a task starts with the beginning of Task Marker. It has a description and then maybe some tags and in Parslet you just say exactly that and beginning of Task Marker, a description and maybe some tags. And now we have to define those rules. Now if we had lots more room in space we might actually write little unit tests for each one of these. I'm not going to bother today. These are kind of the basic building blocks of the task format so we don't really have to drill down much further. I just want to point out in Parslet you can match exact strings, you can match reg X's, you can specify how many times something is allowed to repeat and now we just have to drill down to flush out that tag. So a tag is a beginning of Task Marker, one or more tag characters and then a space. And the other thing is you can call these rules individually so when you're writing you're going to test. If I want to test just the code that formats to recognize as a tag I don't have to construct an entire valid to-do list document. I can just say act tag and I can call just that rule for my test. It's very nice for getting off the gun or running. But anyway that's enough to get our test passing. So yay. The only thing left to take care of is subtasks. So we'll do that real quick. Here's another mini test. Here's that same to-do list from earlier. And here's the structure we'd expect. This one's a little more interesting. We've got three top-level tasks and the first one has some subtasks. And parcel it comes with some stuff where you can take this format and automatically turn it into ruby classes that you would define. So you might write a task class or a tag class or whatever. And we're not going to get into that today but you don't have to stop once it's in this first representation. Anyway we'll throw our assertion down at the bottom here and this is all the code we need to make that pass. And the only thing I'll point out is that a rule can be a function. Kind of like an active record where you can have a scope or you can have a scope defined by a method on the class. So these are just recognizing a line that's been indented over by a certain amount because it's got a certain number of spaces. And then finally a task. And see this as block here. It sets the keys in the hash table. You tag all the parts that are important with this as and the main parcel that throws away everything else all the punctuation. And now our task class can move on to the next vignette. Scripting other people's software whether they know it or not. So this is based on a little bit of a horror story where we were asked to support a format from a vendor like hey, it'd be really great if you guys could support XYZ format. And of course the only program on earth that could understand that format, bless you, was the vendor's application package. There was no spec. It was an obscure binary format. There was no API. We couldn't grab hold of some automation interface. So what do we have to do? We can say no. We can try to reverse engineer the API by dumping the binaries. Or we can say let's just drive this thing through the GUI. And for something really quick and dirty something with the right half of the ass then driving through the GUI might be just fine. I'm just going to, rather than shame the vendor, I'm just going to write like a PNG to black and white in that converter which works by driving Microsoft Paint a pixel at a time. This will just let us show how to use a couple of livers. One is a chunky PNG. It does some basic image processing and it's pure ruby so if you're deploying you don't have to worry about binary gems and all that stuff. So here's how we would slurp a PNG in and there are better ways to do this but we're just going to loop through all the points and say if it's darker than a certain amount throw it in our list of coordinates of dark places. And then to actually grab hold of the user interface we're going to use FFI which is the foreign function interface allowing ruby to call in C. This started in the Rubinius project. The JRuby people adopted it. It's also a Ruby gem so you can get it in MRI in 1819. Which means that if you need to call some C code you can write some ruby code and have it work across four different current popular ruby implementations which is kind of cool. And the way it works we only need two Windows API functions for this, thank goodness. They're called setCursorPos and mouseEvent and if you know their C signatures you can declare those C signatures here in ruby. You can see this vaguely looks like a C function signature except the return type is at the end. And you have to tell it what object module do these live in. They live in user32.dll and the calling convention is the Pascal calling convention which Microsoft braidingly calls standard. And so now to call it to click the mouse you move the mouse to a certain spot. You move the left button down and left button up. Do the hokie-pokie, that's what it's all about. So now we can go through all the show the points we retrieved earlier in one by one. Now if we were doing this for real we would poke around at the user interface and we can this part of it but we're just going to assume it's maximized and move over 100 pixels each way to avoid the toolbar, the menu and stuff. Now it turns out there's an even faster way to write this code. There's a gem I found actually while writing this presentation. Oh, wow. Somebody has already done the work of abstracting away mouse inputs and window pointer motion and that kind of stuff. It's called WinGui and we could throw away those last two slides of FFI code and just find the window and just regex and do this stuff. And so the story has a happy ending. We, you know, we got it working. We had a proof of concept. Bonus points for the first person to identify the color of the garment in the original picture. Three. That's what you saw, I warned you of one internet. And so we had this proof of concept in Ruby and we were able to convert it to C with basically some EMACs and macros, which is great, and then, you know, we were able to convince everybody this is a terrible idea, throw the whole thing away, but at least we proved that we could do it. So, sharing your code with the code would prove that annoyingly too much. So this is about, you know, you print out the whole screen scraper, that little Aaron Patterson image cloner, and you want to get it onto somebody else's machine and if you're at a workplace and there's a chance that they might be running, I don't know, maybe Windows or something, so you can't just count them having Rfium install and Ruby interpreter shipping with their system. But if they're coworkers and they don't mind a little bit, you can just handle the source file and say, here, run this. That used to be, you'd handle the source file and go here, there's one authoritative, just go find the Windows binary at this site and it just works. And then suddenly there were two rubies and they're not of that two different compilers, so if you, you know, as long as you were careful not to write incompatible code, you were fine unless you needed the gem that had C code in it, like the MySQL bindings or NoCogiri or anything interesting, in which case it had to be compiled with the right compiler for the right Ruby version that would get big nasty error dialogues if there wasn't a pretty match. But now the story is really good because MinGW has won thanks to the efforts of Luis Lavena and the Ruby installer team and so now you tell your co-worker go download this particular Ruby install and if you need binary gems you can have them extract the dev kit right over their Ruby and they say gem install foo and lo and behold it goes and compiles the gem if they need to, just like on a real computer. And you still have to worry about dependencies, right? If they're going to compile over here they've got to get libx and don't but it's a solvable problem, it's much better than it used to be. So another approach you don't want to have run from source if you press for time you can just give them an EXE that has a Ruby interpreter and your code and all your dependencies in it and there are a lot of ways to do this back in the early 2000s this guy named Eric Vanstra did a script of, sorry, a series of scripts called TARS and Ruby script and Ruby script to EXE I don't know why those weren't combined into one step and take your Ruby code and Ruby and just have a self extracted EXE that would quickly unzip Ruby to attempt directory run your program and clean up and it's tacky as it sounds but you know what, it worked. So the modern day version of that is called okra, the one click Ruby application and I'd just like to show you how easy it is to create a EXE to share with somebody. Let's just pick a guinea pig I just wanted a simple command line app so we could throw it together real quick and a beautiful bit of synchronicity yesterday Cori told us about a hue bot, the chat bot so there's a project called boom from Zach Coleman and I think this is what Zach Coleman uses to stay so alert in the chat room and be able to quickly blast in a picture of someone with a paper crown on their head and an animated jpeg of their lips he finds these URLs to these really cool pictures and collects them so he can quickly paste them in, boom is like a multiple clipboard manager and it works for the command line and so if we wanted to and there's a video on it Zach looks like I guess and if you wanted to make a self-contained EXE all you have to do is just make a two liner that runs boom and say okra turn that into an EXE and out of country program and it works so we talked a little bit about binary gems my favorite solution to the what do I do about my SQL bindings problem is to use JRuby because my SQL bindings are in Jar and I don't have to worry about whether or not they're compiled with the right compiler and Warbler is a tool that lets you bundle up a Ruby app in a single Jar file and so the equivalent of that workflow, we have our boom one liner, we stick it in the bin directory we add a gem file we install a gem to install and say and then out comes we have to rename it just hand that to somebody and it just runs and this is the way I tend to share code with most of my coworkers we've all got the jre installed on our IT mandated corporate machines and alright so that is sharing code to their coworkers where you can expect that they are willing to jump through a few hoops or you can expect that they have installed, what about people out there in the real world it's probably okay to post an okra executable and let them download it there's no official installer or anything but it works well enough we have actually done this, we've posted little utilities on our website so that our honest and good is paying customers who come and do a little auxiliary tasks and behind the scenes running okra and Ruby and nobody knows and everybody knows that we've provided it quickly and it works but if you do want to have a full installer for your program you could take the Ruby installer base that we talked about before and then add some post installation recipes right I want to install Ruby I need to install this set of gems I need to put some icons in the start menu and then I need to put my program here, you could do that but that work has already been done so an engineer I've got this project by Dr. Nick and Wayne Seguin I think Rails installer, they have done just that, they've taken the Ruby installer and added some recipes for other stuff so what they've done with that is install Git, Rails, a bunch of gems the database bindings, the database drivers, etc, etc and the nice thing is it's all spelled out in recipes in YAML files, config files and rake recipes and it's not too hard to dig in there and just substitute in your own program for those recipes so hypothetically what would it take to have a boom installer I realize I've been pronouncing boom this whole time because according to its creator that's the official way to pronounce it so what would it take to have that you just go in this file called railsinstaller.yaml and list out the gems you need and take out the ones you don't you go in the support directory that supports the rake tasks and you go to components and you strip out unless you want to install Rails and Git alongside boom then you would take that stuff out and the only really nasty part is you open up the installer script that uses a thing called inno setup which is an open source installation builder you kind of grip for Rails and say okay do I need to replace Rails with boom in this particular line it takes about five minutes, it's really easy and then license is an artwork there's a nice graphic of the Rails installer you probably want to turn it into some really awesome graphic representing the software that you'll be installing and then once you've done all that you just say rake package and out it comes I haven't posted the code yet because I've been getting slides ready but sometime during this conference I will take those steps that I've just done and put them in a branch in a fork of Rails installer so this ends the specific portion of the talk now we get to do a bit of kind of armchair philosophy and I talk about come back to this idea of playfulness and why that's important and I'm going to prove to you that anyone can cherry pick a couple of relevant anecdotes from brain science and kind of prove anything to anyone and make us all feel a bit about ourselves for using movie so I'm going to do that now there are a couple of interesting TED talks on the role of playfulness in the mind and in the team so I wanted this by Stuart Brown you can just search for it on their website and he talks about the way play affects the brain the way he says play lights up the brain in a way that's unlike anything else and I hope in a good way I don't know if they've actually studied this found out that it's a good thing and he goes on into the neurology of it and it's really interesting, it's a good watch and the other one is a probably unrelated guy named Tim Brown and he comes at it from the other angle of teams and organizations I think he's got some connection to Ideo the industrial design company and he talks a lot about the result they get as a team when people are encouraged to play and we're not talking about just laying like trust fall exercises we're talking about going about our entire jobs in a playful way and so I'll leave those there another thing I'll mention I found this book it quite surprised I had this on LP my parents had this audio book on vinyl back in the 80s it's called Drawing on the Right Side of the Brain and it was about how you've got this sort of parallel processor in your head that can help you deliver incredible results you can just figure out how to talk to it how to talk in linear sequential ways people don't call it the right brain anymore that's what they call it back in the 80s hence the title but the play feeds into that whole idea that we need play we need play to do our jobs better it's not just about staying happy it's not just about saying we've got to keep ourselves challenged and motivated it's also about doing better works that make us really deliberate and then finally this other book quite surprised me this is an airport reading book I picked this up expecting $10 worth of entertainment on a clean flight totally got that totally worth the $10 I expected to be like Dilbert in Real Life because that's kind of what the title leads us to believe here's the chapter on how to deal with the guy who steamrollers all of your ideas here's the chapter on how to deal with the guy that talks too much here's the chapter on how to deal with this jerk and the first time the book was kind of like that but then the book actually got really good after that it was this kind of Randy Poush style head fake where you think the book's going to be about this and it veers off into how to deliver great results in a big giant organization or a tiny one or a dysfunctional one and the authors talk about the idea of being a soloist so like an expert at your craft not necessarily working alone but working with a carefully chosen ensemble of like-minded people and that kind of brings us a full circle back around to Cascadia because here we are in a close inner circle reaching out to our friends as a kind of support group to help keep each other motivated and sane and productive and brilliant over the months to come and that's my hope for this conference and for us together is that Cascadia doesn't end here not least because lunch is next I'm looking forward to that but also that beyond this weekend that we find each other that we continue to push each other to do great things to use really wacky ways and therefore coincidentally make us do our jobs better and we have more fun and I would just like to close with that thought so long live Cascadia! cheers everybody