thoughts from brian samson

Sharing internal Javascript libraries between Rails projects using SVN and Rake

I’ve been developing rails apps for over a year with Six Fried Rice, and we’ve been using ExtJS as our Javascript framework. As is quite common in industry, we’ve developed internal libraries for Ruby, Rails, vanilla Javascript, and ExtJS. When I used to write Java, we would have our shared libraries in separate source control projects, package them up as JARs and just distribute binaries, which we would check in to each project that used them. This worked fairly well because of 2 important reasons:

  1. Our libraries were mature
  2. They could be developed independently of a certain project

Number 1 is nice because the libraries don’t need to be updated often, so you usually only needed to spend time getting them set up at the start of a new project. Number 2 was true because our libraries usually revolved around authentication/single sign on and they were maintained by an entirely different group in IT. This is more typical of large enterprise development.

So when I wanted to do something similar for our rails/js libraries, I initially turned to gems and plugins. Either of these solutions would work fine for our modifications to Ruby, and we do currently maintain 2 internal rails plugins that handle our ruby convenience methods and also some changes we’ve made to rails (that haven’t made it into core rails yet….). We keep those plugins in separate subversion projects, and everything work great.

Now enter Javascript. We write lots of javascript. Many times as much as we write ruby. The Javascript also tends to be dirtier than ruby, and we run into a lot of problems that are much harder to reproduce so I usually prefer to test changes to the libraries in the context of the applications that use them. This JS code is also very immature and changes frequently, often daily. The traditional method of developing a library on the side and updating it occasionally breaks down for this case, so the situation for the JS libraries is the opposite of the traditional way I described above:

  1. Immature code that changes frequently
  2. Development depends on applications that use the library

It turns out that there is a nice property that is supported by subversion called externals. This allows you to set a directory in one repository to link right to another repository. You can make changes to the library right there, commit it back, and then go run update on a different project and it will go grab the changes. This is perfect, except for one thing. Say I branch off of trunk to write a big new feature that ends up adding a lot of code to the Javascript UI library. This branch may take a few weeks to finish and the whole time I’m committing new code to the javascript, which gets propagated to trunk everytime I update, which could certainly introduce bugs that we might not want in other branches.

This leads me (finally) to the point of this post. I solved this by writing a rake task to “freeze” and “unfreeze” the library. When it is frozen, the library just stays at a version we know to be stable. When you want the latest code, or if you need to make changes, you unfreeze it and test. We’ve been using this solution for a few weeks now and its works really well, so I decided to post the rakefile that handles installation and freezing of a javascript library, called ‘jslib’ by default.

external_js_library.rake

Now I can do cool stuff like

rake jslib:freeze

which makes sure that the library stays at whatever version it is at right now forever, or until I issue:

rake jslib:unfreeze

which sets it back to HEAD and updates. I don’t think this is a replacement for gems/rails plugins, but it does a very good job of handling our shared javascript library. Thoughts?

Deep Dish Pizza

Deep Dish Slice

I’ve always loved pizza, and in my quest to make pizza at home that tastes better than pizza I can buy, I purchased “American Pie” by Peter Reinhart. The book is an interesting read about Peter’s search around the globe for the perfect pizza (which, incidentally, he finds at Pizzaria Bianco in Phoenix), but it also contains recipes for every type of pizza crust imaginable. I tend to agree with Mr. Reinhart as I usually prefer thin, crispy crusts, ala Napoletana. But I though I’d try something different the other day, so I made his Chicago-style cornmeal deep dish crust in a 9 inch cake pan. It was the best pizza I’ve made at home so far. The cust wasn’t too dry, it was oozing with cheese, mushrooms, sausage, and pepperoni, and I could only eat a slice of it before I was full.

Deep Dish Pie

The nice thing about this crust is that, according to Reinhart, it doesn’t benefit from a night in the fridge, so you can make this one on relatively short notice (only about 3 hours of total rise time). I’m glad I made enough dough for 2 pies :)

