Archive for April, 2008

Mozilla Firefox beta is internet-life

Syncing FireFox bookmarks with .Mac

FireFox is a much more powerful and expandable browser than Safari . It’s a no brainer to make the swap from Safari or Internet Explorer. Abandoning Safari for FireFox left me missing only one thing- iSync. A big of googling lead me to a solution that allowed me to continue to sync my bookmarks across multiple machines (pc and macs) using .Mac’s WebDAV. Here’s how to set your Firefox to sync bookmarks through .Mac …

Removing Safari from your internet life is a breeze. Download the latest FireFox and install. The next step is to get your Safari bookmarks out of Safari and into FireFox. Safari Bookmark Exporter will let you export your Safari bookmarks into a file that’s easily importable by FireFox.

Once your bookmarks are moved over, you’ll need to setup FireFox for bookmark synchronization. FireFox has the ability to run extensions- which in essence are plugins by third party developers that provide added functionality to the core application.

Install the Bookmarks Synchronizer (0.9.6) extension. Firefox will need to be restarted for the extension to be activated.

bookmark_sync2
Once restarted, open the Extension window from the Tools menu (FireFox: Tools > Extensions). You should see Bookmarks Synchronizer listed as one of your Extensions. (I’ve installed few additional Extensions that will not show up in your window. Bookmarks Synchronizer is highlighted.)

On the right hand side, the (i) icon spawns the Bookmarks Synchronizer config window

Assuming you have a functioning .Mac account, configuration is a snap. Set Remote File Settings to HTTP. This will allow you to use .Mac’s WebDAV for uploading and downloading your FireFox bookmarks. WebDAV a protocol for saving and editing files on remote servers. All the functions of iDisk that you use in the Finder are handled through WebDAV.

Here’s how to configure the Bookmarks Synchronizer settings to use dotMac:

bookmark_sync1

Host: idisk.mac.com User: DotMacUser Password: DotMacPassword Path: /DotMacUser/Documents/xbel.xml

That’s it. Apply the changes and click the Upload button. If all goes well your FireFox Bookmarks will be uploaded to your iDisk. Configure your additional PCs or Macs the same way- and this time click Download. Once all of your FireFoxes have the same bookmarks, you’re ready for syncing. Whenever you want to sync bookmarks, select Synchronize Bookmarks under the Bookmark menu (FireFox: Bookmarks > Synchronize Bookmarks). Ta-da.

The Synchronize Bookmarks Extension has some bugs, and isn’t perfect. It’s nowhere near as slick a iSync… It does however provide the much missed sync-ability of bookmark files.

Advertisements

April 28, 2008 at 7:15 am Leave a comment

5 Flash Tips: onLoad Event Handler Not Working With loadMovie?

Tip #1: Neat Fix – onLoad Bug
I have heard so many people moan on the many community forums and mailing lists about the onLoad event handler not working with loadMovie and although I have already posted a fix for the problem (www.actionscripts.org/forums/showthread.php3?threadid=13830), I found this very small and functional fix that does the same thing, a while ago on the Flashcoders Mailing List: http://chattyfig.figleaf.com/mailman/htdig/ flashcoders/2002-October/049415.html and so if you see the question, forward people to http://chattyfig.figleaf.com/apache2-default/.

Tip #2: Bug – Sound.loadSound & GetRight
If you have GetRight (www.download.com/GetRight/3000-2071_4-10005533.html) installed on your computer, a download management utility, and you view a Flash movie that attempts to load an mp3 sound file into the Flash Player dynamically using the Sound.loadSound method, GetRight stops the loading of the mp3 file and asks you to choose a location to save the mp3 file on your local computer; whether you choose to download the file or not, Flash still does not load the file into the player, which raises an issue.

GetRight is one of the most, if not the most popular download utility and this is the default behaviour of the program, of course these settings can be changed, by removing the hook for mp3 files but Flash alone cannot do this automatically for you, this is a manual process that viewers of your site will have follow if they want to listen to dynamically loaded sounds on your site…

To fix the problem, I assume that by changing the file extension of your mp3 files to something which is not registered as a download hook in GetRight will do the trick, but of course, if GetRight actually checks the MIME -type of the file instead of using the files extension, then this will not solve the problem. Changing the mime-type is not only a complex process for novices, it will not solve the problem, because the Flash Player will not play the file if its MIME-type is not set to type mp3.

