Sunday, November 25, 2007

Django - the "D" is silent

"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design".

I am quite new to different frameworks and this is probably the first Open Source framework I've actually used for anything. I've heard that there are other frameworks that offer similar things - like Ruby on Rails; however, I've never actually used any of them, so Please keep in mind that my opinion may be a bit biased.

Django tries to keep everything automated and adheres to something called the Dry Principle. It makes life so much easier when creating database designs that I'm pretty impressed. From what I've experienced, it can create full database structures, administrative logins/web pages given object specifications (similar to normal OO Programming Syntax); on top of that you can design urls with minimal code.

Here is an example of an object model (taken from the Django tutorials) used to create the database:
from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Admin:
pass
As you can see from the example, that is how you would create a table called "Poll" with two fields - question and pub_date. Now you can login to the administrator page (already automated) and add as many new polls as you like; simple right? You could even use python shell or a script, and create it like you would a class object. Like this:
p = Poll(question="What's up?", pub_date=datetime.datetime.now())
If you ever wanted to create a simple website or blog, you should check Django out. Try a few tutorials and see what it has to offer for yourself; if you have any trouble login their irc #django IRC channel on irc.freenode.net. There's a lot of nice people there who are more than willing to help out.

Tuesday, November 13, 2007

Metrics Project Contributions

As I have explained in class, my project requires some contributions. Currently, I require some people to test the patch I created on different platforms (linux, mac) and install the extension to test the server script.

Testing the patch only requires someone who uses or has one of the platforms listed above to build firefox with the metrics extension. All details on how to do this is on this blog (click here). I only require one of each, so that would be two people. Please leave a comment below if you're interested; or email me at my student email located on the school wiki (here).

Testing the server requires someone to build the extension with firefox and change some preference settings so that the extension will automatically start and send data to my server (click here). Once the extension has started (you can check by typing about:metrics in the address bar), you should see some xml style data, you just need to use it for about 5 mins. After around 5mins, the data in about:metrics should be reset and that means the data was sent; this is where you can disable the extesnion in the preferences.

Thanks to those who are willing to contribute. Please leave any comments or questions for the above.

Wednesday, November 7, 2007

My Experience at FSOSS 2007

FSOSS 2007 was a great learning experience! Before I attended the event, I dreaded the idea of coming to school on my week off; however, the knowledge I gained was irreplaceable. Although I'm still a student, I create a lot of little applications in many different languages for class, and I have always loved the design aspects. I mean, why do we develop applications? I think that many people get so involved is the code or the next best feature they thought of that they forget who the application is for. The average user doesn't care about what happens behind the scenes; they care about how easy and suited the application is for them; which is why I enjoyed the presentations that Jay Goldman/David Crow and Mike Beltzner gave.

Mike Beltzner presentated "Product and User Experience Design in Open Communities", and Jay Goldman and David Crow presented "Usability Anonymous: A 12 Step Program for Better User Experiences", both of which I thought was quite interesting. They kept the audience a bit more lively and made the experience fun. Both presentations were about the user, and tips in creating better software for them; I think they both mentioned the same book, "Design Patterns" by Jenifer Tidwell. However, each presentation took a slightly different focus. Mike Beltzner discussed much of building a community and letting the users get involved, while Jay Golman and David Crow talked more about understanding the user in design decisions. Although I liked the slides that Mike Beltzner gave (very colorful), I thought I gained a little more from Usabiltiy Anonymous. Sorry Mike!

I was even registered for the Drupal workshop which I didn't attend since I wanted to go see the presentation on Facebook, but it wasn't what I thought it would be about. The presentation was great and they presented a lot of interesting concepts provided in Thrift, an open source cross-language development framework, but my brain must have been on off because it got a little too technical for me. On another note, facebook does provide cool little programming challenges every once in awhile and those can be fun to solve.

In the end, I think I liked my time at FSOSS. The food was okay, the presentations were fun, but the little things that were gained were more than worth the loss of two days of my break. Thanks again to all those who participated in making the event go as good as it did!

Tuesday, October 23, 2007

My O.1 Experience

What is the metrics extension you ask? Well, the general idea of the metrics extension is to collect browser usage data. Although the metrics extension is not yet complete, they want to keep track of UI interaction, Usage of Features (bookmarks, extensions, themes.....), Memory usage/effectiveness, system configurations, and other related subjects. It will not however, collect any personal data that is identifiable to the user; everything will just be appended to a non-identifiable unique ID to distinguish different browsers.

