Archive for February, 2010

Today’s Challenge:

Posted in open source on February 26, 2010 by scottdowne

Today, I am going to see if I can edit what I created in my last post, but this time, when the mouse scrolls, I want the circle in this example to follow a circular track, and not an up and down track. Then before the end of the day, I will post my results.

So far, I believe this is what I must do.

  • Create a circle of x and y points, and store them in an array instead of drawing them to the screen
  • Sort the array’s points, as I cannot think of a way(yet) to draw a circle in the order it is used.
  • When the mouse wheel is moved up, go to the next point up in the array if it’s not the last one, if it’s the last one, go to the first. Same thing but reversed for mouse wheel down.

Update: I have created the circle, and set the point into an unsorted array.
Next: sort it, and apply the “track” to the mouse scroll

Update: To make my life and my computer’s life easier, I’m going to just create an arc, and sort the arc, then apply the arc three more times. Kinda like 1/4 of the circle, then must copy and paste it, flipping it, after the arc is sorted.

Update: And challenge complete.

Self reminder: As of this point, when I scroll the mouse, it moves the objects, but it will also scroll the scroll bar in the window, I want to figure out a way to disable this, while still allowing the mouse wheel to scroll the scroll bar when the user wants it.


Mouse scroll wheel hack: update

Posted in open source on February 25, 2010 by scottdowne


So I was playing around with my solution, my little mouse wheel hack for processing.js, that I mentioned in my last post. I first was making sure I could get it to work in Firefox, Safari, Opera, and Chrome. It really wasn’t all that hard. I also wanted to jazz it up a bit, and use the mouse scroll for something more meaty. This is what I came up with.

In my last example, it was setup to work in all browsers, but it was only being called the Firefox way.

The problem was in this line:

addEventListener('DOMMouseScroll', wheel, false);

Firefox uses ‘DOMMouseScroll’, Opera, Chrome, and Safari use “mousewheel”

So, after some research, I changed the line to this:

addEventListener(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)?"DOMMouseScroll":"mousewheel", wheel, false);

What this is doing, is testing the navigator.userAgent for the word Firefox. Obviously, if you’re using Firefox, the word will exist in the same spot. There are other less reliable ways to do this, as I found in my researching of this problem. I usually lean towards the solutions that make the most sense to me (obviously :P). The rest of the line just loads the certain string inside a ?: conditional statement.

I’ll do some testing and cleaning tomorrow, and if I don’t find any bugs, I’ll flag it for peer-review.

Mouse scroll wheel hack

Posted in open source on February 20, 2010 by scottdowne

Progress for the mouse wheel feature in processing.js.

This is the hack. They call it a hack, as it was not intended for use with processing. It just so happens that any Java code written in processing works, I believe. So I think all I need to do here is the same thing, add a hack. It’s already possible to use the mouse wheel in processing.js, as I show here Note, this only works in Firefox that I know of, it does not work in Chrome or Opera. This is without adding anything to the processing code. Because processing.js uses javascript, any javascript is valid code, so I wrote a simple mouse wheel event in javascript using DOMMouseScroll.

I want to clean up the code in the example, though. That’s my next task.

processing.js 0.1 release

Posted in open source on February 19, 2010 by scottdowne

I have finished my work for 0.1 as detailed in my project plans here and here

The project wiki: here.

my 0.1 release was in time to make it into the 0.5 release of processing.js

I did bug #226 for my 0.1 as well as some automated test cases for the new code I implemented.

What I had to do was protect string content from the procesing.js parser, then test it.

my initial patch: here

second patch: here

Final result: This code was modified to increase speed every so slightly, but every bit counts.

