Archive: May 15, 2007

<<< May 13, 2007

Home

May 16, 2007 >>>


Exporting IP

Tuesday,  05/15/07  08:10 PM

Every once in a while you read something that manages to get just about everything wrong.  And so it is with a recent column in the New Yorker entitled Exporting IP, by James Surowiecki.  You may read the article here.

<rant>

As with most New Yorker columns, the thesis is that the U.S. Government is doing something wrong.  And they are, but in keeping with the general theme of getting things wrong, the article gets the wrong part wrong. 

The article starts by observing that in recent trade negotiations, the U.S. has required trade partners to commit to rewriting their IP laws to be more like U.S. laws.  The article defines "IP" as "Intellectual Property, patents, copyrights, and so on...", without making a distinction.  Unfortunate, that, since there is a huge difference between patents and copyrights.  The article goes on to ask "why does the U.S. insist on these rules?  Quite simply, American drug, software, and media companies are furious about he pirating of their products, and eager to extent the monopolies that their patents and copyrights confer."  The link between companies and the government is not defined; this might be the only time ever that the New Yorker has assumed the U.S. Government is doing something others want, instead of having some nefarious agenda of their own.

So about these "monopolies"?  It isn't clear that strong IP laws deter piracy in any case, but while patents defend ideas, and hence do enforce monopolies (and hence have very little to do with piracy), copyrights defend works, and hence do not enforce monopolies (and have a great deal to do with piracy).  Ah, little details.

Next up is this rather astonishing statement: "Intellectual property rules are clearly necessary to spur innovation".  Clearly?  In what universe?  Far from spurring innovation, our patent laws deter innovation.  The article immediately contradicts itself by noting "too much protection can strangle competition"; yeah, it can.

There is a teter-totter here, it isn't that IP law is either bad or good, but that some is bad and some is good.  Patents - giving entities ownership over ideas - are bad.  Copyrights - giving entities ownership of work products - are good.  Too much patent law = strangling, too little copyright law = piracy.

Finally the article notes "the U.S. in its negotiations insists on a one-size-fits-all approach... but accepting a diverse range of IP rules makes more sense, in light of the different economic challenges that developing countries face".  Well maybe it makes more sense to some, but not to me; consistency of property protection seems like one of the things that helps developing countries to develop.  I would not put anything in the way of ideas in any country, that would seem to encourage innovation everywhere, while ensuring protection of work products in all countries would seem to encourage entrepreneurs to do something with their ideas.

</rant>

 

 

dynamic page sizing

Tuesday,  05/15/07  09:29 PM

This is a nerdy exposition, for those of you creating web apps and for me to be able to find it later :)

The subject is dynamically sizing web page elements based on the size of the browser window.  Usually when you are creating a web page on a server, you don’t know the size of the user’s browser window.  At the highest level, there are three things you can do, first, you can create pages which work no matter what, second, you can have the page tell the server the size of the window, and regenerate the page accordingly, or third, you can have JavaScript in the page which dynamically reconfigures the page contents.

The first solution is the best if you can get away with it, and this is what the vast majority of websites do today.  Most web content distributes itself in a reasonable way inside a browser window, regardless of the size of the window.  However there are cases where you really want to know the size – for example, you might have an array of thumbnails and you want the number of columns in the array to correspond to the width of the browser window.

The second solution works, but it is a bit klunky.  It requires that the page be generated with a URL which gives the browser window size.  If the browser’s window size changes, then you use an “onresize” event to send a new URL to the server, which generates a new page and sends it to the browser.  The advantage is that you can have all the logic for page generation on the server.  The disadvantage is that you have uglier URLs (not really a big deal), and you have to have an interaction with the server every time the page is resized (also not really a big deal).  There is one situation where this doesn’t work at all – when there is no server!  For example you may be creating pages for a stand-alone DVD.  In this situation all the logic for dynamic sizing must be done on the client.

