Monday, December 22, 2008

The join() case for a better select()

Today's bug in JavaScript code: was using the Array's join() function and getting results which did not match the expectations. Turns out, that in a case of sparse array (with missing data at certain indexes) join inserts an empty string. So, considering the code:

var a = ['zero', 'one', 'two'];
a[4] = 'four';

The resulting alert will be «zero:one:two::four».

Duh! To adjust to the behavior I have modified the Ruby-like selector to have the «pack» parameter like in this:

// pack   is truthy: (default) resets indexes, returns new packed array
// pack   is falsy:  preserves indexes, returns new sparse array
// tester is a filtering function. Should accept the array's
//        element and return truthy or falsy.
Array.prototype['select'] = function(pack, tester){
  if (typeof(pack) == 'function') {
    tester = pack;
    pack = true;
  } else if (typeof(tester) != 'function'){
    throw { name: 'ArgumentError', message: 'Function expected. Should accept the array\'s element and return truthy or falsy.' }
  result = [];
  for (i in this) {
    if ( tester(this[i]) ) {
      if (pack) { result.push(this[i]); }
      else      { result[i] = this[i]; };
  return result;

Here are the Firebug runs of the select(...):

>>> [ 1, 2, 3, 4, 5, 6].select( function(e){ return e>3; } )
>>> [ 1, 2, 3, 4, 5, 6].select( false, function(e){ return e>3; } )
>>> [ 1, 2, 3, 4, 5, 6].select( true, function(e){ return e>3; } )

Let me know, if this does not work in IE or others for whatever reason - I have only tested it in Firefox.

read more ...

Thursday, December 18, 2008

JavaScript Meetup Presentation

I will be speaking today at the Chicago's JavaScript Meetup on the topic of "Traps to avoid in JavaScript". The 10-minute talk is for beginners and the slides can be found on the website.

Monday, December 8, 2008

Orphan Works Bill opinion from FSF Compliance Engineer

In October this I have forwarded my opinion (see this post) on the Orphan Works Bill as a question to Free Software Foundation licensing team. Brett Smith from FSF sent me an interesting and detailed answer, which I post here verbatim with his permission:

On Oct 21, 2008, at 11:38 AM, Brett Smith via RT wrote:

[Vlad Didenko - Mon Oct 20 19:22:09 2008]:

The recently passed by Senate "Orphan Works" act got surprisingly little attention from the Open Source community. In my assessment, however, it is guaranteed to reduce the benefits of the Open Source paradigm and put the extra defense burden on individual authors. I am trying raise awareness of the legislations impact on our industry.


Thanks for getting in touch with us to share your views on this bill. At this time, we do not have an official position supporting or opposing the act, and since the corresponding bill in the House did not come to a vote this session (HR5889), it does not seem to be a pressing issue at this time. However, we will continue to watch developments in this area, and will announce any new positions on our web site as appropriate.

In general, we believe that copyright law provides more rights to creators than is socially justified, and we support efforts to lessen its scope. However, we understand your concerns that the particulars of this bill may favor large companies holding many copyrights over individual free software developers. Ultimately, much of the analysis is likely to depend on exactly what does and does not count as a qualifying search under the new act -- which may be difficult to evaluate since it depends on the Register of Copyright's Recommended Practices, which don't exist yet.

I did want to take the time to address a couple of factual issues in your e-mail. First, we at the Free Software Foundation and the GNU project aren't part of the Open Source movement, but the Free Software movement. This movement has been campaigning for computer users' freedom since 1984. We discuss the ethical issues surrounding software development and licensing, and the impact that actions in these areas have on society. The Open Source movement began in 1998 and focuses on promoting the technical and practical advantages provided by Free Software. I encourage you to learn more about the differences and relationship between the two movements at

Second, a copyrighted work would not necessarily be considered orphaned under the new act if the copyright holder passed away. When this happens, the copyright is ordinarily transferred to another party: the original copyright holder could name a recipient in their will, or else the copyright would be held by their heirs. With enough effort, a search to contact the copyright holder should discover this and be able to find the new copyright holders.

I hope this helps you understand our current thinking on this. If you have any questions about this, please feel free to contact me.

Best regards,
Brett Smith
Licensing Compliance Engineer, Free Software Foundation

read more ...

Thursday, November 13, 2008

Autodiscover new pages using the server's directory index

Needed to have website pages listed in a side bar of the main page, when they are created in a certain directory. Wanted to do it without any additional server-side software. jQuery to the rescue.

First, enable the directory autoindex in NGINX. Add this to the nginx.conf:

location /drop_dir/ {
    autoindex on;

Then use the script from here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
    <title>Directory query example</title>
    <script src="js/jquery-1.2.6.pack.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
      $(document).ready(function() {
        $.get( "/drop_dir/", function (data) {
          .each( function(){
            page = $(this).attr('href');
              $('<a>').attr('href', '/drop_dir/' + page ).text( page )
    <style type="text/css" media="screen">
      #examples {
        list-style-type: none;
    <ul id="examples" />

Notice, that URLs starting with dots and question marks are filtered out, and only pages full .html extensions are selected. Adjust to your taste. Needless to say that the there should be no index.html, or similar, file, or the default index file should be de-configured for that directory.

Should not be too hard to adjust for apache, either.

jQuery rules :)

read more ...

Saturday, October 4, 2008

The Accordion Experience

While at the TAE in Boston, I have tried to use the accordion widget «on the spot» to organize my conference notes. I have looked up the Accordion documentation and put the code together. It did not work. After a brief conversation with Richard Worth (thank you, Richard!) it turned out that I did not read well enough into the Accordion's assumptions on the DOM structure. The documentation touches well on the «standard» cases of using lists, but it was unclear on how to use it with structure based on divs, or other elements.

In case it may someone else, here what I now understand:

Accordions being created on a jQuery object. To avoid visual surprises, each element to be made an accordion should have a set of children elements, which will become the accordion's items. E.g.:

<div id="my_accordion">
<script type="text/javascript" charset="utf-8">

My wrong assumption was that anything inside the item's <div> would become content, and a header's text just extracted. However, each item must have exactly two elements - the first one for the header, and the second one for the content. The first element needs to be queryable. The second element apparently does not have to be marked in any special way:

<div class="accordion_item">

With that infrastructure in place it is a simple call to create an accordion (add other options to taste):

$("div#my_accordion").accordion({ header: "h3" });

My next task was to allow all items to be collapsed. Since the application was to allow for easy reading of the conference notes, I wanted the items to collapse, when clicked on the active item's header, so the whole list of sessions can be reviewed. That is done with the «alwaysOpen: false» parameter, while the «active: false» parameter creates the accordion initially closed:

  active:     false,
  alwaysOpen: false,
  autoHeight: false,
  header:     "h3"

Hope that helps someone dealing with the Accordion widget the first time.

read more ...

Friday, October 3, 2008

An Opinion on «Shawn Bentley Orphan Works Act of 2008» - open source application

As far as I know, the only way to punish for an open-source copyright infringement is via punitive damages. The owners of an infringed copyright, who opted for open-source licensing, quite often are innovative hobbyists and simply have no money to carry the legal burden unless there is a possibility of punitive damages to pay for lawyers to work on their cases. The legislation specifically removes the only way for this community to survive.

The open source licenses' value is not in a direct monetary gain for the owner, but in secured return flow of value back to the community. Such a value is impossible to express in terms of «reasonable compensation», which is the only dispute remedy suggested by the legislation. So what an abuser is going to pay, when caught? Nothing, and keep using the software? There is nothing in the bill, which upholds the licenses, set by copyright owners. If fact, the way I read it is it designed to disregard the license, if an infringing side made it look like acting in a good faith.

Open source software from individuals or small groups will have no protection and way to enforce the return flow of value. That creates an extremely lucrative ground for copyright abuse. Especially for large companies, which have a history of strong-arming and taking advantage of creative individuals.

Imagine that a copyright owner of an open-source/creative commons work of art or software deceases. Does that mean, that anyone can do whatever with his/her work? Is the license considered unenforceable anymore? If the author is not to be found does that mean, that improvements to a piece of open-source software no longer have to be returned to the community?

Please, help to DO SOMETHING about this awful development. Please, write your congressman its a public disservice legislation. Tell your friends and co-workers. Blog about it. Anything.

Thank you!

read more ...

Saturday, September 27, 2008

Orphan Works Bill

I just wrote to my Congressman to oppose the Orphan Works Bill. The bill has passed Senate yesterday, and the next step for it is to go to the House Judiciary Committee. The discussion of the bill can be found at the sites:

Please go to the form and do the same. It takes two minutes. The mail form is kindly provided by the Illustrators Partnership of America

Thank you for your action!

Tuesday, September 2, 2008

Open Finder from Terminal

Sometimes needed to be able to open a Finder window right where I an at the terminal prompt. Just realized, this is done by a simple:

open .

One of those «why-did-it-take-me-so-long-to-get-it» revelations.

Wednesday, August 27, 2008

Thoughts on «free» photography.

The impact of wide-spread amateur photography on the professionals is something I was often wondering about. Being an amateur, I have by never grasped fully. When participated at a photo trip I once asked the group leader about the issue and got the polite "it's-not-such-a-big-problem-keep-shooting" kind of answer. What else would I expect, being a customer at the moment?

Some more revealing reading was provided in David Ziser's post Digital ProTalk: They Want Free Pics, And I Hate It, and linked materials, which got me thinking further. Why is that the photo community seems to take the topic in a very heated way, while the whole industry is completely oblivious to the self-made YouTube videos (no, I am not talking about the pirated ones).

There are two issues at stake. One is a freebie mentality. Bad thing. I recently got a chance to experience the feeling how hard it is to be positive and constructive, when someone tells you - «let me profit at your expense». When a new National Geographic Expeditions came out with the announcement of the “My Shot” photo contest, I got excited. Then I read T&C. And got disgusted. This is an agency, which understands the media so well, which knows the feeling of proud and ownership a photographer has, when a great photo turns out. Why would they be so rude to, effectively, tell people to just be happy to post, we own it now? As I experienced, authors want to share, not be robbed.

The second issue is a market squeeze. What is perceived, is that free (as in beer) materials from amateurs getting of an acceptable quality/price = value for customers. I know, I shot for the local Boy Scouts. They won't hire a pro. I am OK with donating them the images. It's a mutual agreement. Even if they would hire a pro for an important event, but instead got satisfied with a lesser quality amateur images - it's OK. They are not likely to appreciate the pro quality and would constantly go back to the cost in their minds.

An interesting input into the issue was provided by the same «My Shot» contest. There were OK pictures. There were good pictures. There were declared winners. There was not a single great picture. Nobody posted a real winner on their T&C. And there is no «My Shot» anymore - it folded. I guess, the for-free quality acquisition did not happen. Even with the NG name attached.

So what would we need to keep the art healthy?

  • License awareness. A mandatory meta tag needed to reference one of established licenses. Copyright tag currently gets unstructured text, so it is useless for automatic checking of the license conditions. I think it is a ripe time to come up with a license data structure.
  • Vocabulary of license conditions. Like at, terms need o be defined, so that licenses can be formalized and put inside images. Creative Commons is a great effort, but a narrow legal application for the photography market.
  • Image signature. Image and it's license should be verifiable together.

The three items will lay the ground for simplified dispute resolution in the situations of slackly employees and honest mistakes. That will raise the society awareness and free resources to go after mindful thieves.

I assume, that the words easy and affordable will come to mind of any collaboration implementing these. I also hope to have some more time to give this more thought.

read more ...

Friday, April 4, 2008

Peers value

Just had a thought, that religious communities have a financially encouraged role of morale and ethic educators, watchdogs and maintainers. Quite often all given as a same priest for a given community. In agnostic environments such roles are volunteer, peer, or relative based. As such, they often lack professionalism and continuation, but provide diversity and make ochlocracy less possible.