The Per Diem Budget

I read an interesting idea about budgeting spending money last week, and I was waiting for a new pay period to give it a try. So I started April 25th by going to the bank and withdrawing 14 tens and 14 fives ($210 total). I happened to have $39 in my wallet so we’ll see how cheap I have to be when we go out tonight :)



Updated Monday 4/27
Starting on a Saturday was tough. I put golf on the credit card and proceeded to spend all $54 at the course, dinner, and the bars after, although that’s probably less than I would have spent if not on this budget. And since I didn’t spend anything on Sunday, I helped myself to coffee and a danish from starbucks today, and I’m left with $26 in the wallet on Monday night. Not too bad.



Updated Friday 5/1
This week went pretty well. I had a few lunches out and a happy hour on Thursday, but I’m sitting here at 5:22pm on friday with $21 in my pocket. And I even loaned a buddy $20 that he’s paying back tonight, so I’ll be off to San Diego tomorrow morning with a little over $50!

Capistrano: Calling tasks from other tasks

I wrote a new capistrano task for deploying a rails app the other day that would totally reset the old deployed database and give me a fresh new one with fixtures pre-loaded. This is useful for deploying different branches to the same location on a server. However the lack of proper capistrano documentation let to some wasted time figuring out how to invoke previously defined tasks from a new task. Most of them are just simple methods you can call, but to call the task deploy:migrations is a little more complex because it’s really a task called migrations in the deploy namespace.

So for my new “super deploy” task, deploy.rb looks something like this:

task :drop_db
  run "cd #{deploy_to}; rake db:drop"
end

task :create_db
  run "cd #{deploy_to}; rake db:drop"
end

task :super_deploy
  drop_db
  namespace :deploy
      migrations
  end
  create_db
end

Pretty simple but I got hung up it for a few minutes. So there you go.

Installing Ubuntu 9.04

I’ve been running Ubuntu 8.04 since may of last year and have been extremely satisfied. I skipped 8.10, and now I’ve started to notice some of my software getting old, and since I never want to mess with backports again, I’ve been looking forward to the new “Jaunty Jackalope” release (I think the names are terrible). In short, it worked great.

It took less than 15 minutes from the time I inserted the CD to when it presented me with a GRUB menu. I pretty much clicked through all the menus as defaults, except I changed it to install over to instead of next to my 8.04 install. It used ext3, and I didn’t see an ext4 option anywhere, which would have been nice. This time it even noticed my Windows drive and put a “Vista” menu item at the bottom of GRUB that worked perfectly the first time, without me having to remember a bunch of menu.lst hide/map commands.

First thoughts: They were right about the boot time, it is substantially faster to get me to a login prompt. The default desktop wallpaper is ugly, but it detected my 1920×1200 display perfectly. There were only 11 updates I needed to install at first, which is pretty good but will certainly get much worse as time goes by.

Wow feature: After I installed the new updates, a window popped up asking me to configure my printer. Not only had it heard of the Canon Pixma iP3000, it had it preselected. I clicked “next, next, print a test page” and after 30 seconds of the printer adjusting itself the test page shot right out. That’s pretty amazing. However in the settings dialog that followed it told me that while the printer was “shared” it wasn’t “published” and I’d have to go see the “server settings” to change that, wherever those are.

The fancy compiz desktop effects aren’t enabled by default, but when I chose to enable them it told me I have a nvidia card and then installed the drivers for me. Restart (login/logout) and its up and running and I have my cube back.

MP3 files played after a couple clicks to a dialog about restricted packages. I understand the dialog but that doesn’t make it less annoying.

Overall, the install was incredibly painless and I was up and running with the defaults in no time. I didn’t have to type on a command line at all and everthing just worked out of the box. Pretty impressive.

16 Million Terabytes

Just so you know I don’t play favorite and just post screenshot of windows being stupid, here’s one I ran into on my Macbook Pro this afternoon. That’s a lot of virtual memory right there.

16 Million Terabytes

Then why is there a cancel button???

