Archive for the ‘Hacking’ Category

Learning to read

Monday, August 18th, 2008
Image licensed under Creative Commons

Image licensed under Creative Commons

No, this is not a post about illiteracy.

OK, now that I got that off my shoulders…

I’ve been learning Ruby on Rails for the past few weeks, and I’ve encountered an interesting question that I’ve faced a few times before and never really found a good answer to.

How do you read code?

And I don’t mean that in a metaphysical sense. I mean when you’re learning a new framework, language or technology you usually look at some code written in it to try and see how real world applications use it. These days you can pretty easily find Open Source code written in almost anything. What I find difficult is figuring how to read the code of these applications.

I’ve read a book about Ruby on Rails, so I understand the basics decently well. I’ve created a toy application just to see how to do it. But the jump from that to digging through source code for a full fledged real application is pretty huge. Where do you start? Initally I started looking at the models to try and understand the objects that the application dealt with. But I found that to be a bit confusing. Then I looked at some of the key controllers (like user authentication and those that handle the main pages) and also found that a bit confusing.

Finally I sort of settled on looking at a specific page in the app, looking through the view that generated it, then going to the controller that was invoked, and maybe looking at some helper methods and model code that I found there. I found that to be a reasonably understandable strategy. But I’m not really sure if it would have worked as well if I didn’t already have looked at some model/controller code before hand.

This is not specific to RoR. If you learn a new development environment, how do you figure out where to learn the code?

Running ‘ri’ with colors under Mac OS X

Tuesday, July 29th, 2008

Ruby has a command line utility called ri for looking up documentation, and ri has a nice feature of displaying its output with pretty colors. Unfortunately, when I tried to run it (ri -f ansi) what I got was:

After tinkering about a bit I gave up. But today I decided that I’ll have my damned pretty colors even if I have to spend a lifetime getting them! Thankfully it only took 10 minutes. ri uses less to display its output in a scrollable form, if you make it not use less you get what you want by giving it the -T option:

“But…but…but… I like scrollable output!”, says you, whimpering softly.

Well, stop your cryin’, so do I.

less itself takes an option to treat escape characters as escape characters (duh!) instead of just printing them. So you want to make it use it. Here’s what you want to add to your Bash profile file to make the magic happen:

# I likes pretty colors!!!1!!
export RI="-f ansi"
export LESS="-R"

And the result is:

UTest at DemoCamp 16

Tuesday, December 4th, 2007

Today I presented a similar presentation to what Mike, Pardis and I presented 2 weeks ago at Eclipse DemoCamp.

I managed to squeeze our 15 minute presentation to under 5 minutes (I don’t know exactly how long I took, anyone keeping the time?), which was a bit of a challenge. I’ve got to admit that I almost got a heart attack right before the presentation. After bringing up all the software that needs to run, I tried to create a new assignment (because I had wiped the DB) but nothing happened. Queue panic attack. Literally nothing worked. Full stop. After some useless clicking around I was about to give up. As a last resort I decided to switch browsers and try with Camino instead of Safari. Insert long sigh. Turned out that for some magical reason authentication stopped working with Safari (even though it worked perfectly an hour before). Lesson: never wipe the DB right before the presentation, have everything exactly configured an hour before.

Overall the presentation went really well and I got very good feedback from people in the audience. One of the criticisms that I heard was that I never said what problem the software was trying to solve. Fair enough, I think that would be a good point to add to this presentation. I was kind of disappointed that only one question from the audience was asked. I guess for next time I present I really do have to plant people to ask at least one or two questions. :-P

Overall the demoes were much better this time than the last few times that I attended. I was very impressed. The demo of ShapeShop was pure amazing. I remember trying to play with 3D Studio MAX and Maya in high-school and even though I could figure out some stuff it was really inaccessible. There was just no way I could have come up with anything more than what a retard-3-year-old would have doodled on a piece of paper. I think that software like ShapeShop could play a similar role to what digital cameras have done for hobby photographers. We could potentially see people start doodling 3D models and being able to form communities like flickr, but for 3D models. What about iStockPhoto for 3D models

