<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>waelchatila.com - Web category</title>
  <link>http://waelchatila.com:80/categories/web/</link>
  <description>Notes on Software, Engineering and Science</description>
  <language>en</language>
  <copyright>Wael Chatila</copyright>
  <lastBuildDate>Thu, 11 Mar 2010 03:23:48 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Turn your roomba into a walking google bot </title>
    <link>http://waelchatila.com:80/2010/03/01/1267514760000.html</link>
    
      
        <description>
          When my latest son was born I got a little worried since he didn&#039;t look at all like me. I decided I needed a discrete device to spy on my wife while I was at work. I started hacking my roomba and made a  &lt;b&gt;G&amp;#229;&amp;#229;gleBot&lt;/b&gt; (pronounced &lt;i&gt;/google-bot/&lt;/i&gt;). G&amp;#229;&amp;#229;gleBot is a &#034;home crawler&#034; consisting of a vacuum roomba with an on board webserver and camera.
        While the vacuum goes about its business, it extracts text from the images it takes.
        The text is later put in a database on the roomba and searchable through a web interface. This was a good pretext for my wife. I, of course, also added the ability to remote control the roomba using AJAX...for spying purposes...hehe.

&lt;br/&gt;
&lt;a href=&#034;http://www.gaaglebot.com&#034;&gt;&lt;img src=&#034;http://www.gaaglebot.com/building/r2.jpg&#034; alt=&#034;GaagleBot&#034;/&gt;&lt;/a&gt;
&lt;br/&gt;
I created a dedicated site for the little fellow for fun with showcase app. &lt;a href=&#034;http://www.gaaglebot.com&#034;&gt;http://www.GaagleBot.com&lt;/a&gt;
&lt;br/&gt;
&lt;br/&gt;
This is the next version of &lt;a href=&#034;http://waelchatila.com/2006/07/13/1152788433678.html&#034;&gt;My AJAX Lego Robot&lt;/a&gt;.
I&#039;m working on yet another version of my AJAX Remote Controlled thingies...stay tuned.
        </description>
      
      
    
    
    
    <category>AJAX</category>
    
    <category>Hardware</category>
    
    <category>Java</category>
    
    <category>Games &amp; Fun</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2010/03/01/1267514760000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2010/03/01/1267514760000.html</guid>
    <pubDate>Tue, 02 Mar 2010 07:26:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Running Jetty as Non Root</title>
    <link>http://waelchatila.com:80/2009/01/20/1232522160000.html</link>
    
      
        <description>
          I&#039;m kicking the tires of Jetty and am in the process of setting it up on a production machine and found that the latest Jetty realeas (6.1.14) has a really easy way to start jetty out running as root and later switch to a uid of your choice which enables you to open up server sockets on the privileged ports 80 &amp; 443. See the README file under {jetty.root}/extras/setuid. The process is just a one-liner...well, there are some more perks as you&#039;ll see at the end.
&lt;p&gt;
The README seems little bit out of date as my
&lt;div class=&#034;codeSample&#034;&gt;mvn install&lt;/div&gt;
did all of the compiling and copying steps. However, when I try to launch jetty with the new jetty-setuid.xml config file I get the following error.

&lt;div class=&#034;codeSample&#034;&gt;
2009-01-20 23:10:33.887::WARN:  Config error at &amp;lt;Set name=&#034;uid&#034;&amp;gt;jetty&amp;lt;/Set&amp;gt;
2009-01-20 23:10:33.888::WARN:  EXCEPTION
java.lang.reflect.InvocationTargetException
   at java.lang.reflect.Constructor.newInstance(libgcj.so.81)
   at org.mortbay.xml.XmlConfiguration.set(XmlConfiguration.java:405)
   at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:248)
   at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:214)
   at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:974)
   at java.lang.reflect.Method.invoke(libgcj.so.81)
   at org.mortbay.start.Main.invokeMain(Main.java:194)
   at org.mortbay.start.Main.start(Main.java:523)
   at org.mortbay.start.Main.main(Main.java:119)
Caused by: java.lang.NumberFormatException: invalid character at position 1 in jetty
   at java.lang.Integer.parseInt(libgcj.so.81)
   at java.lang.Integer.&amp;lt;init&amp;gt;(libgcj.so.81)
   at java.lang.reflect.Constructor.newInstance(libgcj.so.81)
   ...8 more
&lt;/div&gt;
My jetty-setuid.xml file looks like:
&lt;div class=&#034;codeSample&#034;&gt;
&amp;lt;Configure id=&#034;Server&#034; class=&#034;org.mortbay.setuid.SetUIDServer&#034;&amp;gt;
  &amp;lt;Set name=&#034;startServerAsPrivileged&#034;&amp;gt;false&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;umask&#034;&amp;gt;2&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;uid&#034;&amp;gt;jetty&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;gid&#034;&amp;gt;jetty&amp;lt;/Set&amp;gt;
