 Hello, I hope no one's offended by VIN that I love it, and there's a VIN thing tomorrow at half eleven if you want to come along and talk about VIN because it's awesome. So I'm going to quickly talk about dependency injection in Ruby, which apparently is quite a controversial thing as I've found out today. To understand why I'm talking about this, I'll give you a wee quick bit of background about myself. I used to be a .NET developer before I saw the light and became a Ruby developer. One of the things I loved about being a .NET developer was alt.net, and there's the sort of thing that brought testing and all the good stuff that we take for advantage as Ruby developers. One of those things that I loved the most was dependency injection, and I did a lot of talks on dependency injection, loved it a lot. In fact, the first question I asked on Stack Overflow when I became a Ruby developer was, how did you do dependency injection in Ruby? I was told, you don't. It's true, you don't normally. In .NET we do dependency injection to make things testable, but everything in Ruby is testable. It's easy to test. But there's another thing you can do with dependency injection, which is a really cool thing. You can do it in Ruby, but dependency injection to me is a pattern to use. I want to go for a quick wee sort of monologue about how I got to where I am with this dependency injection stuff. It starts off when I came out as a first Ruby developer. I saw a lot of code like this. If you imagine these are Rails controllers, I couldn't be asking a full Rails app together for this, sorry. I got in here where we do some finder method, and imagine this here is an active record finder method as well. It would return me a class and you call something on it and you turn it. Is everyone seeing code like that? That's not unusual. I could run that and you'd see it working, but who cares? I didn't like that because it has a database call in my controller. I really, really don't like database calls in my controller. I know in Ruby, tentatively, it's kind of all right, but I kind of don't like it. I move things from being database calls to sort of class level methods. I'm not supposed to call them that anymore, but for the purpose of today, I will. I had a lot of self methods, a lot of class methods that would do something. The database call would be in there, it would do some work, and then return back the information that I wanted. I'd end up with something, blah, blah, blah, blah, where's the controller gone? Is it at the top? At the top, yeah. I'd end up with things like this, and then I'd do whatever I need to do to output that to the screen. I had the controller basically doing what the controller was supposed to do very little, calling something, getting some stuff back, and throwing it on the page. One of the things I came to talking with Pete, who's around somewhere over there, Pete, was the thing about what if we want to change that implementation? What if we want to use something different, or in different situations, want to use something else? In Rails, just now, what we'll do is go through and change every single implementation of that, and then take ages and we'd run our tests, and they may or may not break, and update them on it would be a pain in the bum, basically. So after a bit of talking, we went, wouldn't it be great if we had a sort of dependency injection back in Ruby on Rails? So I went away and, yeah, I kind of created it. Much to his annoyance, because he wanted to do it. So at the top here, we've just got a class, some service class. I call them service classes, because that's what I'm used to from .NET. I'm sorry if you don't agree with that. Some class that does something again. And I created this thing at the top here called DependsOn. Now, in this situation, that's very simple. What I've got here is a symbol right next to there, which is exactly the same as the name of the class at the top. And what that'll do is essentially create a nice little variable on our controller for us, and then we can call the methods all the methods we want all the way through. And that's great for that situation. But what if we want something that can change whenever we want it to change based on maybe, based on classic ones, tax calculator? When we want a different tax calculator for a different country? You mean what I call that? Well, I went ahead and put that in. Put some very basic, I say basics, I've only been working on this for like three days before the conference. It's very new. Some very basic sort of factoring support on it. So what I've got here is, as well as just passing a symbol, you can pass a lambda. And that lambda or block or proc or whatever, you get the owner context into it. You can then do something like that. In that case, I'm just returning a different class. So, in this case here, I've got my normal class that I had originally at the top, some awesome class service. You can tell I like the word awesome. It's such a great word. I've got it through here, and originally, if I was to go back and run the one beforehand, it would be a good idea. There. So if I run that, it'll go down here. Them is awesome, just to let you know. When we come down here, just create the controller and put that out. You can see it will run and it will put out whatever I've got on that screen. Now, in the case, in the second case, I've got a wee bit of a switch in there. That takes, that was the original class that you saw. I wanted to now change that. So I've created another awesome class. It's slightly more awesome, because it uses a dirty Harry quote, which is great. And all I've done is changed its implementation here. So in terms of maintainability, this is great for me, because I don't have to then go through and change all those calls and all my code. I can just switch it around really quickly. Or if I want to actually change it totally based on some dependency, something else, I can just change it in here by doing some sort of this statement or whatever I want to do. And then if I run that, it'll say, it'll give me a different implementation. Now, to me, that's what depends injections all about. It's not about testing, which is always how it's sold in languages. It's about this ability to be able to change things in and out really quickly depending on what the context is. So I was kind of starting to develop this, and I kind of wanted to hear other people's ideas about it. That's why I'm talking here right now. Already talked to Pete, we've got ideas, well, he's told me what to do basically. He's put in support to make mocking and stuff really quick and easier, or stubbing, sorry, quicker and easier within RSpec and TestUnit to make that a lot quicker. That's pretty much all I've got to say. If you want to check out the code, which quite little is about ten lines of code, it's very small. GitHub here. If you want to email me at all, or get me on Twitter, or just grab me afterward and kick my ass for doing this, that's fine as well. Just tell me I'm wrong. It's great. You get me on there. That's me. I can take a couple of questions apparently. I've got three minutes left so I can take any questions if someone wants to pass me right now. Fine, okay. Quicker to the pub, I like that. I'll shut that down. It seems to be the lightning talks are just in the order that people get to the podium, so if you're really determined to speak, just sort of queue up over here. I'm going to talk about vagrant virtualisation and configuration management very quickly. I'm Gareth. I work at Free Agent. I'll bet everyone knows that. I blog. I curate e-mail newsletter because they're un-vogue at the moment. Here's a number of disparate problems from teams I've seen in the past or worked on that you may or may not be interested in. You may or may not have come across, hopefully you have. Getting new employees started is often difficult. Some developers are bad at what works on my machine. Why is it not working on the server? What works on my machine? Hopefully that's not you. It's a big advantage to running the entire stack of any given software project locally. I spent a lot of time on train and when I started a company that didn't do this, it meant I couldn't work on that train. Pretty specific, but anytime you can't run it, the internet's down. Oh no, it's not going to work. You're not in the office. It's very difficult. Services are a good way of doing various different things. If you can't run that locally, you're running to odd bugs that are difficult to debug again without all the access. Not all developers want to be sysadmins and nearly always end up managing their own local development environment in a somewhat ad hoc and different manner to the person next to them, which leads to odd bugs. Different versions of libc between two people not going to catch you all the time, but if it does, you're going to hit finding out what the problem was. Not all developers make good sysadmins, because that's all stuff. I think there's a number of solutions and they also have come around using local virtualisation. Using some of the configuration management tools like Chef and Puppet, but rather than it all being about the niceties of going like 1,000 servers, this is cool. Focusing inwards and using it for your local development environment and then maybe using it for your development environment to standardise things. And there's a very nifty Ruby tool called Vagrant that I'm a big fan of. Quick note on virtualisation. Most people go on virtualisation, I use Vmware Fusion a while back out slow. They're probably using it for windows and they're probably using it so they could use IE. All of those things are painful. Throw a hardware at this problem, anyone using a machine that doesn't have maxed out RAM do that first and then things are slow. I say I used to use Vmware Fusion I now use VirtualBox. They got went to Oracle and I'm a bit scared now. There's good tools. VirtualBox runs on Windows, Linux, Mac and there's an open source version so no excuses. vagrant.up.com is the tool I want to talk about for most of this session. It's a long list but it's normally when you're managing VirtualBox there's a GUI and you're clicking things. And there are some config files and there's some properties and some XML things and there's a command line app that you can send very weird messages doing it. It'll set things up. vagrant removes all that and gives you a very simple DSL that I'll show you in a second to show all these bits and pieces. It's for automatic provisioning of those VirtualBox instances using Sheffan Puppet. They're virtual machines. They're often headless virtual machines by default so you're not having to carry around a big GUI. You just SSH into them. You can manage the network stack of one or more VirtualBox machines for doing static IPs if you want to show someone else. You can forward ports from your local machine if that's already on a network. You can very easily share folders in a few ways and you can package these boxes up and give it to your colleagues or put it on a service so new employees can grab it. And I now find myself whenever I go, oh that's a cool project I'd quite like to play around with. I just grab a new environment. I might play around with it and go oh that was cool and I might then throw that away. It's like the cloud experimenting with VirtualService. I'm throwing them up and tearing them down and it's liberating rather than having to manage all these things. It's a gem. You're really people, you know what that looks like. At its height it has a vagrant file. Basically a text file called vagrant file like a rake file. And you have a really detail and this is basically the sort of basic. There's a lot of minimal feature would be I want to use a box. A box is simply just a pre-built image with the vagrant tools and an operating system on. And this would be saying I've got a box locally called Lucid32 running Ubuntu and I can run the vagrant tool just say vagrant up against that file and it will spool up a new virtual machine and then allow me to test it into it. You can set up port forwarding. So you might be running a Rails application there but you want access to it from your desktop machine from your laptop. Where is port forward? Send one port to another so you can export lots of ports that are on your local machine so you just go to localhost7000 and it's processing it it's basically forwarding it through to the virtual machine. And there's just a config file and there's one liners and you can add them and take them away. The auto property means that it will automatically discover one that's not in use so I have lots of machines and I bring them up and down and I want SSH access but I probably don't care about the port because there are other tools to manage that SSH config for one and so it will find one that's not in use. Shared folders, again shared folder configuration in virtual box or in VMware is pretty gnarly you have to do a lot of work vagrant gives you a one liner that you can put into these config files. Talking about service based architectures sometimes you want multiple machines you can have a vagrant file and remember this is a text file that you can put in version control and you can share between you that can bring up multiple machines in one file so vagrant will bring up two machines or three machines or ten machines before your machine runs out of RAM. Talking about boxes these encapsulate the tools and the operating system this is a website I put up that is hosting a lot of these boxes and you can find most operating systems WN, Ubuntu Red Hat Gen2 and you can make these boxes internally if you have very specific requirements but what I prefer to do is use config management tools to provision those boxes so this is what doing it in chef looks like again you build up these files and you can say well I've got a load of chef configs and I want this machine to have this role when it comes up you can tie this in with the chef server so if you've already got a chef server setup that you're using for your production stack you can point this at it and say oh it should have the role of this type of machine a developer workstation machine whatever you want and you can do more complicated things so this is one I use all the time to every time I bring up a new virtual machine I want my zshell config and my vim configs on there for two people and this will do that it drags the cookwork down from github and put the config files on there so I get my shell straight away whenever I fire up and throw away these machines it's very nice you can do the same thing with puppet you can again have local files in that directory or you can point a puppet server so if you're already using puppet to provision your infrastructure you can use your existing puppet infrastructure to do the same things run through that quite quickly but for me the advantages are you can minimise finding weird bugs only in production there's lots and lots of people here with Mac laptops how many people are using X-serving production it's like no one does it there are subtle differences that they don't catch you very often but when they do you've got a problem in production that you can't replicate luckily and finding those bugs is I'd rather do this than find running into bugs like that casing sensitive file systems if someone's going oh what's that read about casing sensitive file systems cos the Linux and Mac are different early and often testing of your configuration files if your sys admins do this at the end it's like anything that's just done at the end it's going to be poor if you can run through everything all the time it's like CI for your configuration management stuff excusable documentation is always better onboarding someone oh here's the documentation setting of the development environment that's only ever up to date the days after that person has started because they go through it doesn't work oh yeah change it doesn't work in a few weeks or months go by someone else comes in same problem excusable documentation that's run all the time will always be right and it leads to faster onboarding you can just go hey here's a vagrant file vagrant up download box chef puppet configure that machine bang they're up and running really quickly and they can be productive quickly even more important for contractors and there's a shared language between development and operations and that's important if you have two teams that have finished that was good no questions because that was 10 minutes if anyone's interested come speak to me about it I'm happy to show demo how I use it and the tool in front hello everybody so this is something a little different this is a productivity enhancement tool or a technique that you can use independently of the language you're using it's called top 5 and we'll see how why it's called like that in a moment this is 105 check so let me tell you a story at the beginning of the last century Charles Schwab was heading the Bethlehem Steel Corporation in the US the company was not doing very well and at that time Charles was hiring ideally a consultant for public relations ideally is known now as the the founder of what is called modern marketing relationship and ideally told Charles let's try something so I heard your story I think I know the problem so let's try to do this take this piece of paper and write down what are the 5 most important things you need to do tomorrow in 5 minutes Charles wrote down those 5 things then Ivy said well now prioritize them in the order that you think they are most important another 5 minutes pass it then the paper was ready so these 5 things were ready and Ivy said ok so first thing in the morning tomorrow when you go to the office start executing the first thing in the list that's all you don't need to think about anything else start executing and don't worry if you don't finish all the items in the list just try to finish the first one and start with the second one only when you finish the first one so respect the sequence of the things on the list in total this explanation was about 25 minutes and what happened was that after 2 weeks Ivy received a $25,000 check $1,000 for each minute that sort of consultancy lasted because those simple advices changed the future of Bethlehem Steel Corporation and at that time it became one of the largest independent steel industry in the US and Charles was a millionaire for that reason so he sent this $25,000 check back to Ivy Lee so this is the story of where the top 5 name comes from then in more modern time so this story has been told countless times blogs and books and in more modern times Cameron Harald rebranded this story or this technique to top 5 a few suggestions of how you can use it now other than that you are not allowed or supposed to put more than 5 items on the list this is very important is what makes the technique simple and powerful at the same time but you can use variation of it top 4 to 3 depending on the kind of work you are doing you can tweak it and try to understand what is the best thing that works for you maybe you should share this list publicly so other people can see it and you can feel the peer pressure to finish it to finish the items on that list and maybe you can expand this list to other time windows simple time windows like this week or this month or maybe this year so let's try to see an example of how you can use it top down which is in my opinion the simplest way of using it so let's say that this year I want to write my first closure application I'd like to run a marathon and I'd like to learn Portuguese so maybe sustain a casual conversation in Portuguese with someone what I need to do this month to achieve those goals maybe let's try to run at least 10 continuously at least 10 keys 10 kilometers maybe I can start attending the weekly local Portuguese meet up group where other people are talking the language I want to learn and I can maybe this month try to arrive and try to achieve the goal of running simple closure scripts then what you need to do this week to achieve those goals always not more than 5 or not more than 3 maybe I should read the first two chapters of the joy of closure maybe I should try to run at least 3 times this week and maybe watch a couple of movies in Portuguese and so what I need to do today finally well I can start by installing closure and REPL to do some experimentation I can try to run a 5 key and maybe I can start by learning the first 10 numbers in Portuguese from 1 to 10 so this is just a simple example of what you can do so the rules are pretty simple but yet it's so complicated why it's complicated because it's not easy to find out what are those 5 items that should go on the list and it's also not easy to find the correct size of those things so that at the end of the day you can have that check that green check on the item and you can feel that sense of accomplishment which is the main engine the main fuel that keeps you working then on the other items for this day, for today and for the next day maybe I didn't mention it but at the end of the day you're supposed to spend another 5 minutes thinking about what you want to do what are the 5 most important things to do tomorrow I didn't mention it was in the story in the initial story what's revolutionary if you want is that it's missing to the list huge to the list sometimes they become unmanageable too long it requires too much time to prioritize the item on the list because everything is in that list I don't know if you have ever experienced that and why it works because the brain is already automatically filtering to the list so you are perfectly able to forget what is not important to do and hopefully you will be able to remember what is important to do today and tomorrow so that should be easy for your brain to remember at the same time it should be easy for your brain to forget what is not important for the future that's all any question? I have a couple of minutes I have one there it's the same go ahead that is an expansion of the techniques can you repeat the question please? oh yes, you asked if this is if this going top down from the year down to today is part of the technique it's not part of the original story which is a true story but it's part of the extensions that has been added later by the ideas of Cameron Harold so yes it's part of the technique I think it's okay I I tend to do to put everything in the same thing because what I need to do today maybe it's part personal and part work that is the problem anything else? yeah not that long three months so it's not that long but I come from and I'm still using it other techniques so I'm quite used to learn these kind of improvement techniques and try to integrate them with my current workflow and maybe personalize them a little bit but it's not that long, it's three months and I'm struggling with it it's difficult as I said if you're quick I'm searching twitter hashtags and google for top five yeah it's quite new there's well there are really a few blog posts about it that's it there's a product I'm developing it's called teamlead.com and that is implementing this technique that is the other thing but other than that nothing else well it's it's against it because getting things done will try to push all your tasks or everything that comes into your mind into the inventory list and then try to prioritize them recursively so it's quite the opposite I would say we can talk it, yes thank you