The third solution is cleanest and accommodates the situation where there is no server.  However there is more complexity on the client side because of the JavaScript, so it may not always be the simplest solution.  The remainder of this email describes how this works.


Okay, let’s say you have a web page, and you want to dynamically adjust the content based on the browser window size.  How do you do this?

Well, first a brief digression into some JavaScript basics.  JavaScript can be embedded into any web page with <script> tags, like this:

      <script>
      ...a bunch of JavaScript code...
      </script>

You can also embed brief sections inline, like this:

      ...HTML stuff<script>...some JavaScript code...</script>more HTML stuff...

Wherever you put the <script> tags, the JavaScript inside will be executed “immediately”.

One of the powerful things you can do with JavaScript is you can output HTML.  You do this with the document.write() function.  The output of the document.write() goes right inline where the HTML is being processed.  For example:

      ...HTML stuff<script>document.write('HTML to be inserted')</script>more HTML stuff...

In this example “HTML to be inserted” will be inserted inline into the HTML.  This HTML can include tags, text, anything.  Here’s a little more complicated example:

<script>
function setfont(color)
{
document.write('<font size=5 color='+color+'>');
}
</script>

...

...<script>setfont('red')</script>this will be red</font>...

In this example we’ve defined a JavaScript function called setfont, which outputs an HTML font tag, using a color passed in as a parameter.  In the HTML the setfont function is called with a parameter of “red”, causing “<font size=5 color=red>” to be written inline into the HTML.

Okay, so that’s a bit about JavaScript.

Next, in order to do conditional stuff based on the size of the browser window, we have to know the size of the browser window.  So, how do we know that?  Well, here’s some JavaScript which figures it out…

<script>
var   width, height;

if (navigator.appName == "Microsoft Internet Explorer") {
      width = document.body.clientWidth;
      height = document.body.clientHeight;
} else {
      width = window.innerWidth;
      height = window.innerHeight;
}
</script>

This JavaScript code sets the variables width and height to the dimensions of the browser window in pixels.  (This finds the dimensions of the inside client area of the browser window, not including menu bars, status bars, borders, etc.  If the page content grows scroll bars, the scroll bars will be inside this area.)  You will note that the logic is slightly different depending on whether you are running in Internet Explorer or anything else.  There is a simple rule that applies to browsers, all browsers behave the same except Internet Explorer.  Unfortunately about 80% of the world uses Internet Explorer, so you have deal with two cases, Internet Explorer and everything else.  Thank you Microsoft.

So now that we know the width and height, how can we do something cool?  Well as an example, consider that table of image thumbnails.  The table has a certain number of columns, but the number will depend on the width of the browser window.  So you can do something like this:

<script>
var   width, height;

if (navigator.appName == "Microsoft Internet Explorer") {
      width = document.body.clientWidth;
      height = document.body.clientHeight;
} else {
      width = window.innerWidth;
      height = window.innerHeight;
}

var   col = 0;

function chkEOL()
{
if (col % parseInt(width / 200) == 0)
      document.write('</tr><tr>');
col = col+1;
}
</script>

...

<table...>
<tr>
<script>chkEOL()</script>
<td>...HTML to create first thumbnail...</td>
<script>chkEOL()</script>
<td>...HTML to create second thumbnail...</td>
<script>chkEOL()</script>
<td>...HTML to create third thumbnail...</td>
<script>chkEOL()</script>
<td>...HTML to create fourth thumbnail...</td>
...
</tr>
</table>

Okay, here’s what’s going on.  First, at the top we figure out the width and height of the browser window as before.  Then, a little function named chkEOL is defined.  Further down is the table itself.  It consists of a whole bunch of <td>…</td> sequences to generate the cells of the table for each thumbnail.  In between each cell is a JavaScript call to chkEOL.  This function uses a global variable named col to keep track of the current column number.  On each call it checks to see if the current column is an even multiple of “width / 200”, and if so it generates a “</tr><tr>” sequence to end the current row and start the next one.  This assumes that the columns are about 200 pixels wide, so if the browser window was 850 pixels wide, there would be four columns, and if the browser window was 1080 pixels wide, there would be five columns.  You could compute the column width instead of hard-coding 200, you get the idea.