The HealthSpoke demo was pretty interesting too. The demo looked pretty slick. But I have pretty big concerns about doctors sharing patient records. Forget sharing. What about even storing medical records off site? I don’t remember the latest on this but I’m pretty sure there’s legislation that deals with this specific issue. When the presenter said “according to my interpretation of the law…” I got the impression that they didn’t really look into it. Of course if this is mostly targeted towards alternative medicine providers and personal trainers, then no worries; but it shouldn’t be marketed as a system for medical doctors then. The other problem I see with this idea is importing data from legacy systems. Read: paper records. For this to be even somewhat effective doctors would have to import thousands of patients’ records from pen-and-paper systems into the system. That’s just not going to happen. I remember thinking of this kind of easy-medical-record-keeping system for a startup several times over the past few years, but the problem was always of how to get the existing information into the system.

The other thing that I really found interesting yesterday is Mark’s mention of FixMyStreet. Which is a website where people can report problems (like a bug tracker) and it is linked on the backend with the city’s systems and lets them find and prioritize problems. Crowdsourcing city inspection! Genius!

All in all a great DemoCamp, too bad I won’t be able to attend the next few, but I look forward to attending them again in the summer.

(more…)

Ontario Linux Fest

Sunday, October 14th, 2007

Yesterday I was at the first ever Ontario Linux Fest, manning the Eclipse booth together with Remy. Also hung out with a whole bunch of people from Red Hat’s Toronto office: Sami, Lillian, Ben, Andrew, Behdad, Tom and Matt. I think the conference was great. It was pretty small and intimate and didn’t feel like LinuxWorld; which I think is way too huge.

You can see some photos at Andrew’s blog post. I especially like this one :) :

Eclipse Booth

We had a whole bunch of people come by the Eclipse booth, and to my surprise at least 60% didn’t even know what Eclipse was. Another 20% kinda knew what it was but never tried it. The rest knew what it was and at least have tried it once. Only a few people actually used Eclipse. That was kind of surprising to me, even though I knew that Eclipse wasn’t very well received by the Linux crowd. Andrew‘s presentation was well received from what I heard, so hopefully that will help with spreading the word about Eclipse. I think that the efforts of the Eclipse linux distros project is well worth it, and will help really help people use Eclipse on Linux.

OpenMoko

I had my Neo1973 with me and was playing around with it in the booth most of the day. A *lot* of people came by because they saw it and wanted to play around with it too. :) So that was fun. Yesterday I flashed the latest OpenMoko image to the phone and was actually able to make phone calls out of the box, which was very exciting. I even used the phone all day as a cell phone, and was surprised how long the batter actually lasted: most of the day. Of course I connected it to the computer once in a while because I was shuttling files back and forth. But since I always have my laptop with me anyway, that’s not a problem so I hope to start using the phone full time soon.

I think I’m also going to go to FSOSS, since it looks pretty interesting and it’s going to be a good break from school. See you there. :)

Ontario Linux Fest tomorrow

Friday, October 12th, 2007

Tomorrow I’m going to be manning the Eclipse booth at the Ontario Linux Fest, together with Remy. That should be a good break from doing school work all the time. :-)

There’s going to be a pretty huge turnout of Red Hat folks from Toronto , so it’s going to be fun seeing everyone again.

I’m also going to have my Neo 1973 phone there (which is currently on loan to Sami). Since the Fedora and Eclipse booths are right next to each other I hope Sami and I can have a lot of fun playing with it.

Come say hi if you’re there!

Don’t $@!% with IDocument.DEFAULT_CONTENT_TYPE

Friday, December 15th, 2006

I’ve been doing some general bug fixing of the Specfile Editor today and noticed that we had some problems with partitioning the document. We had defined 4 types of partitions for spec files:

  • Files (for a single %files section)
  • Scriptlets (i.e. %post, %prep, etc.)
  • Changelog
  • Default (for everything that is not one of the above)

What I noticed is that the default partition never got used, instead the IDocument.DEFAULT_CONTENT_TYPE partition was used for this. After digging through the code for a while and “fixing” what seemed to be the places that caused this, I ended up completely foobaring the partitioner.

Turns out that the Eclipse Text framework doesn’t support having a different default partition, and will happily barf in your lap if you try to force it.

Morale of the story children: Don’t $@!% with IDocument.DEFAULT_CONTENT_TYPE.

Trying out the Specfile Editor

Friday, September 22nd, 2006

I’ve been asked several times how people can try out the specfile editor that Andrew and I have been working on for the past month or so. We’re not including it in the update site where our other plugins reside just yet because I don’t think it’s stable/usable enough for that, and it’s not in fedora extras yet for the same reason. I hope that maybe by the time of FC6 final or a bit after it’ll reach a good enough state that we will put it in those places.

If you just one of those people that want to try it now, awesome! You have 2 options:

1. You want to just try it out for a bit but not really use it for editing specfiles:

Just check out the org.eclipse.cdt.rpm.editor plugin from :pserver:anonymous@sourceware.org:/cvs/eclipse (hint: copy paste that string into the Eclipse CVS checkout dialog), under the rpm module, and just run it as an Eclipse Application. Click on the Run menu, Run. Then right-click on Eclipse Application, click new, pick the plugin in the plug-in tab, and run. You can now create a new project (just a general project is good) and import your specfile into it. You can now edit the specfile with the specfile editor, which will open automatically for files ending with .spec.

2. If you want to actually use it for anything more than just a cursory glance you don’t want to have 2 Eclipse instances around, unless you’re very RAM-happy. Here’s what you do:

From :pserver:anonymous@sourceware.org:/cvs/eclipse checkout org.eclipse.cdt.rpm.editor and org.eclipse.cdt.rpm.editor.feature (under the rpm module) into your workspace. Now create a new project, this will be an Update Site Project, under the Plug-in Development category in the New Project wizard. Note that you need the PDE installed for this, under Fedora all you need to do is ‘yum install eclipse-pde’. Now double-click on the site.xml file in your new project, create a new category, under that category add a feature, select the org.eclipse.cdt.rpm.editor.feature project in your workspace as the one to add. Now click on the ‘Build’ button. This will create a local update site in your workspace. You can now use this to install the plug-in.

Go to Help-> Software Updates ->Find and Install, pick New Local Site on the second page, and pick your newly created update site. Now if you want to update the plugin, all you have to do is CVS update the plugin in your workspace, hit build in the site.xml of the update site. And then go to the Find and Install dialog again. Only instead of installing a new feature pick ‘Search for updates’.

Enjoy.

Specfil-editor: changelog entries

Monday, September 4th, 2006

I’ve spent a few hours today hacking on the specfile editor after not touching it for the past week or so. Andrew’s made some great progress towards making it useful to real users, *shudder*. So I spent the afternoon implementing a simplistic ‘Create ChangeLog entry’ action. We’ll probably make this an extension to the ChangeLog plugin in the end, but for now being part of the specfile editor is good enough.

Here’s a short screencast of how it looks.

I’d love to hear what other people would find useful as part of the editor, this would be great to help us determine the direction for the near future.

Introducing an Eclipse spec-file editor

Wednesday, August 16th, 2006

A couple of weeks ago the guys in the Eclipse group in the office got together to try and hack together an initial version of a spec-file editor for Eclipse, and learn how to write editors for Eclipse in the process.

We spent a couple of hours on it and got it kinda working. It wasn’t really an editor because it didn’t have any extra editing features, but we did get some syntax highlighting done in addition to figuring out at a high level how Eclipse editors work.

Last week I spent some time fixing up our work on the editor. It still not much, but I have working and pretty nice looking syntax highlighting working right now. Take a look:

The squigly white line in the middle is my amazing artistic skills when combining 2 shots :) .

Now I’m trying to figure out how to do content outlining, and the next step after that would probably be formatting or simple error highlighting. In the slightly further future we can have things like content-assist, validation (a.k.a. not-so-simple error highlighting), validation with external tools like rpmlint, and other goodies.

A lot of these features require parsing spec files, which right now isn’t that easy. I haven’t found any source of information that have a precise/formal definition of spec-file syntax. Basically I want to know 2 things:

  • What are the rules that rpmbuild/rpmlint use for reading or validating a spec file.
  • Is there a library that I can interface to that would do this for me?

I thought initially that rpmlib would be able to do the parsing, but the docs I read on it suggest that that would be outside of rpmlib’s scope.

Any ideas out there?

P.S. you can check out the editor at pserver:anonymous@sourceware.org:/cvs/eclipse under the rpm module. (Tip paste the CVS string pserver…/eclipse into Eclipse’s new CVS repository wizard).

New ChangeLog features

Wednesday, June 21st, 2006

Kyu Lee, one of the new Interns we have in the Toronto Red Hat office, has been working on the ChangeLog plugin, trying to implement some new features.

He’s made great progress, and yesterday we pushed an update of eclipse-changelog 1.1.0 into both devel and the FC5 updates-testing repository. This version has a ChangeLog editor, which has nice color highlighting, and also allows you to jump to a file by Ctrl-Clicking it’s name in the ChangeLog. A modest, but very nice start. I think this plugin can become much more useful and usable with a very minimal amount of love. If you use Eclipse, give it a twirl.