&amp;lt;/Configure&amp;gt;
&lt;/div&gt;
For some reason its expecting an integer instead of &#034;jetty&#034;...well well
&lt;div class=&#034;codeSample&#034;&gt;
&amp;gt; su jetty
&amp;gt; id
uid=1002(jetty) gid=1003(jetty) groups=1003(jetty)
&lt;/div&gt;
My jetty-setuid.xml now looks like:
&lt;div class=&#034;codeSample&#034;&gt;
&amp;lt;Configure id=&#034;Server&#034; class=&#034;org.mortbay.setuid.SetUIDServer&#034;&amp;gt;
  &amp;lt;Set name=&#034;startServerAsPrivileged&#034;&amp;gt;false&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;umask&#034;&amp;gt;2&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;uid&#034;&amp;gt;1002&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;gid&#034;&amp;gt;1003&amp;lt;/Set&amp;gt;
&amp;lt;/Configure&amp;gt;
&lt;/div&gt;
...works like a charm.
        </description>
      
      
    
    
    
    <category>Unix/Linux</category>
    
    <category>Java</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2009/01/20/1232522160000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2009/01/20/1232522160000.html</guid>
    <pubDate>Wed, 21 Jan 2009 07:16:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Single Table Polymorphic Inheritance with ActiveRecords </title>
    <link>`</link>
    
      
        <description>
          Implementing a single table polymorphic inheritance in rails is dead easy. 

Simply do
&lt;div class=&#034;codeSample&#034;&gt;
class Fruit &lt; ActiveRecord::Migration
  def self.up
    create_table :persons do |t|
      t.column :type :string
      t.column :shape, :string
      t.timestamps
    end

  end

  def self.down
    drop_table :fruits
  end
end
&lt;/div&gt;
or if you a migrating...
&lt;div class=&#034;codeSample&#034;&gt;
class Fruit &lt; ActiveRecord::Migration
    def self.up
        add_column :fruits, :type, :string
    end

    def self.down
        remove_column :fruits, :type
    end
end
&lt;/div&gt;

Now, all you have to do is to create your sub-classes
&lt;div class=&#034;codeSample&#034;&gt;
class Fruit &lt; ActiveRecord::Base
    def calc_volume
       ...
    end
end

class Apple &lt; Fruit
    def calc_volume
       ...
    end
end

&lt;/div&gt;

Don&#039;t forget to put &lt;i&gt;Apple&lt;/i&gt; in a separate file by itself &lt;i&gt;apple.rb&lt;/i&gt; or else ruby will spit out an unconditional warning if you reference &lt;i&gt;Apple&lt;/i&gt; in your code with &lt;i&gt;Fruit::Apple&lt;/i&gt;
&lt;div class=&#034;codeSample&#034;&gt;
warning: toplevel constant Fruit referenced by Fruit::Apple

&lt;/div&gt;
&lt;p&gt;&lt;a href=&#034;`&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2008/05/22/1211520420000.html#comments</comments>
    <guid isPermaLink="true">`</guid>
    <pubDate>Fri, 23 May 2008 05:27:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Internet Explorer 6 &amp; 7 document.domain bug</title>
    <link>http://waelchatila.com:80/2007/10/31/1193851500000.html</link>
    
      
        <description>
          &lt;b&gt;Disclaimer:&lt;/b&gt; Im not sure this a bug discovery...couldn&#039;t find anything that resembled it after a couple of minutes of googling, or a super silly security restriction.
&lt;p&gt;
I&#039;ve been coding some javascript ajax code that inserts an iframe, and into the created iframe, inserts a form and submits the form to a (cross domain) server. This is an old cross-domain ajax technique by now, but while implementing it I came across this ridiculously annoying bug in IE. The line in red below will result in an &#034;Access Denied&#034; exception being thrown...again, only in IE. Tried this with IE6 under WinXP Media Center Edition SP2, IE7 under WinXP Home Edition SP2, and IE7 Windows Vista Home. Needless to say...it works just fine in FireFox.

&lt;div class=&#034;codeSample&#034;&gt;
&amp;lt;script type=&#034;text/javascript&#034;&amp;gt;
  document.domain = &#039;waelchatila.com&#039;;
  var new_html = &#039;&amp;lt;iframe id=&#034;frm&#034; name=&#034;frm&#034; src=&#034;http://waelchatila.com&#034;&amp;gt;&amp;lt;/iframe&amp;gt;&#039;;
  document.body.innerHTML+=new_html;
  try {
    var iframe_doc = &lt;font color=&#034;red&#034;&gt;document.getElementById(&#034;frm&#034;).contentWindow.document;&lt;/font&gt;
  } catch (e) {
    alert(e);
  }
&amp;lt;/script&amp;gt;
&lt;/div&gt;
&lt;div id=&#034;frm1&#034;&gt;&lt;/div&gt;
&lt;script type=&#034;text/javascript&#034;&gt;
function insertIframe() {
        document.domain = &#039;waelchatila.com&#039;;
            var new_html = &#039;&lt;iframe id=&#034;frm&#034; name=&#034;frm&#034; src=&#034;http://waelchatila.com&#034;&gt;&lt;/iframe&gt;&#039;;
            document.getElementById(&#039;frm1&#039;).innerHTML+=new_html;
var bError = false;
try {
 var iframe_doc = document.getElementById(&#034;frm&#034;).contentWindow.document;
} catch (e) {
   bError = true;
}
alert(bError?&#034;Exception thrown&#034;:&#034;No exceptions thrown&#034;);
}
    &lt;/script&gt;


Try it by clicking the button below. &lt;p&gt;
&lt;button onclick=&#034;insertIframe();return false;&#034;&gt;Try it!&lt;/button&gt;
&lt;p&gt;
This page should be served off of &lt;i&gt;http://waelchatila.com&lt;/i&gt;. As you can see, the document.domain is explicitly set to the domain the page was served from. The iframe src is also from the same server. I&#039;ve tried it with a whole variety of variations, none of the demonstrated here but tested for.
&lt;ul&gt;
&lt;li&gt;iframe&#039;s document.domain = &#039;waelchatila.com&#039;;&lt;/li&gt;
&lt;li&gt;iframe src is empty&lt;/li&gt;
&lt;li&gt;iframe src is &#034;javascript:false&#034;&lt;/li&gt;
&lt;/ul&gt;
There should be no problem accessing the iframe&#039;s content in either case. 
&lt;p&gt;Now, if the &lt;i&gt;document.domain = &#039;waelchatila.com&#039;;&lt;/i&gt; line is removed, it works. In order for this to work, you&#039;ll need to reload this page if you clicked the previous button since document.domain has now already been assigned.

&lt;p&gt;
&lt;div id=&#034;frm2&#034;&gt;&lt;/div&gt;
&lt;script type=&#034;text/javascript&#034;&gt;
function insertIframe2() {
            var new_html = &#039;&lt;iframe id=&#034;frm&#034; name=&#034;frm&#034; src=&#034;http://waelchatila.com&#034;&gt;&lt;/iframe&gt;&#039;;
            document.getElementById(&#039;frm2&#039;).innerHTML+=new_html;
var bError = false;
try {
 var iframe_doc = document.getElementById(&#034;frm&#034;).contentWindow.document;
} catch (e) {
   bError = true;
}
alert(bError?&#034;Exception thrown&#034;:&#034;No exceptions thrown&#034;);
}
    &lt;/script&gt;


&lt;button onclick=&#034;insertIframe2();return false;&#034;&gt;Try it!&lt;/button&gt;
&lt;p&gt;
The same results present itself if the iframe is created with &lt;i&gt;document.createElement(&#039;iframe&#039;)&lt;/i&gt; and &lt;i&gt;document.appendChild(...)&lt;/i&gt;
&lt;p&gt;
I&#039;ve yet to find a workaround for this issue. I&#039;ll be positing another entry if I found out how. Please let me know if you know of one!
        </description>
      
      
    
    
    
    <category>AJAX</category>
    
    <category>Windows</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2007/10/31/1193851500000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2007/10/31/1193851500000.html</guid>
    <pubDate>Wed, 31 Oct 2007 17:25:00 GMT</pubDate>
  </item>
  
  <item>
    <title>DisplayTag Paging</title>
    <link>http://waelchatila.com:80/2006/11/07/1162942661799.html</link>
    
      
      
        <description>
          &lt;a href=&#034;http://displaytag.sourceforge.net&#034;&gt;DisplayTag&lt;/a&gt; is a very versatile jsp tag library. It provides a whole lot for free. Paging, sorting, even / odd highlighting, grouping, exporting to PDF, Excel, CSV, XML, just to mention a few things it can do.  &lt;br /&gt;
I use it in pretty much every project. However, I&#039;ve yet to see a built in way to keep track of which page you were at last. In this blog entry I explain one general way to get around this limitation.&lt;p&gt;&lt;a href=&#034;http://waelchatila.com:80/2006/11/07/1162942661799.html&#034;&gt;Read more...&lt;/a&gt;&lt;/p&gt;
          &lt;p&gt;&lt;a href="http://waelchatila.com:80/2006/11/07/1162942661799.html"&gt;Read more...&lt;/a&gt;&lt;/p&gt;
        </description>
      
    
    
    
    <category>Java</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2006/11/07/1162942661799.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2006/11/07/1162942661799.html</guid>
    <pubDate>Tue, 07 Nov 2006 23:37:41 GMT</pubDate>
  </item>
  
  </channel>
</rss>