var strings = aCode.match(/(["'])(\\\1|.)*?(\1)/g);
for ( var i = 0; /(["'])(\\\1|.)*?(\1)/.test(aCode); i++){
aCode = aCode.replace(/(["'])(\\\1|.)*?(\1)/, "");

into this.

var strings = [];
aCode = aCode.replace(/(["'])(\\\1|.)*?(\1)/g, function(all) {
return "";

I have to thank Corban Brook for helping me fix the code, and get it out as soon as I did.

Automated tests: here

What I learned

  • Object orientation in javascript. By seeing Java object oriented code being transformed to JavaScript, I got a good understanding of how JavaScript objects work.
  • Managing and working with processing.js source code; large code, that was not created by me.
  • Basic uses of irc. I used ChatZilla and later irssi. I switched so I could use irssi with screen.
  • Revision control: git and mercurial. I used git to work with processing,js, and mercurial to work with Firefox (to setup js.exe, which I mentioned in this post)
  • I learned how to build Firefox, and setup a Firefox build enviroment.
  • I learned some standards for code. Like where to and not to use whitespace.
  • One of the most important things; I learned the importance of blogs.
  • I learned there is no such thing as too much testing.

A lot of this is technical stuff that required troubleshooting. I am confident that the next release will be less of a learning process, and I can get deeper into the code.

re initial project plan

Posted in open source on February 19, 2010 by scottdowne

Ok, so I’m going to go back to my initial project plan and re assess things.

project wiki: containing basic information of the overall project. I will be updating it more frequently throughout 0.2 and 0.3.


  • 0.1: Bug #226
    While researching my first initial processing.js bug, I noticed when there was a comment // inside a character string, the parser would be happy to remove it, which is only the beginning. If there is ANYTHING inside a string that resembled code or keywords, it would break. the parser would grab the keyword, and change it to javasctipt. For example:

    text("int i = 0;", 0, 15);

    would then be parsed to:

    text("var i = 0;", 0, 15);

    After noticing this, I went right to the bug tracking system and found this. The bug I, myself just found. So, I’m going to complete that for my 0.1. I will also implement automated test cases for it.
  • 0.2: Bugs #133 and #230.
    These have been bumped to 0.2 from 0.1. I will also do automated test cases for these too.
  • 0.3: TBD.
    I hope with the experience I have gained, I can do three bugs, and implement automated test cases for them as well.

I’ve got down the process involved in doing this, and I hope to start back on 0.2 as soon as possible, Monday at the latest. It’s best to start small, and start early. This stuff is not something that, for me, can always be accomplished in one night.

Scott 1 : Firefox 0… 10

Posted in open source on February 19, 2010 by scottdowne

The Problem
Alright, I’ve been messing around with Firefox as described in two previous posts, here and here. Trying to make new tabs load your homepage.

The Solution
I got a solution that works perfectly (assuming you don’t mind alerts popping up while browsing…).

First, a HUGE thanks to Benjamin Huang and his post.

What I did was:
In tabbrowser.xml. Note, my copy is a slightly different version.

var blank = !aURI || (aURI == "about:blank");

if ( blank && confirm("would you like to load your homepage?")) {
aURI = gHomeButton.getHomePage();
blank = false;

I added a the if statement bellow the var blank statement. This made sense to me as it was an easier way to check everything, then if the page is blank (you don’t want the homepage to load when you click on a non new link) it prompts the user to open his/her homepage or not, then set blank to false.

The Conclusion
It’s sooooo easy, it just took me time to get there. And honestly, I don’t know how long it would of taken me to find gHomeButton.getHomePage() on my own, Benjamin Huang and his post are to thank for that one.

I broke Firefox!

Posted in open source on February 19, 2010 by scottdowne

In my last post I attempted to make a simple change to Firefox. Allow an option to select a new tab to open your home page, or a blank page.

I said what I’ve accomplished. I’ve found the spot in the code where a new tab is created, and change it to load anything I wanted based on code hard coded right into the code.

Today, I added a simple confirm box, that asked if you wanted to load your homepage (which at this point was just “”) The box appeared, but the page was no longer loaded. It was not working, so I removed the code I added, and reloaded it again, which broke it more. Now, when I load a new tab, it loads the tab as a blank page with the same address fromthe first page writting in the new tabs address box, and if you chage a new tabs address, and hit enter, the original tab loads that page. I highly doubt this is a desired feature :P.

It’s because when you’re stuck on a problem, you usually have to learn something new to solve it, but it isn’t always what you think it is. For example, first step is to understand the problem, second is to get an idea or some direction for what the solution could be, this is usually an abstract idea of sorts, usually has nothing to do with code, just an idea. Like “If I could do this, or bypass this, it would solve the problem”. Then, you research your solution, see if it’s already been solved by someone, if not, see how it’s done (it’s always possible), implement it (this is the coding part (notice how it’s only one step in the process (for me anyway))), then debug it. This is assuming your idea or solution is the right one, sometimes it’s not, but you still learned loads from dead ends. Anyway, this happens a lot, and can happen in a short period of time, then when you discover an answer, you notice you answered the wrong question. This can break code. You can find later, something you tried that did not work, that you forgot to remove, and it’s breaking the code. This is what I think I did. So now, instead of combing through 2000 lines of code trying to get it to a working state, I’m just going to start again with a fresh build (that’s good practice too, as I learned that when you first clone Firefox, you can specify the name of the directory it will go in, not a big deal, but it’s the little things you learn that are the most fascinating sometimes).

I was recently asked in an interview how I go about solving a problem, and well, I don’t feel like I gave a complete answer as I was not prepared and answered it best and honest as I could on the fly, well, that last paragraph was the whole answer 😛

I’ve been stumped on this homepage part, and on my last blog another student has given me a useful like I’m going to poke around in, see what I turn up. Reading code seems to be the most time consuming process right now.