 So I'm Eric Hodel and I'm with the Seattle Ruby Brigade and we're going to be talking about several of our pet projects since I'm This is here is Ryan Davis and we have Aaron Patterson Phil Hagelberg and in the back there is JD So since I get to go first for some reason so here go. Oh crap There we go. I had a fine Now you broke it. No. Oh, you unplugged it Take these broken wings Okay, so I'm gonna talk about my upnp project and so when I started this thing I Had this cool idea and it was I want to easily be able to watch movies on My PlayStation 3 from my laptop and you know I've I've been using the media tomb and some other things and you had to go to all these different Websites to go and figure out how to turn on transcoding because not all of my videos were in the right format And so, you know, I thought this was a really cool idea that this could be automatic And it's probably not as cool an idea as having a bath with a bunch of McDonald's hamburgers But it's probably equally crazy So I went and did some research and I discovered that all of this is using the upnp protocol and There's some there's four main components to this. The first is there are devices. So things like routers light switches are part of the protocol and media server, which is what I was interested in and on those devices there are services that run and So you've got like for the router you can ask whether or not the internet is up. You can open a new port For light switch you can turn it on and off see whether it's on for the media server You can go and browse all the content and select what you want to watch And then to discover these networks or discover these devices on the network There's a discovery protocol, which is similar to Bonjour, which uses multicast and an HTTP like protocol and Then to talk to the devices there's a separate part of the protocol for control So you can go and connect to the device figure out what services it runs and then what the methods on those services are and This whole thing is built on top of soap so it uses a Description language similar to whistel, but much much simpler So I took all this information and I decided okay We need to write a library for this and some like my two two major goals for it And the first was for it to be as friendly as possible So if you're gonna create a device you just say okay I need these two services and then I'm done and to set up a service you say well It has all these methods. These are the input and output parameters Then you just implement them. So there's really no more setup to do everything else. I wanted to automate So once you have the the implementation then you say you want to start it You just say okay device go and then it automatically says okay I need these services it instantiates them builds up a soap server and advertises it on the network for you And then if you want to control a device that you've already got on the network You can say use the discovery protocol to discover it say and it gives you a URL back And you say okay take this URL make me a control endpoint and then it automatically goes and builds all the classes for you Fills them in with all the methods and all that through soap. So that was pretty nice and so eventually I got to the hope sorry got to the upnp media server, which was my burger bath project and Started to work on this stuff and I found that the UPnp parts were actually pretty easy so implementing the device stuff the service stuff the discovery stuff The soap stuff I built on top of soap for our which is not well documented as far as the internals go So that was pretty difficult. I had to go and dig through soap for our a lot to go and say Oh, so this is how wisdom does it so I need to do something like that and teasing parts out of the API So in my media server, I'm still working on the transcoding library I've got a buddy who released the ffmpeg ruby jam on github a couple about a month ago or so Whose name is Antonin Amand and so we've been working back and forth on that And it's actually kind of difficult because ffmpeg is has all these great libraries for encoding and decoding But all the glue code is written in or the C binary So we're having to port parts of that to ruby and there are still some pieces I want so Now that once I get transcoding working. I'll be able to do stuff like Go to YouTube or have YouTube served up by the media server and you can go and watch YouTube videos I'd like to do flicker as well and that'll be you know, so you can go and say here's my flicker user account I want to view my slideshows on my TV And so currently what I have working with the media server now is you can go ahead and browse images And it gives you the thumbnails and it'll go and do the transcoding. So like the PlayStation doesn't support TIFFs So it'll convert it to a JPEG so you can see it I'm using one of the mp3 Tag libraries to go and grab all the track info so you can browse the list of mp3's We'll show you artists and track length and genre and all that stuff And if you have a video that is supported by your device then those all work So if you got a regular mpeg then those will work on most devices the few thing a few more things that I Want is the for example the Xbox requires a very specific layout of the top-level directory So I'd like for my software to automatically go and say oh, you're an Xbox. I'll go and fix all that stuff up for you And that's it for me. Thank you Next is JD. Let me just get the audio plugged in Make sure Get the functions. We should hear that audio if I hit the what do you have it on function? We can go audio us if we have to Is that actually coming through so we have audio out Good. Okay, super. And then what do we do? beautiful, okay, so this is really The appendix to Greg Bornstein's Arduino Address yesterday and you all know the rules to that because we got a couple demos and when you do a demo It's all oh, so we have to do the practice ready set. Oh No, okay. No, no, you'll get it better. So Okay, so thoughts on extending extending the rad DSL and So we all know Ruby. It's enjoyable It made programming fun again productivity efficiency Why we chose Ruby we all love power and we love to extend it To things why not we saw Greg do it yesterday? And so I'm going to show you a little bit of my experience extending it and talk about that There's only one problem though These things Wait, I'm up here. Okay. I'm out of sync here So these things these are these electronic manuals with about a million devices in them And the first thing you do is try to do anything You see these books and it just is a complete turn off, but fortunately timing is everything and We have this make movement going on and we have things like spark fun, which essentially gives us curated electronics So instead of a million things in these Convoluted books you get a thousand things or a hundred things that other people are working on so you can share notes And you can have some success So you can get things like very very cool RFID readers that are just plug them in and they work or little leds Actually three leds combined with a microprocessor on the back So you can put together an ambient orb just in an hour or a little switch like this Which is just the coolest switch and so these are all curated electronics and it works great for open-source hardware design So we have the tools. We've got Ruby. We've got curated hardware And so I had this interest in network devices everything's a device has a network address it can all talk and I really wanted to take and Take my power meter and hook it up and do some fun stuff with it So I said well, how should I go about that? I should grab the Arduino, which you know about already It's a little chip With a bunch of ports and people are crazy about the Arduino. They build cakes on the Arduino. They do little Bots that run on it. They wear it It's just crazy. It's written up in a wire. It's got a lot of traction and it's pretty exciting So that's really the third element. Well, and here's the fourth element Greg Bornstein's Ruby Arduino development and so I grabbed it And I did hello world it worked right out of the box And you've seen this little hello world sketch And I said great fabulous now. I got to go drag up the servos from the basement So I get the servos and I said oh Doesn't quite do that right out of the box And so I set to work to get my servos to work got distracted from my meter reading and so Added made some additions Okay, so the first thing smart pin declarations so you could do this is the hello world Actually There we go. Okay. That's the hello world and I said well we just Want to take my button and then I call it a device button. I instantiate a bunch of Basically a data structure and I can keep the state of the button so I can toggle them on and off, etc And it just happens by saying device button You can also get some hysteresis in there that's baked in so if you got a debounce. It's already taking care of for you then Did the same thing for servos set up a data structure store the state of it Sign minns and max all for free and then continued on and did it for I to see one wire LCDs You can just buy a spark find LCD plug it in and we know about it just by saying devices SF underscore LCD EE prom and ethernet so We added more libraries Brian lot Riley was really key on pulling together libraries and Then we added some modular plugins for C code a little bit more translation more damn parentheses Where are they there they are so this whole thing is based on ruby to see or a big component is based on ruby to see by Eric and Ryan and The parse tree and so you have a lot of s expressions and so this is just a little definition for a times function So that's all hidden from you. So you don't need to worry about it Let's see. So the result here's the result and There's some sound in a minute. So you see the that's a little Arduino nano servos the three servos some wine glasses and It plays So that's a wine glass and then I went on to do other things But first, let's do some some quick demos. So I want to switch. This is a simple RFID and We're just going to show this is not even using our Arduino Is go ahead and flip the camera down and Aaron's going to put on just a little alright RFID chip Whoa And we want to go right here so it's kind of so basically out of the box You need a point down a little bit Right There you go And it doesn't it reads the same numbers. So I won't read again. It reads the same number. So I won't read again and That's just example of not so much Arduino is just out of the box Like 30 bucks and your RFID reading with serial out It's and I'm just feeding that from a serial out on the RFID reader that little device right here Right to a serial in screen. I mean there's you've almost eliminated the electronics out of it Okay, so let me go on to demo number two if we switch back to the screen So this is the blink em tower. I'll show you the video and I'll explain what it's about Yeah Okay, so let me just show you the live version of that really quick and show you what it's all about So once again, it's these curated devices a serial LCD and you can actually just leave that out We got it all started up. And so literally it's we got that are we We want to get that guy right there So it's basically these really cool resistive strips and you touch them and You can basically change the RGB just it reads the resistance and then changes the RGB on this These are actually little I to see networked LEDs three LEDs in one and then you can do funky things like Let's see if I can get there. You can chase them you can get a color chase over a color chase and If you take a look at the code on it, it's pretty darn simple. So if we shift back to this So a lot of setups here, but basically you see two buttons Three sliders an LCD and that the top are actually establishing our eye to see and we just call a device a spectra And if it's a it's a spectra strip and it knows that it's this fancy strip and can just deal with it So the code's really straightforward and simple Because it's basically built in and then this is this little dance chase where it basically changes the RGB run Laughs to the array of RGB of LEDs changes the RGB colors right there and then changes them back super simple stuff So and this finally is the remote control book so This is using Zigby, excuse me And if you aim at the book here, there's the book right there. That's perfect So Aaron's going to control via Zigby on one Arduino right there and he's going to talk to the book right there ready one two three There we go Okay So and then back to the slides And once again the code super super simple I mean we've got a loop. This is actually the code on both pieces and We've got a loop we send the message if we read the button and at the same time it checks for a G And if I got a G I basically do an acknowledge I do an acknowledge and then I Open the cover bounce the cover close the cover very basic stuff Let's see that's thank you very much and Just a couple of credits Ruby Forge Radis hosted Ruby Forge and there's a little bit of information there Arduino at the second address All right, my name is Phil Hegelberg and I'm Yeah, I'm from Seattle RB. Hey At the last RubyConf there was some talk about you know Ruby and Lisbon how they're very intertwined in their history and This is I think during Mantis Q&A and masks asked, you know, how many people have implemented Ruby or sorry, how many people have implemented a lisp on their own and Something like six or seven percent of the hands went up and that was awesome But I was very sad that my hand couldn't go up then so I started this project Called bus scheme and that's what I will show to you right now Let's see, okay It's so distracting, okay Let's go back to Doraq here. Kidding me? Okay Come on, give me a break here Okay, here we go. Thank you So everything you want to know about bus scheme, but actually this talk is only 10 minutes long So I had to change the title So you're talking about that instead So bus scheme is a scheme interpreted that is Implemented mostly on the bus not a hundred percent anymore, but I do it on the commute to work Yeah, Ryan Ryan felt compelled to point out that it's not just on the bus so Scheme is a lisp and lisp is all about list processing and A list is you know, it's a list of things wrapped in parentheses So that's kind of you know the thing you always hear about lisp is that it's all about parentheses And that's because it's it's all about lists list for the lists are the most basic data type So you see a list list and the ruby version of the same thing right down there So everyone talks about metaprogramming with lisp, right? So when you talk about metaprogramming number one Thing is code is data. So What that means in lisp is that the structure of the program is a list Well, this is actually true of ruby to behind the scenes right this function method definition at the bottom there It's actually turned into something kind of like this behind the scenes before it gets interpreted This is actually a little cleaned up from the real version, but just for readability's sake So if you've ever used parse tree you can kind of get at what's going on here or rubinius's string to sex B Will expose that to you? But you don't want to really be working with that all the time. You don't want to write your code like that because Well ruby's not meant to do that but There are some advantages to that when you talk about code is data, right? You know, you can you can rewrite your code on the fly you can inspect it. It's its first class So schemes syntax is optimized for that. So that's essentially This is the ruby version and this is the scheme version of the same function really So you see It's just a list of lists. So it's it's basically the parse tree is right there. And that's exactly what you end up writing So when you're evaluating these functions the first element of each list is considered the function and the rest of it is Everything else in the list is an argument And each argument gets evaluated before it gets passed on so this kind of convoluted thingy here is a function Call that calls the plus function with all these other arguments numbers evaluate to themselves But then these other lists get evaluated because their function calls to so Times three two gets evaluated to six and what have you and then all those arguments get sent to the plus function And it returns 12 that semicolons are comments and tax So that's that's it basically for evaluation. So it's very simple. You can you can learn it pretty quickly But if you if all you have is numbers, it's not that interesting. So You know, you have strings just like in Ruby and You have symbols symbols are a little different from in Ruby because in Ruby a symbol is a literal So like colon foo evaluates to colon foo in Lisp a Symbol is just an identifier So it's what your parse tree is built up out of But if you evaluate just foo by itself, then it returns whatever foo is bound to but You know, if you want to just get at the symbol itself, then you have to quote it Which is the first notation there is kind of the more literal notation and the second one is a shorthand For so when you see quote foo just think of colon foo in Ruby And that's not the right key is it? functions are the building blocks of pretty much everything in Lisp, so in Ruby we have proc.new to create a new Anonymous function and in in Ruby. It's the lambda function So you see those those two are virtually the same there So when you want to You do an assignment you you do that with a defined function so the you see there we have the value 41 getting bound to the The variable bus line we have the string Northgate transit center bound to the bus stop Identifier and the arguments get evaluated. So, you know in the last one you actually end up with 22 as the transit time So because of this property of functions being data You don't have a special you don't need a special notation to define a function You're really just attaching a literal function to an identifier and that's what you see here with the Fibonacci function That lambda expression is just getting bound to fib. That's all there is to it So So lambdas are closures just like they are in Ruby So if you define a lambda it has access to the variables around it that that were in scope When it was defined even if they're not in scope when it was called. So in this example X is bound to one and Y is bound to two and because those are in scope when the lambda is created The lambda has access to them. So if you try to call X outside of that block, it's no longer in scope but if you Try to call that function adder that we just defined which is bound to that lambda expression there It still has access to those X and Y values. So that's you know With Ruby you get the same thing with with blocks and that's kind of the the Ruby version Lisp version Ruby version So X and Y only in scope during that function Def give me adder So that's kind of the basics of scheme like the actual scheme programming language, but with bus scheme, I wanted to kind of experiment a little more and since it's The only no, it's actually not the only scheme interpreted in Ruby Koichi wrote one back in like 2002, but I wanted to experiment with some more, you know Some of the things that you don't always see in the scheme world. So Whenever scheme people go on the web, they always talk about these crazy continuation based Servers, which are really awesome, but you don't see a lot of Real functional programming type people understanding rest. So that's that's the direction. I wanted to take it so in bus scheme you can deaf resource something and this is this is just binding a string to a Path, so if you visit it in your browser, you just get that string back, which you know This is built on the rack web service abstraction Library, so you can it it uses mongrel by default it falls back to a web brick and it kind of encapsulates all the weird things about handling HTTP requests that you shouldn't have to think about when you're just when you're just wanting to create a simple service, so That's not that interesting, right so because lists are trees and HTML is HTML documents are trees they actually map pretty well onto each other so you can see there we're defining that Real HTML path to the resource that's defined by this this list so Yeah, that actually renders into it compiles into XML on the fly using the builder library And the notation is just very uniform. You don't have any special You know it's it's like builder is for For Ruby where you don't have to think about the details of XML You just build up a tree and the tree becomes HTML or XML So but that's still static so still not that interesting to really get dynamic you want to bind a lambda to a To a yeah a path on your web server, so The first one just returns basically time dot now is a string and the second one will Yeah, it'll return the Fibonacci sequence number of whatever query string you pass it so Just a little little taste of scheme on the web for you So I think do I have time for a short demo or are we cutting it kind of close? Okay, in that case you can grab it. It's a gem It's up on github and these slides should be up there in an hour or so. They're not quite yet and there's a tutorial up there for if you want to go a little further into What bus game does so plan on working on polishing the web functionality a little more right now It's a pretty thin layer around rack. So I want to I want to make it a little more natural I'm working on macros to get syntactic extensions, but it's still Still in progress and at some point continuations in line Ruby really cool things like that. So Yeah, that's bus game. Thanks Hello, my name is Ryan Davis So what I want to talk to you today is a bit darker topic than than the other people up here Basically, I want to talk about being a Ruby status. I've talked about this a little bit before Basically that it's it's been my my theme for the year that I like to hurt code a lot Basically, we are seeing a New era in Ruby where we're finally getting the language tools that we need to really have a transformational experience with our code So if we talk about the philosophy of Ruby sadism The basics are people will press charges if you hurt them, but code won't So top your code Make the code your bitch and beat it in submission That's a lot easier and you get to keep your job So Ruby sadism I define as driving pleasure from inflicting pain on software, especially bad software But really all software as a candidate And we have a bunch of tools to do this with and you're familiar with some of them and you use some of them I hope if you don't We have to have a talk One of them is auto test and it's really it's the howitzer of testing And a lot of you use it already. It's it's truly a sadistic tool in that it's constantly beating on your code with your tests And if we haven't seen it before we can get a quick little demo here So we make a modification and save and it automatically runs the relevant tests which fails When you change it back so that it's no longer going to flunk It passes and then it reruns all the tests to make sure you didn't break anything else You know, it's a really simple idea that when we brought to the table We didn't realize how much it was going to change the way we do our work We have another tool called heckle It helps make your test cry And the basic idea behind it is that once your tests all pass We're going to go on the fly in runtime modify part of your implementation and run your tests again If your tests don't fail then you've done something wrong and you're not covering everything. So let's see a little demo of that We have deaf is awesome and it is small for a reason deaf is awesome exit at awesome and Your tests all pass and that's great. So heckle is going to go and modify that So that the if is morphed to an unless now obviously by running the same test You're going through a different code path and you should fail But if it passes you've done something very very bad and you know that you need to go in and get better test coverage Another tool slightly newer is flog. It was beatings build character What it does is it goes and analyzes your code at the AST level for various kinds of complexity Assignments branches and calls and it gives weight to certain things in different ways. So here we see a very stupid example Where we've got in a val and some the quality checks and the conditional and puts and it scores all that up as 11.2 and gives you A detailed reason why it's scored that way now the actual numbers and this is something that the people are finally beginning to catch on The actual numbers themselves are meaningless Absolutely, but relative to each other. They're very very important Whatever is boiling up to the top of your report is what you should be looking at the stuff at the bottom report is not as Important relative numbers are important, but you can't use these to compare your project to someone else's it just doesn't make any sense That way it absolutely And the new kid released here at RubyConf is flay. I Have a harder time describing what flay does it uses the AST to find structural similarities And here we see some some real code that I went over. It's an incredibly complex piece of ruby that I found while Flogging a bunch of code that I use for for testing my parser So here we see a simple flay on it and the thing that boils up to the top There are these four when's that it found that look the same now Let's go look at them. Now. You don't actually have to read the code on the next page because quite frankly. It's painful That's one of the when's it's 21 lines long. It's really complex, but That's the next one. Oh, it didn't line up right Damn it didn't line up, right? But if it did line up, right, you'd see that three words are changing just three There those line up better That's it. So this is a really really simple candidate for Refactoring you refactor this when into a method call that takes two function names You do sends instead of the function calls and you're done You've you've you've cleaned up your your code quite a bit and then you move on to the next one on the next one That's what flay does I'm gonna go nice and fast that you don't have any problems with yours and then last But not least just for fun. I wanted to show some shiny shit This is something that I presented at 2005 But it has since been forgotten because I don't think anyone's touched it So you've seen parse tree and you've played with parse tree probably to some extent or indirectly and you've probably heard of Ruby to Ruby You may have heard of Ruby in line That allows us to embed C code or any foreign language code into Ruby and compile it and run it on the fly You might not have heard of Ruby to see that's another thing that we wrote. It was mentioned in in the talk about rad We also have a code profiler So what happens when you take all of those things and put them together a profiler plus parse tree plus Ruby to see plus Ruby in line Well, here we see a 500,000 iterations on factorial in plain MRI that takes 4.39 seconds if we run the same code again Was then optimized we trip a threshold Automatically convert it to C Take that C and put it in an inline have it compiled linked and brought back in and replacing the method as it's running and Boom we hit 1.4 seconds instead And I think that's pretty rad. Although it's not actually that usable for most things unless You use fib a lot in your business So that's all I have thank you Hello, my name is Aaron Patterson. I am a Seattle R member RB member and internet expert and I want to be the first to welcome you to RubyConf 2008 Or what I like to call the International House of Nerds. I Have a hundred and six slides and only ten minutes to do it so I'm going to speak quickly I'm going to talk about no kogiri and the history of Seattle RB No kogiri is a gem. I recently recently released It is an HTML XML XSL T I One two one two three four five six seven eight nine compatible X path compatible CSS three parser thing so you can parse your HTML and slice it up using X path and CSS selectors if you like and It is internationalized as you can see No kogiri sits on top of libexml 2 and the reason I chose libexml 2 is because it is fast It is standards compliant. It is popular. Well supported and dry. Oh I kind of want to explain dry a little bit I wanted to use libexml 2 because it already has an HTML parser. So why would I write my own? Here's an example of the usage It's very easy You just open read something tell you want to search via CSS selector Iterate over all the nodes and you're done. You may ask yourself. How did I get that CSS selector? I loaded this web page opened up firebug inspected their logo copied the selector from firebug and then used it in my codes So I'm going to talk about those little bullet points a little bit speed. Let's look at some numbers First I want to say I love H per cot I love H per cot so much that I stole its API and I sat the API on top of libexml 2 because why not so Before we show off these benchmarks. I want to show you a little bit of code just so you can see how similar they are The top two lines are using regular currently released H per cot Well, the top line is regular currently released H per cot the second line is H per cot 2 the third line is my compatibility layer for things which I don't think work quite right and the fourth line is incompatible but You'll see how compatible that is Now these are all the methods being tested as you can see they're very very similar And that is because I stole H per cot's API You should be able to get away with using the incompatible layer unless you're doing something wrong Here are the speeds the most important one to look at is the real time As you can see the compatible layer is a little bit slower than H per cot 2 But the incompatible layer which should work most of the time for most of your use cases is Much faster Here is more numbers look at the red you can see X path searching is insanely faster using libexml CSS searching is Slightly faster using the incompatible layer and I kind of want to zoom in on this one because H per cot is so slow on this it kind of makes the graphs look Strange actually, that's not true. I didn't want to show that one HTML parsing is the one I wanted to show you so HTML parsing. This is just parsing a document parsing slash dot H per cot 2 versus no kugiri. I zoom in on this one and It's about two seconds faster in this particular test. So they're pretty close X path You see no numbers in H per cot 2 because it just fails. It does not work and No kugiri is faster. Same thing with this particular selector this selector Every benchmark is faster using the non-compatible mode If you'd like to check my number as you can check out the gist from here Next thing I want to talk about is standards compliance I Use libxml's x path parser and it deals with all of that. I don't deal with any of it. It's only libxml CSS selectors I've written my own CSS parser and Tokenizer, but I stole the ones from W3C. So all of my parsers and tokenizers are generated Specificity is your friend. Does everyone see this HTML document? Does everyone know what that style tag does? It turns that text red awesome, right Can anyone tell me what this returns in H per cot? Probably not fail and The reason is because it's ambiguous Each per cot mixes CSS selectors and x path selectors in the same query. It's actually treating that as an x-path query. In x path, this means give me all p tags who have a child tag with a In CSS, it means give me a p tag who has a member attribute of a So in NoCoguerre, I make you specify that Don't trust me. Trust the specs Popular I would venture to say that libxml2 is used by more people than use Ruby Well supported I read your bugs Gem install NoCoguerre Try it out, please Okay, now on to the fun part history of Seattle R.B. Starring me The year was Ruby 167 The place was Seattle Eric Odle And Ryan Davis now the first The first the first meeting was arranged via email, and I wanted to take a few excerpts of the emails The first is a story of misconnections Ryan Davis says I'm terribly sorry And it is because he missed Pat Eiler. They they missed each other and Pat says arg Because they missed each other. So the first Seattle R.B. Meeting was a fail Then a connection of love Eric Odle writes into the list. I've written a web page in Ruby in my spare time and Ryan says cool. Welcome Eric, I love you. What? Nothing And that's how they first met The first meeting another dramatic reenactment starring me First is introductions. Hi, I'm Eric I'm Ryan Next was some common ground building So then came the first codes Those are nice codes Ryan likes codes too the year Ruby 182 Seattle's first gem released by Eric Odle Ruby growl Yes, he has Jim The year was Ruby 183 set 16 gems released including parse tree Ruby inline and I want to give a few stats Seattle R.B. Before November 1st has 90 unique gems. It's probably more now It is more now 399 total gem releases before November 1st. It is more now Here's a graph of our gem releasing which if you want to run these codes you can get them here Seattle R.B. Was the first Ruby Brigade ever and I want to end with one more thing The year was Ruby 185 79 gems or 185 79 gems released and The thing that all of you don't know is that Ryan didn't used to be angry as you can see from this photo Photo evidence of Ryan not angry Tuesday night 655 p.m. I Showed up 7 p.m. 7 p.m. 7 0 5 p.m