Okay, so the main idea is that wherever you might want to generate some HTML dynamically, you make a JavaScript function call, and in the function you check to see what to do, and you can output HTML with document.write().

So this is great, it takes care of the initial layout of the page.  But what happens if the window is resized?  How do we handle that?  Well, it is amazingly easy.  Do this:

<body ... onresize='location.href=location.href'>

In the <body> tag, force a refresh of the page whenever the browser window is resized.  Setting location.href to itself is a portable way to force a refresh.  This causes everything to be reevaluated, and all the JavaScript will be reexecuted again, possibly yielding different results this time because the browser window size has changed.

Happy coding!

 

Tuesday,  05/15/07  10:00 PM

Ah yes, the ol' Ole filter makes a pass...

The Floyd Landis hearings are underway not far from me, at Pepperdine Malibu.  A three-member arbitration board will decide his fate.  See Velonews for great ongoing coverage.  So far after two days, it seems both sides have landed a few punches but no knockouts (except for a French interpreter who couldn't, er, interpret French). 

The Smithsonian asks "what happens when you mix evolution with climate change?", and answers Species Explosion.  "Already this year researchers have announced the discovery of a bunch of new species: 6 types of bats, 15 soft corals, thousands of mollusks and 20 sharks and rays, to name a few."  (One of the newcomers is Hortle's whipray, shown at right.)  So be it.  [ via Jason Kottke

Apropos my rant regarding Exporting IP, ArsTechnica reports piracy rate in China down 10 percent.  Good news, shows you what a little capitalism will do, eh? 

So, the Treo 755p is available from Sprint.  Decisions, decisions... 

Michael Arrington introduces Bringo!  "Here's how it works: 1. Find the company you'd like to call.  2. Enter your phone#.  3. Wait a few seconds while we navigate the phone tree.  4. When we call you back, pick up your phone and you're done. No more phone trees." I have no idea about the business model (is there one?) but I have no doubt about the usefulness.  Neener neener to all those companies that don't believe humans should answer their phones. 

This is amazing - the SkyscraperPage!  Diagrams of all the biggest buildings in the world, with all kinds of architectural detail.  The nine tallest skyscrapers in the world are shown at right; click for larger pic.  The website is nearly as amazing as the drawings, which are nearly as amazing as the buildings themselves...  Proof that you can find everything on the Internet, and everything is so much more than you ever thought. 

The World Atlas has the highest lowest smallest tallest deepest oldest youngest Continents Countries Cities etc.  Really excellent information.  Remember when you were a kid, and you needed to look this stuff up in encyclopedias and things?  Man was that tough.  Now you just Google and poof! there it is... 

And going right along with that, here we have Unusual Hotels of the World.  Everything from underwater to boats, igloos, farms, castles, lighthouses, you name it.  Even prisons and treehouses :)  The picture at left shows Dog Bark Park, a unique two-storey beagle in Cottonwood, ID.  Check them out by WOW rating... 

The Earth Album has stunning photos of the world superimposed over Google Maps, such as the Blue Mosque, in Afghanistan (shown at right).  Travel around and watch the pretty pictures, without leaving the comfort of your keyboard. 

This has to be one of the most beautiful buildings in the world: the Palacio de las Artes Reina Sofia, in Valencia, Spain.  The HDR picture from Salvador del Saz is pretty awesome, too. 

And here are some more amazing aerial shots, from a Russian photographer.  I can't read the site but I sure can admire the pictures.  You have to click through to see these!  (I love all the Russian comments and ads, too; there is a whole world out there which doesn't speak English, and it is great to be reminded once in a while...) 

 

 

(New Yorker, 5/13/07)

Tuesday,  05/15/07  11:10 PM

 


 
 

Return to the archive.