THEN WHY IS THERE A CANCEL BUTTON??!?!

Thanks for being so specific.

I’m trying out the windows 7 beta. After all these years of usability testing, you’d think Microsoft would have learned not to write horrible “confirmation messages” like this. In fact I would argue they shouldn’t put a confirmation message at all. Maybe just show me the file. Maybe ding. Certainly not this.

The files have been exported in the format you selected

Also on the first screen of the export contacts wizard, the default button is cancel. So I typed a file name and hit enter and the whole thing closes.

Thanks for the rally, Barack

Stock Market March 10

I’d just like to quickly thank Barack Obama for propping the Dow Jones up today. The talking heads out there who blamed him personally for its recent tumbles are conspicuously silent today.

I just want to play video games

So I wanted to play Fallout 3, which my friend Jeff told me is totally bad ass. Unfortunately it is, like pretty much every other PC game out there, only for windows. I could have monkeyed around with WINE for a while, but since I had a copy of the Windows 7 beta sitting around already and Jeff gave me a spare hard drive, I figured what the hell. So here goes:

At 7:45 I reconfigure the BIOS so that windows thinks my newly installed HD is the only one. It somehow discovers the other drives, but at least it thinks it’s drive is #0, so I think I’ll be ok. After picking my language, it starts installing. It sits at the first step, “Copying files” for about 4 seconds and then moves on to “Expanding files” where it sits at 0% for 5 minutes and then slowly creeps up to 100 over the next 35 minutes. It reminds me that my computer will “restart several times” during the install. No problem.

After the files are done expanding, it says it reboots, but I don’t see a POST or hear a beep, i just get a black screen. The hard drive is furiously spinning, so I wait it out another 15 minutes, during which time num lock flashes on and off sporadiacally. Now it’s like 8:45 and I’m starting a black screen, so I kill the power and reboot. The “Safe Mode” menu briefly (and I mean briefly) shows up and then it picks safe mode. Windows boots up, it says it’s continuing installation, and then a dialog pops up that says it can’t continue installation in safe mode. Restart. Windows comes up, eventually tells me that the install did not complete successfully and it needs to reboot and start over. Restart. It comes up and tells me the same thing, so now I realize it want’s me to reboot off the dvd again. Restart.

Now it’s almost 9:00. I restart the installer, this time I find the advanced menus and format the hard drive it’s installing to. 2 seconds of “copying files”, only 10 minutes of expanding, and then another reboot. This time windows comes up and continues the install. I’ve only lost 90 minutes of time, maybe I can still play fallout tonight :)

9:12 - While windows is “completing install” it decides it wants to up the resolution from what looks like 800×600 to the full 1920×1600. It ups it alright, but only the top left quarter of the screen has anything and the rest is black except for a “Windows 7 Build 7000″ in the bottom right corner. It sits like that for another minute or so and reboots again.

9:15 - Setup is preparing my computer for its first use! After entering my product key, it guesses that the time is 4:17 AM, which is strange because its really 9:17pm. I tell it that it’s a home computer and it sets up a “Homegroup” with the easy to remember password of “pw6IU3gV1u,” and no way to change it.

9:21 - Windows spends 4 minutes “preparing my desktop.” What took so long you ask? 2 icons (one of which is the recycle bin) and a fish background. Also a message about how it needs to install 4 updates. Not too bad I guess, only 23 megs. And I can start the fallout install now.

9:28 - It finished downloading updates about 5 minutes ago and wanted to reboot. I clicked “later” and started installing fallout. Then all of a sudden right in the middle of the install windows says “Logging out” then “Installing updates” then “Shutting down” and reboots. This is garbage.

9:31 - Back up, IE opens up and tell me without a hint of irony that my “last browsing session closed unexpectedly.” Yeah. Thanks for the heads up.

9:45 - Fallout is installed. Sweet. 2 hours isn’t that bad, I guess. If thats the price to pay to play the one good video game that comes out every few years, I can deal with it.

« Previous Entries