Tip #3: Stage.showMenu
It is all in the name, Stage.showMenu is a Boolean property of the Stage object that defines whether to display the menu or not, when the user right-clicks on your Flash movie.

A boolean value is either true or false, 0 or 1, on or off, the Stage.showMenu value can either be true or false:

true – Show the menu on right-click
false – Down show the menu on right-click

Please bear in mind, that this isn not the answer to all our prayers, when you turn the right-click menu off, the ‘About Flash 6 Player’ and ‘Settings’ options are still displayed, so no, you cant ‘fully’ remove the right-click menu. The actionscript:

//turn off the right-click menu
Stage.showMenu=false;

Tip #4: System.security.allowDomain
This undocumented method grants permission for the specified domain(s) to access objects and variables in the Flash movie that calls the allowDomain command. This property had to be implemented because of the changes made to the Security Sandbox in the Flash 6 Player…

I have two movies, ‘a.swf’ and ‘b.swf’, ‘a.swf’ is located on http://www.flashguru.co.uk server and ‘b.swf’ is located on http://www.macromedia.com server, for ‘a.swf’ to be able to access the contents of ‘b.swf’, ‘b.swf’ has to make a call to the allowDomain command as follows:

System.security.allowDomain(”http://www.flashguru.co.uk”);

The domain can be formatted in numerous ways, the same different formats that the loadVariables, loadVariablesNum, xml.load and loadvars.load methods accept: http://www.domain.com

http://domain.com
domain.com
http://IpAddress

You can pass multiple domains to the method as arguments. This method has been documented in the Macromedia Flash MX ActionScript Dictionary Errata (www.macromedia.com/support/flash/documentation/ flash_mx_errata/flash_mx_errata03.html).

Tip #5: Test Player – System Keys
By default, in the local test player(Control > Test Movie), if you try and press the enter key, to test some code that uses it, your code will not work because the player over-rides the key press as a keyboard shortcut to pause and play the movie, the same goes for the tab key and other important system keys, such as Ctrl, Shift etc… So if you want to test your tabIndexes in the test player, so you can use trace and the debugger, simply select Disable Keyboard Shortcuts from the Control menu (Control > Disable Keyboard Shortcuts) and your code will now recieve the key presses. Saves me a lot of faffing around! Think this is something else I was slow on, these little fine details just fly over my head.

April 28, 2008 at 7:13 am Leave a comment

Will Success, or All That Money From Google, Spoil Firefox?

Only a couple of years ago, Firefox was the little browser that could — an open-source program created by thousands of contributors around the world without the benefit of a giant company like Microsoft to finance it.

Skip to next paragraph

Illustration by James C. Best Jr. /The New York Times

Jeff Carlick/Bloomberg News

Mitchell Baker is the Mozilla Corporation’s chief executive.

Since then, Firefox, which has prospered under the nonprofit Mozilla Foundation, has grown to be the largest rival to Microsoft’s Internet Explorer, with 15 to 20 percent of the browser market worldwide and higher percentages in Europe and among technology devotees. It is the most popular alternative browser since Netscape, with about three times as many users as Apple’s Safari.

Part of Firefox’s appeal was its origins as a nonprofit venture, a people-powered revolution involving the most basic Internet technology, the Web browser. Also, because the core code was open, Firefox could tap into developers’ creativity; they are encouraged to soup up the browser, whether by blocking ads from commercial Web sites, a popular add-on, or by creating “skins” to customize the browser’s appearance.

But in trying to build on this success, the Mozilla Foundation has come to resemble an investor-backed Silicon Valley start-up more than a scrappy collaborative underdog. Siobhan O’Mahony, an assistant professor at the School of Management of the University of California, Davis, calls Mozilla “the first corporate open-source project.”

The foundation has used a for-profit subsidiary, the Mozilla Corporation, to collect tens of millions of dollars in royalties from search engine companies that want prominent placement on the browser. And by collecting that money as a war chest to compete against giants like Microsoft and Apple, the foundation has, at least temporarily, moved away from the typical activities of a nonprofit organization.

“The Mozilla community has been a bit hybrid in terms of integrating public and private investment all along — its history is fairly unique in this respect,” Professor O’Mahony said.

So far, the many contributors to Firefox seem pleased with its financial success. The bigger question is what Mozilla will do with all its money.

According to Mozilla’s 2006 financial records, which were recently released, the foundation had $74 million in assets, the bulk invested in mutual funds and the like, and last year it collected $66 million in revenue. Eighty-five percent of that revenue came from a single source — Google, which has a royalty contract with Firefox.

Despite that ample revenue, the Mozilla Foundation gave away less than $100,000 in grants (according to the audited statement), or $285,000 (according to Mozilla itself), in 2006. In the same year, it paid the corporation’s chief executive, Mitchell Baker, more than $500,000 in salary and benefits. (She is also chairwoman of the foundation.)

Ms. Baker, a lawyer who has worked for Silicon Valley companies since the mid-1990s, said her compensation “is yet another example of Mozilla as a hybrid,” adding that it made her “a poor stepchild, not even,” compared to the leaders of other equally influential Silicon Valley companies.

Ms. Baker says it was the community, not Google’s money, that made Firefox a player in the field. “Mozilla is successful because we have this giant set of people who care about it,” she said. “The fundamental infrastructure piece that keeps Mozilla independent from even a single source of income like Google is the diverse set of people.”

She added: “No amount of money would have allowed us to be as successful as we are.” Then, referring to Microsoft, she said, “We cannot outspend them.”

The rise of Firefox can be seen as an extension of the Netscape-Microsoft battle of the mid-1990s. After Microsoft largely wrested control of the market, Netscape decided in 1998 to release its code to the public, and immediately developers took up the challenge.

By 2003, AOL, which had acquired Netscape, released the browser code to the newly created Mozilla Foundation, and by November 2004, the first version of Firefox was released. At the time, it was promoted as pursuing the goals of being user-friendly, able to work on different operating systems and more secure. The corporation was created in 2005.

The browser’s other, unstated advantage, shared with other open-source projects, was A.B.M.: Anybody but Microsoft.

“Firefox is able to tap many different audiences. Not everyone cares about keeping Web standards open, but a significant part of the contributing population fears that if Firefox loses share, then Web standards could become the purview of Microsoft alone,” Professor O’Mahony wrote in an e-mail message.

Dean Hachamovitch, Microsoft’s general manager for Internet Explorer, noted that the market still showed a marked preference for Explorer, but he did concede that Microsoft, for structural reasons, could not show the enthusiasm Firefox developers have.

“We are much more reserved about thinking out loud as we make the browser better,” he said. “I can go through and talk about all the innovations we have made, but we don’t talk about them until they are done. People make very important decisions based on what Microsoft says; we have a responsibility about what we say out loud.”

Looming over Mozilla’s future, however, is its close connection with Google, which has been writing most of the checks that finance the Firefox project through its royalty contract.

When the connection with Google was revealed more than a year ago, the question on popular tech Web sites like Slashdot.org was whether Mozilla was acting as a proxy in Google’s larger war with Microsoft and others.

The foundation went so far as to directly address the issue, writing recently, “We do not vet our initiatives with Google,” and adding that it made sure that Google “understood the separation between a search relationship and the rest of our activities.”

Yet lately, the concern among Firefox users and developers about the Mozilla-Google relationship focuses more on what would happen if Google were to walk away, create its own browser or back another, like Safari. This discussion of life after Google represents an unexpected twist: the fear is that instead of being a proxy for Google, Mozilla may have become dangerously reliant on it.

Wladimir Palant, a longtime contributor to Firefox and developer of the popular Adblock Plus add-on that removes ads from Web pages, said he was pleased that the foundation had so much money saved up. And while he rattled off a number of priorities that he was glad the foundation had been pursuing, including improving the infrastructure and hiring more staff, he said No. 1 was, “Save some of the money for later.”

He said, “This will keep them independent of market tendencies and companies like Google.” If Google were to make an unreasonable demand, he said, “Mozilla will still have enough time to look for alternative money sources.”

Ms. Baker said that while she tried “to stay away from” that kind of speculation, “I take the view that we are doing something fundamentally important, and as that becomes clear, there could be other entrants.” She added: “Google is on everyone’s mind, but it could come from China, who knows?”

A Google spokeswoman would not comment on any of the issues raised by the Google-Mozilla relationship, but issued a statement: “Mozilla is a valued business partner because many users utilize Firefox to access Google products and services. We will continue to work with a variety of technology providers, including Mozilla, to ensure our mutual users have the best experience possible with our products and services.”

To an outside observer like Tim Wu, a law professor at Columbia who focuses on the Internet, the alliance still makes a lot of sense.

“We’re living in a cold war between open and closed systems, and Google is happy to lend support to entities that it sees as allies,” he said.

While acknowledging that he does not know the secret terms of their contract, he said, by way of analogy, “No one is surprised that Turkey would get aid from the U.S. during the cold war.”

April 28, 2008 at 7:12 am Leave a comment

Why threading is hard

Anybody who says “I can write correct multi threaded code” probably should be saying “I don’t test my multi-threaded code”.

It is very difficult to write correct multi-threaded code.

One way to appreciate this is various “find-the-bug” pop quizzes that occasionally come up.

Another approach that I’ll go after here is to look at the state space.

If single-threaded apps have O[n] execution paths where n = number of atomic operations,  just two threads have O[n!] paths or worse. (It’s not O[n*n], or even polynomial – see below). And n is usually a very large number.

Each of those execution paths is an angle to hit your program and find a bug. Maybe you can test against O[n], but you’re delusional if you think you can protect against O[n!] or worse.

15 is a small number, and 15 factorial is 1,307,674,368,000 = ~1.3 trillion. Testing a million cases is hard enough. “Trillion” may sound like an unrealistic number, but listen to some of the ship-stopper stress bugs that show up in product’s end games followed by the “what are the odds that could ever have actually happened” comments, and it’s not so unrealistic.

Practically, that means multi-threaded apps have so many states that you can’t possibly keep track of them all in your head. And even if you do, the next guy that goes and changes a line of code just ruined your model.

Counting the execution paths

Suppose you have a function that executes sequence of atomic operations:  A0, A1, A2, A3.

I want to just compare single-threaded and multi-threaded cases, so for now, let’s ignore loops, conditionals, etc. because that’s common across both and so it just complicates the comparison. (This simplification actually downplays the complexity of adding additional threads). In this model, there’s only 1 code-path through this sequence of N states: A0, A1, A2, A3.

Now suppose you have a second function B0, B1, B2, B3 executing on another thread.

The threads can interleave these operations in any order. The convenient case would be (A0,A1,A2, A3, … B0,B1,B2,B3). But maybe it’s something goofy like: (A0,A1,B0,A2,B1,B2,A3,B3). If the bug only occurs when the pattern (A1,B0,A2, B1) is executed, good luck finding it.

It turns out for 2 sequences of lengths N and M, there are choose(N+M, N) ways to interleave them. That’s (N+M)! / ( M! N! ) execution paths.  Hence O[n!] for 2 threads.

You can see how much more complex just simple execution gets with threads. Now imagine how much more complicated threads make loops, conditionals, etc.

How many states?

Locks don’t make your code safe. They just reduce the number of states and hedge your bets.  At one extreme, 1 giant lock around everything can reduce you to 1 state per thread. If you put 4 states under 1 big lock (eg, A0…A3), and you put that same lock around every other state (eg, B0…B3), then you’ve reduced those 4 states to 1 state, thus eliminating 3 states.

You likely don’t control the number of states. An operation that appears atomic (like a memory read) may actually be multiple states. Maybe you’re looking at the source-line and the compiler split it out into multiple states. Or maybe there are windows where you communicate with the file-system, or other processes – and so they can be effectively injecting states into your state space. Or maybe the hardware has multiple states (usually around memory models).  That’s why there’s InterlockedIncrement(&i) instead of just doing i++.


Threading vs. Reentrancy
:

Now threading models aren’t the only way to rack up states. Single-threaded models (like UIs) that queue messages can create a ton of states too, and those tend to create nasty reentrancy bugs. And there will be times when another thread would actually produce fewer overall states then a single-threaded model. Just be wary.

What if the states independent from each other?

Granted many of the states may appear to be independent from each other. So one may claim that O[N!] is way to pessimistic. But unless you have a very thorough isolation model, it tough to prove the states can’t impact each other.

For example, states A0 and B1 may not directly interact, but maybe A0 impacts A1 which impacts B0 which impacts B1.  Maybe A0 impacts how much memory A1 allocates, and that impacts whether an allocation in B0 fails (especially if there’s a process wide memory allocator), and then the bug is in B1 handling the out-of-memory failure case.

And even if most of your states actually are isolated, factorial growth is so fast that you only need a small number before you’re doomed.

April 28, 2008 at 7:09 am Leave a comment

Newer Posts


April 2008
M T W T F S S
    Jun »
 123456
78910111213
14151617181920
21222324252627
282930