 The topic that we're talking about today is embracing collaboration with JRuby and JavaScript. My name is John Crosby and during the day I work at Engine Yard. At night I work on quite a few open source projects and many of which spawn the ideas for this talk today and yeah, that's all I'll say. I also work on the Engine Yard cloud platform. We've got several of our engineers here today, actually half of our company is probably here today. If you have any questions about that, obviously look me up, I'd love to talk about it. Incidentally, we are hiring, it looked like everyone was hiring when I saw the whiteboards out there but we are also hiring, if you'd like to work on a team of really bright people who are a lot of fun to work with, please look me up or anyone on our team. Okay, so I thought that the focus of today's presentation would be a lot more on the mechanics of how bridging JavaScript and Ruby works and we're an agile shop at Engine Yard so we like to create something, put it out there, let users test it and iterate on that and so I've sort of been doing a mini version of this with this talk and people I work with and other friends that I can annoy occasionally and usually the mechanics, once you've extracted them into a gem which I'll show later, are fairly simple but most of my time is spent explaining why you'd ever want to do such a thing and so I think that's probably the most value that I can provide for everyone here today is talking about the why's, how everything works together and I think that you'll see that the mechanics are pretty clear but we can talk about some advice on how to use these things and so in doing so instead of just having a technical tutorial walkthrough, I thought it would be more fun to work at this from the viewpoint of a set of themes. The central principle of driving all of this it turns out is the principle of dry, do not repeat yourself and I think it's really nice as a software engineer if you can find some sort of core principles that you're working with when you're developing that help drive all your decisions. It helps make things more clear when you're designing user interfaces or deciding how to go one way or another with code and finding a central principle is actually a fairly popular topic. If you've been to some of Jim Wyrick's presentations you know he's searching for this grand unified theory of software development and if you have a chance to hear him speak definitely check that out. It's a really cool way to think about the software that you're building but it goes beyond that even to music. Very odd one of my very favorite jazz guitarists Pat Martino. He's been around for quite some time. He's an amazing improviser. He does jazz, bebop guitar and I just happened to hear him out in the lobby earlier today and he's got an amazing life story if you have a moment to check it out. He was basically getting to the peak of his career back in the 60s and 70s and he was playing this gig at this huge festival and then totally just went silent and so I think the other musicians he was playing with thought this guy is like trying to have a big dramatic pause here or something but what actually happened was he was suffering from a brain aneurysm while he was on stage so not too long after that he had emergency surgery to save his life. Forgot everything about who he was, how to eat, that he even played guitar, had to relearn absolutely everything and now he's back at the peak of his game but one of the things that makes him so awesome is that he has a central principle for everything he does with guitar improv that extends from a core concept of guitar geometry and you don't have to buy a whole stack of books to learn how to play using his mindset it's just a central principle that you can use to guide your entire exploration so a little bit of a divergence but really cool that you can extend from core principles in this way. Some other smaller themes that we're talking about here are pragmatism not to be confused with short-sighted practicalism. We'll be talking a little bit about performance, some surprising interactions some of these things have with the idea of craft or software craftsmanship. We're also talking about collaboration obviously and a much larger theme of just the web itself so to kick it off the first thing is the intersection of pragmatism with the web or in the context of the web and my proposal for this talk jokingly started out saying as web developers we live in an arranged marriage with JavaScript but I'm probably missing some cultural subtleties there and I probably should have said something that would make a better analogy which is you can consider it like siblings right we don't choose our brothers or sisters that were born into families with but we are living with them and that's the way it feels a lot of times as Rubyists when we have to interact with JavaScript and there are several strategies you can use when you're in this situation the first one is the one that I personally use for a very long time avoid it try not to write JavaScript on consulting projects I can remember advocating very strongly for this for a long time you know we we can't write JavaScript it's different in every different browser and this was in a Java gig at the time and we need to be able to unit test everything we put out there how can we be totally sure that this thing's the same and all these browsers and all these works unless we can unit test it things are different now you can unit test JavaScript in the browser and at the command line if you didn't know but that was a good strategy at first I think some of us then went to generating it right there's there's a whole RGS thing we won't talk about today but other strategies were even in Pearl land I worked with this guy named Matt Lins back in St. Louis where I come from and he was rolling his own Pearl web framework like everyone was in those days and we use something that would generate JavaScript so we had a regular expression of course because it's Pearl and we were talking about the types of data on the server and we can use that same regular expression the browser to do some simple validation it was kind of a nice abstraction there and there's another area where you can do code generation like Dreamweaver again won't cover that but people used to use it to make tacky mouseovers with really tacky beveled buttons and browsers for navigations you remember what I'm talking about another strategy that's a little bit more recent is using JavaScript as a compile target I don't like this one because it's not very pragmatic and so let's just have some fun talking about why this is a beautiful JavaScript object it's it's a property foo that has the value of bar and loading that object into a bit of JSON or from a bit of JSON from URI is exactly this simple if you're using something like jQuery on the client side I like that and that's has some affinity with the way that we do things in Ruby contrasting that with the Google Web Toolkit and we can have some fun with this because a lot of us don't write Java here the Google Web Toolkit compiles Java down to JavaScript and in their environment it probably is pragmatic because they have a lot of Java developers but the one thing I didn't really like about that is they're not using web protocols or what I like to consider the web protocols they're using a mechanism known as RPC and so again it's not very webby so we could throw that out and I unfortunately did a very long lived experiment integrating GWT in Rails using a plugin and so to start that I ripped out the GWT RPC stuff and started using GWT REST and this is not what this whole thing is about today don't worry but the way it looks is instead of having this JavaScript object you can just throw up there this is Java so Java needs to know everything about what you might do with this object and if it can be different in different scenarios especially for schema-less things then you need to define an interface you need to say this thing's probably got an ID because we're storing in the browser we need a way to populate it to and from JSON and then maybe in general they'll be sort of the same so in Java if you want to load some class you don't know about ahead of time you can load it using this trick doesn't work in GWT or at least the version I was using at the time so you do whatever good Java developer does you start making factories and you have like for example this create interface that returns something that implements this resource interface and then it gets better instead of having this simple jQuery line that we saw we have a response callback of course there's an abstract class above it of course it implements an interface that GWT is expecting and then yeah you get this thing back on your response received hook you use the factory to create it implements this thing and then you populate it with your JSON text that you got and then call back into the framework ouch that's a lot of code but we're not done yet yeah well wait there's more so on the rails into the spectrum since we can do cool things with Ruby we can inspect the MySQL data store we know all the properties that are available so we can use that to code generate unfortunately this class that extends foo base which will make fun of in a second but if you have something that Java guy would call business logic that would go in this class you could change it all the time it's not very brittle because it's not going to get overwritten with subsequent generation that is not very dry because it's going to end up being duplicated on both sides defense so more fun here this base object that we extends this is the thing that actually implements resource and it has to know about every property in the active record data model so that's where this string foo is coming from and we again we populate it and those three dots there it's just lines and lines of pain all the way down so I am making the case today that that is not a very pragmatic way to integrate javascript with your code and it's not very webby as a slightly different take that I won't spend time making fun of because actually kind of cool as the guys doing cappuccino they have objective J in the browser it's a little bit more like objective C it's a super set of javascript so you actually don't have to bridge if you don't want to you can just write javascript directly worth checking out if you're interested this last one is definitely not pragmatic but I think it's a more forward looking way of thinking about this in Rebenius if you're familiar with this it's a Ruby implementation built on LLVM the low low level virtual machine and what LLVM is is a compiler toolkit there's just a series of phases things go to to get to machine code on the other end so it's language front end like Ruby C C plus plus objective C Apple's using it to do some pretty cool things these days they eventually end up at this intermediate representation it looks like high level assembly language it has functions doesn't quite look as gross as assembly and then finally there's a back end it turns it into machine code so in Rebenius you've got Ruby source actually goes to bytecode eventually ends up at LLVM intermediate representation and then generates machine code so there's the summary the cool part is that these back ends are pluggable on LLVM so it's it's feasible to use Ruby to generate this IR and then write a javascript back end for LLVM so what that would actually allow you to do is run Ruby code in the browser with no plugins which I think is compelling because I think that we've been saying as a development community over and over again we don't really want your plugins in our browser and we'd like an open way to do these things that's one way you could do it and because this IR is totally language agnostic every language compiles directly to this you could do things like Python into this intermediate representation that then compiles a javascript Haskell you can you can get as crazy as you want and then what yeah you can think of it as decompile yeah that's probably better a better way to look at it that if you see the reputation of this javascript going on here you could imagine a model where as the browser vendors if they would adopt something like this low level virtual machine code we could all write whatever languages we wanted to and run those in the browser so that's not very pragmatic as we said what about today so getting in the meat of this embracing javascript I think is the best way to deal with it at this time and this allows us to embrace collaboration in various aspects the first one we'll talk about is collaboration in the human context so I took these numbers from github if you look at their code that's hosted there 25 percent of the code on github is Ruby that already is very cool that's a huge community lots of us are already here I've seen a lot of faces that I've only seen avatars for here today and it's we have a cool community so already that's big win but if you look at the percentage of javascript code on github that's actually pretty large compared to all the other languages 17 percent so again that's a big community of people that we could be working with but the Steve Jobs boom moment that we get to here is that if you look at languages that have an affinity for the web python parole php java things like that it's nearly 70 percent of the code on github is in a language where people are typically dealing with javascript in some manner so that is a massive community that we have the potential to collaborate with by sharing libraries across our language boundaries now we can extend this principle into machine-based collaboration as well and this all funnels out of the dry principle this was my prompt personally to implement a framework called cloud kit you can find on github and I'm going to use cloud kit is sort of a storytelling mechanism here so that I don't bore you the idea is to mount these restful collections without too much tedious repetitious work so if I'm building a rails application for example I would typically generate a controller if I want to have some collection called things that I'm managing right now I generate a model I generate migration question will set of tests depending on what test framework you're using and how how they like to do things you generate a helper and a set of views to do all of your credit operations and then if you're doing heavy javascript validation or or I shouldn't say validation work in the browser user interaction then you end up writing or generating javascript models that match these and controllers as well in the browser contrast that with cloud kit which abstracts all these principles I was able to reduce it to one line of configuration in a rackup file so now you can say expose things and now you automatically get these things that would require code generation and duplication in rails so you can get a collection of things out of the web service you can get a specific thing this thing with the ID one two three all the historical versions of these things even specific versions based on the e-tag ABC for that one in a previous point in time you can post to create new things inside the collection you can do a put to update a specific thing you can also delete things of course and then get and head are interchangeable if you just want to get the metadata about an object there's even more but we're gonna wait a second so now we've got one line of code and we're still writing and generating javascript models and controllers so again there's still some things that aren't really dry there so let's see if we can take those out dry this up a little bit more and we can do this using machine based collaboration the principle here is that there's a root URL that anything working with the service can boot strapped from and you can ask it to return things like what collections are hosted on your web service now from this point I have an end to everything else hosted on the service and so in addition to things that we just talked about you can use the HTTP verb options which surprisingly it isn't used a lot and I think it might even cause a 500 and older versions of rails but you can you can ask for the options that you can perform with this things collection or what you can do with all these specific things and what according to the spec should happen and does in cloud kid is that you get an allow header back saying these are the operations you can perform on this object or this collection of objects and so I use that to create a plug-in for cloud kid called jQuery cloud kid and that enabled me to do things like set up a store just this jQuery plug-in you boot it that's just like your on ready function and jQuery when you start something up once it boots it's actually synchronize all your data with the server so all your collections are local there they're a mere of what's in your user data on the server and you can do things like create objects and it's all asynchronous because you are working with user interactions and then you can use it just like you might expect so this is sort of an intersection of themes here on our path to jruby and rhino uh... this is machine-based collaboration uh... following this dry principle leveraging human collaboration language like javascript that's running on arguably the collaborative platform which is the web before we get too excited about how we're following these cool principles and doing cool things we should note that we've totally overlooked querying which is also very common we need to be able to ask questions like all things that have a food property that's equal to bar so how would you typically do this you would write an active record thing or you would use some sort of custom finder you'd extract those parameters in the controller you might ask questions like does this apply to all my controllers because maybe it's pagination i want the second set of ten in this whole data set and then you need to make sure that the view sends all the correct parameters and all the different views that you're using if you think about how this is playing out you've got data already loaded once you've interacted with the service a little bit and the browser is on the server so what about a situation where there's a poor network connectivity or you're on the train which is where I do a lot of my personal hacking uh... do you do you limit your users from searching when they're not connected to the internet because they already have the data there so why should they have to be online to ask your server to search the data that's already local and then return it back to them again that's not very dry so let's clean this up other problems it's different for every single web app it's a one-off snowflake sort of situation it's not using machine-based collaboration it's certainly not collaborative with other people because it's not shared or standard so json query uh... from the sky named chris zip and dojo land this sort of standard lets you ask things in a cross service manner so i can say these things give me all them that have food that equals bar rating greater than this or this little double period here is recursive descent so any nested object has rating that's not equal to three sorted ascending by the rating and give me items ten through nineteen you can do this in the browser or on the server so then your question is now do i write two versions of this one in the browser one on the server also not very dry so now we have this sort of pragmatism here like we don't want to duplicate our work we want to keep it dry we want to use these types of collaboration and that's what finally prompted using a bridge so this isn't an impractical wild crazy experiment as much as this was actually needed and that's where this came from so running javascript on the server side now several choices that you can make one is no js note is really cool if you haven't checked it out i was pretty excited about the first time i saw it and uh... start using it from day one writing a lot of code in it it's pretty fast if you write it what would look like a rack app in node it's using google's v8 engine and it's using all non-blocking i-o so i was able to get like thirty seven hundred requests per second on my laptop in javascript which is unheard of previously it's good stuff check it out the thing i didn't like about it is that if there's anything that node doesn't provide as a rapper to v8 that means i'm in c++ land which i don't want to be in and so i had to toss that one aside being pragmatic there's also spider monkey that's the c-based javascript engine that's used in firefox a lot of projects do use that couch db vendors spider monkey i think mongo db is made the switch from rino to using spider monkey as well and there's a ruby project called johnson that's a ruby to javascript bridge also uses that i ran to the same problem there as well uh... it's a good project really good people hacking on i know that it's it's getting there maybe it is already there now but i was i was pushing part of it that was causing some seg faults and i couldn't get in a troubleshoot that because i'm i'm not really a c-person by trade there's also a web kit and i think chris wanstroth wrote a bridge to use this with mac ruby but again that i can't i can use that because i was thinking about ways i might want to play this thinking about jvm performance and stability in production plus this idea just being pragmatic finding a way to do this today is what led me to j ruby in rino actually happened during it a hack day at engine yard and i i was just frustrated and i just thought okay i'm gonna try this out i'm gonna write some stuff i'm gonna show that it's a fault and i'm gonna try to try this in uh... j ruby and rino and insured that it doesn't seg fault that was my act best demo watch this not say fault but it worked so j ruby as you know ruby on the java virtual machine rhino less people know about but that's a java library that you can access um... it's also from a zilla and you can use that to use java to script javascript techniques for crossing from j ruby to java it's actually pretty nice j ruby guys have done great work on integrating this uh... so if you're looking to do something like this this is sort of the approach that you can take there's java code i found on the mills illa website that's showing how to use rhino from java so you've got some import statements you're setting up a context which you can think of as your your javascript session and then finally you have this scriptable scope thing that you can call commands on that's uh... manipulating your session basically to convert this to ruby it's pretty simple you keep the import statements there in j ruby you obviously don't need the semicolons you can take off the typing information here in the the third line we don't need to declare types in ruby you don't need a semicolon in parentheses done with that line we can do the same trick with the next line it's now a little bit more concise it's not quite idiomatic because of the camel case method calls in java but uh... the j ruby guys have also done some work there so that you can use uh... which might call snake case to make this integration very smooth so now we've got something that we can command from ruby and it's actually talking uh... through java to javascript by rhino so after working with this seeing ways that i could use it i decided to abstract it into a gym uh... that's been published is called snarl it's on my github account it's also on gym cutter the slogan i got from ben burkart at work javascript in disguise it was taken from the cover of this javascript book but i can use rhino because the mozilla guys already stole that so i picked the closest thing i could think to to that and this is this transformer i had a variation this toy as a kid uh... until one of my my neighbor stole it i was really ticked off but this guy's name was was snarl so so this context that you created in ruby as called snarl javascript context you just create a new one of those and from here on out you can just play with it like it was a browser session so context evaluate one plus one in javascript that returns true on in ruby land there's also you can do things like in javascript you can assign functions to variables so here's a simple function to increment whatever number you pass in and then because you're doing this in the same context later on you can make another call to say increment this number i just passed in there it is comes out to four that's not super scientific or or elite uh... you can also think of this context as your your global scope so if you want to set a variable put food set the value equal to bar and then if you want to get it back out later you're also just saying get food returning bar where this starts to lend a little bit more power to you while you're writing code and wanting to share code with other people is the fact that you can load a whole javascript library just by calling this load function we'll get back to some cool things we can do with this in a second keep in mind though that if you are using something like this that crossing the bridge is definitely not free uh... so keep all your interactions with it course grain for example if i'm going to evaluate some javascript here and iterate over a collection of ten thousand items and just keep in incrementing those of storing them in a total really trivial stuff shouldn't take long right it's not bad it's point oh four seconds and that's using uh... the bridge in a course grain manner if we want to do the same thing using ruby and in the middle of this tight loop context eval this javascript actually was pretty sad about how poorly this performed i thought maybe some string interpolation here so i took that out just hard-coded some number in there almost no difference at all six point nine eight seconds just uh... in iterate over this measly little ten thousand objects here so don't take that approach when you're building your library and i thought in building this i would be creating ruby objects that live in javascript and vice versa trying to proxy them back and forth it just wasn't a pragmatic way to go i've not included any of that stuff in my library because it's it's not very useful at this point maybe someday it'll be pragmatic however if performance is not a concern and you would just like to say provide a scripting api for users to use in a one-off manner then there is a project uh... by this guy named cowboy d on github called the ruby rhino and after blogging and sort of talking about this a little bit he sent me a message on github very cool feature and we decided to collaborate so i think eventually we're gonna mix our projects in the same thing but he's taken a more fine-grained approach so if you're interested in that sort of scripting or seeing the techniques that he used that's a cool project to check out and i don't know whether he'll host my code or i'll host his but doesn't really matter as long as we're we're collaborating so back to this jason query idea we talked about earlier this guy chris zip who wrote the javascript library and dojo to implement jason query he's provided that in a dependency free manner for other people to use in other areas of javascript development so in cloud kit what i end up doing is keeping the whole framework but then right at the end using this jason query library so the way it works is it just attaches to a root DOM element here and you can say pass in whatever query came across the wire and then give it the collection that it's searching that seemed cool is a pragmatic step forward but it's really scary from a performance aspect because this jason thing means all of your data so how are you getting all this data especially if you're storing it in ruby land it just doesn't seem very feasible to pass your entire database as an argument to a function though we'll get back to how we solve this problem in a minute we're gonna take a diversion here validation normally if you're going to validate some objects what do you do you're using active record ruby on the server and you're duplicating those same validations in the browser with javascript and that is sort of a pain it's also it's not very dry so again let's use this to help us out it's also if you're duplicating things here you're not letting the machines collaborate with themselves to solve the problem for you you're going through this exercise that requires a human fill in values submit it and then see if it worked but there's no way for me to tell ahead of time if my thing is going to fail I just have to try and see if it breaks and that's not very good interaction design so this jason schema is another thing also by chris zip he's quite the thinker and he's quite prolific with standard proposals how about that oh yeah cool sorry about that sounded quiet to me suddenly okay so jason schema this is me declaring that I have a person that's an object because the other top-level thing you can do in in jason is just have an array as the outer thing it has these properties the person's names a string we've got some things about the birth date some men's and max we can use an integer if you want to use like Unix time or maybe a string but the format we're expecting is date time and it's also optional if you want to tell me how old you are I'm not going to push it so the cool thing about jason schema is that you can use it in combination with something called lard or low-level resource descriptor also there's sort of an intersection there with another spec called HTTP link headers so just like it in html you'd say a href rel something or other you can do this in header land to for machine interactions so we're saying that this thing that we just grabbed this thing number 123 this hypertext reference here with the semicolon scheme on the end of it the relationship is described by and we're using jason schema to describe this so this lets me detect what I expect on the server side to be the validation and even cooler and there I think they've done some experiments with this in dojo land you can use that to generate user interface elements like if I know that there's a string here I can generate some things just to start with start iterating on user interface it's a pretty cool technique and then obviously we return this foobar thing so again there's another library out there called jason schema all these things by the way you can find on my github account I've usually taken the libraries if they're not on get I put them in github and then write a test suite around and most of them aren't tested so I've read unit tests to first learn about the library and allow me to start refactoring or trying to mold it into the situation I'm in so using it we can say validate here's name Carl Huda and I pass in the schema that we created earlier this is just going to say yes this is valid and then we can try to mess it up pass in a number for the name and we get this thing back saying no it's not valid and then we have error messages number number found but a string is required and here the path to the thing that was busted is using something called json path which is kind of like x path but for json I don't know if they invented it with that in mind or not yeah I'm not sure so this again this is using machine collaboration to keep things dry and the unintended consequence that came out of this was actually a performance benefit and that is that this big entire database that we passed in as a method argument in JavaScript land we can actually index that for querying performance using json schema so thinking of JavaScript and json being sort of like Ruby they're schema free you can kind of do whatever you want with them there's a lot of things you don't really care about and you're not going to be searching on but there are property certain properties that you might care about like for a user you might care about their name so by declaring that using json schema you're saying this is something that exists for everything in my collection and that's something that's that might be important so you can use this information to control how you index the data I think this is maybe a little bit more usable approach than say map reduce which will cover you in all situations it's not saying that you should do one or the other I think maybe in conjunction this will be something cool to see in couch TV someday where you could just overlay this schema on a collection to say they sort of look like this and then you can spin off workers on the back end to try to keep this the index is updated and you can index things on the way in that raises the next question where do the indexes live if you keep the indexes on the Ruby side if you imagine a request coming into your server you have to think about the data that's coming in you can't just slap it in the database you have to look around in it and update some indexes but then on the JavaScript side you don't know about those so you end up crossing the bridge again it's really fine-grain manner and we saw the performance of that just completely stinks so the idea is lots of bridge crossing is bad let's try not to do this so this spawned yet another project extracting everything in cloud kit that was at the database layer on down into its own JavaScript library and it sort of models itself out after datamapper I haven't actually open sourced this piece yet but maybe by the end of conference I'll get enough hacking to do so I was previously using no JS as I mentioned earlier and I'm in the middle ripping out some of the assumptions I had in there for that so again modeling itself after datamapper or active record you're doing all your create reads updates and deletes in JavaScript all your callbacks are also in JavaScript so you can attach before saves after creates things like that and your indexing also lives inside the database in JavaScript and the cool part about is in the datamapper model you have this concept of adapters so you're not always using datamapper against a sequel store for example sometimes I saw you hit a live code one time a Gmail adapter for datamapper it was pretty cool to see it in a lightning talk but he was persisting data to Gmail over IMAP so in my case in this thing was to adapt inside the JavaScript database I have two adapters right now one is an in-memory adapter where you'd expect to find JavaScript objects in the browser the other piece is a local storage adapter also fully functional so if you go offline Safari Firefox IE all support this idea of local storage so you come back online later it's it's basically like a long-lived session that's tied exactly to a single domain name the cool part about that is beyond that you can run this exact same database on the server side so for example in my Ruby project using this bridge I can run the same database have a different adapter that's because it's in Java or JRuby I can actually adapt that to the file system so now we have the same indexing strategy the same validation strategy and the same storage strategy on both sides of the browser and the server this completely dries up pretty much everything left that I've been complaining about here so then you might ask what's left well not a whole lot but this is again this is sort of targeted towards a heavy JavaScript interaction type of app so the routing it's still in rack the benefit and also middleware so authentication in cloud kit for example in says saying expose these resources you can say contain them and automatically puts open ID or OAuth in front of those collections well we can keep that stuff in Ruby and still work in that world but it also allows us to continue to integrate with existing Ruby app so if you have a Sinatra app this rack based or or Rails or Merb that stuff can continue to work and you can continue to share code there if you want to take it one step further just try to go all the way off the deep end at this point you can try to reduce context switching even further by saying yes I'll keep my routing in rack however racks interfaces that they're just calling lambdas to return functions back to the browser basically you could mount JavaScript middleware in rack using snarl so rack does your routing gets gets the point where it's saying here's the request that came in you can hand this off using snarl and mount that and write all of your code in JavaScript there taking it one step further than this is something called JS GI so if you've heard of WSGI is the Python standard for this web server gateway interface that was what spawned rack this the Ruby parallel to that they also have one called Jack in JavaScript and it's sort of this JS GI standard so to wrap up here the the surprising other theme that ran across was this idea of crap this came came up over some really good Mexican food with a co-worker named Gilberto Medrano is here if you have a chance to talk to him he works with us at Engine Yard on user interaction design he's very bright and I've been able to learn a lot from working with them but the idea is that if you really care about the application that you're building and you're working let's say on something that has lots of interactions that need to work very well hopefully all of your apps are like this but I've seen some places where that matters less you can do away with terms and actually try to consider them to be obscene like front-end developer that's our front-end guys gonna do that he's the CSS guy and you can do away with other terms like that's the back-end guy's job or all have my DBA write these sequel scripts for me I hear less of this in the Ruby community but it is really prolific in the Java so the idea there is that everyone working on your development team takes full ownership of what they're building and it's more like the craftsman model you care about everything that you're building every interaction with the user and because the context that you're working in is very close to the user experience because you're using something like JavaScript then your mind is also naturally connected with the user and how these things work so I think it's a compelling way to promote collaboration even outside of our developer communities just with the users that we're building our applications for so we've covered here is basically the pragmatic ways to use JavaScript in the near term with JRuby and Rhino and also talked about some crazy far-fetch ideas of using LLVM and running Ruby in the browser and all this has been driven from this core engineering principle of do not repeat yourself that is it we aren't able to answer some questions in here this this is all my contact information my personal site Twitter my GitHub account I'd love to work with you guys on projects if you're using things like this but for now we looks like we've got about seven minutes left but there's any questions I'd love to answer no none of these are being used on production apps obviously JRuby is in production in a lot of places but these things I've been working on have been more experimental and I've been hesitant to ever slap a 1.0 on CloudKit for example because of all this flux in the background and trying out these different models but my personal intent is to use this in a production environment for some apps I'm writing in JavaScript they're not not for work at this point yeah you're envisioning that as more of like a I mean client-side validations specifically with that you were thinking like not as a substitute for server side but as an analog so it would do that first and then go to the server which would do it again to make sure that everything was right yeah so if you're using JSON schema you actually would have the same set of code running on both sides of the fence and yeah just in case someone had disabled those protection mechanisms submitted requests you'd have the same thing running on the server side there I would imagine that for the really simple cases those will be the same but that there are some times when you don't want to expose some of that information in the browser so you would you would probably have to supplement that on the server side somewhat saw some other answers you talking about offline databases whether it's offline or online it doesn't really seem to matter yeah and strikes me that obviously you want one client only download the portion of the database it's relevant yes and when you're running on the server side you execute against just portion of the database it's relevant to that client or do you run against the whole database and do extra stuff to limit the way you would in your regular Rails project to say no clients dot right so the question here is basically the scope of the data that you're querying is it everyone's stuff siloed or is it all shared and and how do you secure that I've stepped around part of that in CloudKit when when you say expose it's just all open data anyone can do anything with what's created when you say contain it's you're only working with your own thing so when you put it up there you're the only one that can do anything and access it the next layer that I've started designing with this adapter layer that I was talking about in the JavaScript engine is using a form of ACL so put this ACL which I'm trying to come up with a way to represent that and Jason that would be fairly generic but put this ACL on this collection that I've created and the users are all indicated by their open IDs so we can even grant permissions to people on other websites or other services right now I haven't totally tackled all that I think that there's going to be some some more optimization to let the drill out yeah so implementation wise for databases if you're using local storage in the browser there's just some native code that you're actually getting access to there there's also like in Safari there's a local SQLite database that you can access I started using that but it was actually more complex and why I needed which is in the local storage which is more hatch key value-based but on the server side that's that won't scale really so the old cloud kit model was using Tokyo cabinet which is ridiculously fast very stable it's a C library with really good Ruby bindings several projects are working on that but to make this work with the the new JavaScript approach what I ended up doing was creating an append only array that I'm using for storage so every time you update something it just goes on the end and that would it obviously works in the browser it's not a big deal but on the server side then you're just appending to the same file and you can avoid some corruption I totally stole that idea from couch DB but I think that's a it's a good model for doing writes safely exactly yes as in yeah it Jason even doesn't really care about the schema unless you tell it to you so the thing I'm working on right now is how you apply the schema to a collection and I don't have all that worked out yet like how it's going to spin off workers for things you haven't cared about previously but now you care about their structure but I don't have all the answers there but the idea is that once you declare the schema for a particular collection that's how it knows what it is but it doesn't care about anything else it's just all JSON data so as a user of it in JavaScript if you want to access a property that hasn't been declared it's fine you can set properties you haven't declared before no big deal this is long as you're not stepping on something that you've declared to be a certain format well you can actually set up your database as totally schema-free yeah but yeah then otherwise when you're booting it you have to say here's my config yes not particularly active record adjacent schema but the thought-bot guys how I originally found out about them is they were working on this library called jester which was an active resource client in JavaScript yeah to use rails in the back end I don't know where the project is at this point but yeah yeah I think Tamer's here he might be able to answer answer a little bit of that any other questions yes okay yeah for everyone's benefit there's an update on Johnson coming at the lightning talks tonight so I'd be very interested to check out what's going on there thanks awesome no I'm not are they presenting at the lightning talks by any chance or and what's the names of those libraries again okay red and Ruby JS two other JavaScript Rhino bridges that are available oh Ruby to JavaScript gotcha gotcha okay we should wrap up I see other people coming in I'm right at 45 minutes so thanks a lot