For most of my 0.1 release, I have to created a small server script to the metrics extension. This basically involved my server script to recieve requests from the metrics extension and do the following - recieve uploaded data, or send back a config file. Currently, the data sent to the server is just uncompressed and saved into a file to read manually; however, in the future, it will be stored in a database infrastructure and hopefully used to display the data in many ways. For a better understanding of my o.1 release please check out it's wiki - Metrics Server Collection Wiki and to get a working version of the extension please follow these instructions How to enable Firefox Metrics extension.

The experience I had working on my project was quite different from most of my other classes at Seneca. The project required me to work with a massive existing code base, creating patches, debugging, server scripting, and http response headers. The experience was something else and I believe I have gained a better understanding of how my future career experience will be like. In addition, the project has also given me the opportunity to learn about working in an open source environment and the real idea behind community. I would suggest that all student at least try to do something in the open source community once.

Monday, October 22, 2007

How to Enable Firefox Metrics Extension

Before reading this guide, please make sure that you understand how to Patch and build Firefox. The steps will basically assume that you have knowledge of building Firefox and will skip basic information. If you don't understand how to Patch or build Firefox please refer to the "Resources" below.

Basic steps to install & enable the Firefox Metrics Extension

1. Checkout a nightly build from the Mozilla CVS.

2. Patch the metrics extension with this patch
--Metrics Patch--

3. Add the following to the .mozconfig
ac_add_options --enable-extensions=metrics


4. Build Firefox.

5. Go into the "dist/bin/extensions/metrics@mozilla.org/defaults/preferences" folder and edit the metrics.js. It should look like this.

pref("metrics.upload.enable", true);
pref("metrics.upload.uri", "http://matrix.senecac.on.ca/~sljung/metrics/metrics.cgi");
pref("metrics.event-count", 0);


6. Start the Firefox build.

Resources
MDC Build Guide
Guide to Build Firefox in Windows (Blog)
Seneca Lab in Patching
Guide to Patching & Building (Blog)

Thursday, October 18, 2007

Watching a Bugzilla User

For my weekly assignment, I decided to watch Vlad for a week. It was quite interesting to see how many e-mails I would get on a daily basis. In fact, I recieved emails faster than and in more quantity then the spam that goes to my mail. From it, I believe that my user, more or less, watches specific types of bugs. Most of the e-mails I recieved about bugs were on things related to graphics. Not sure if that's the right term; however, most of the subjects were on things like SVG, APNG, CGBITMAPS, canvas, etc....

I actually found most of the bugs interesting and hope that probably in the future I may be more involved in trying to fix them. For now, I will basically do research and learn more there is to all things Moz.

Monday, October 15, 2007

Firefox Extension - File I/O

For my blog post today, I will briefly explain how to write data to a file in a Firefox extension. This can be used for error logging or whatever your purpose. One of my projects has required me to produce XML documents on the local machine; therefore, I have used it for that. Please remember that this is all done using javascript.

The first part of the code basically needs to find the extensions file path. To most, this is within the mozilla profile folder. This is needed if you want to keep the file in the same folder as your extension. Otherwise, you could leave it out or give it a different file path. Id is used to hold the id of my extension.

//get extensions file path
const id = "sample@foo.net";
var extension = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager)
.getInstallLocation(id)
.getItemLocation(id);


The second part of the code is used to check whether or not you have the proper permissions to write a file to the local machine. I have not thoroughly tested this though.

try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e)
{
alert("Permission to write to file was denied.");
}


Next, I create a variable to hold my file path (just easier for me); this is done using the extension path that we found earlier. Then create the proper components needed to write the file. First we need nsILocalFile, which to my understanding is like creating an instance of a file object. This needs a path which is basically the filepath I created. Then you need to create it.

//create proper path for xml file
var theFile = extension.path + "\\" + "metrics.xml";
//create component for file writing
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath( theFile );
if(file.exists() == false) //check to see if file exists
{
alert("creating file...");
file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420);
}


Now, we create an output stream; nsIFileOutputStream, and give it the proper modes. As shown in my comments, I have chosen to do only write, create file if not exists, and truncate which basically deletes the content (leave this out and add 0x10 if you want to append to a file).
Then, you write to the file; giving the content and the length of the content, and close close the stream.

//create file output stream and use write/create/truncate mode
//0x02 writing, 0x08 create file, 0x20 truncate length if exist
var stream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);

stream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);

//write data to file then close output stream
var content = this.xmldoc;
stream.write(content, content.length);
stream.close();


For more information on File I/O you can find it at
Mozilla Developer Center


Also check out the XPCOM reference at XUL Planet
. This is basically where I go to research each component used.