<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>waelchatila.com</title>
  <link>http://waelchatila.com:80/</link>
  <description>Notes on Software, Engineering and Science</description>
  <language>en</language>
  <copyright>Wael Chatila</copyright>
  <lastBuildDate>Fri, 23 May 2008 05:27:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <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>GreenMail v1.3 Released</title>
    <link>http://waelchatila.com:80/2007/12/19/1198107540000.html</link>
    
      
        <description>
          This release contains minor changes to GreenMail core, most notable the introduction of slf4j for logging.
&lt;p/&gt;
New in this release is a JBoss service for GreenMail.
The service runs GreenMail as a lightweight mail server sandbox, nicely suited for developers.
&lt;p/&gt;
Check out the project page &lt;a href=&#034;http://www.icegreen.com/greenmail&#034;&gt;http://www.icegreen.com/greenmail&lt;/a&gt;
for the latest documentation!
&lt;p/&gt;
Note about the released files (&lt;a href=&#034;http://sourceforge.net/project/showfiles.php?group_id=159695&amp;package_id=179329&amp;release_id=562874&#034;&gt;goto download page&lt;/a&gt;):
&lt;ul&gt;
&lt;li&gt;greenmail-1.3-bundle.jar : mvn upload bundle&lt;br&gt;
&lt;li&gt;greenmail-1.3.jar : contains all greenmail core classes&lt;br&gt;
&lt;li&gt;greenmail-1.3-src.zip : contains sources, javadoc, required libs, docs&lt;br&gt;
&lt;li&gt;greenmail-1.3.zip : like above, but no sources&lt;br&gt;
&lt;li&gt;greenmail-jboss-service-1.3.sar : deployable JBoss service archive&lt;br&gt;
&lt;/ul&gt;
&lt;p/&gt;
&lt;br&gt;
&lt;b&gt;Changes:&lt;/b&gt;&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Added logging via slf4j, replacing System.out.println&lt;br&gt;
&lt;li&gt;Minor improvements:&lt;ul&gt;
  &lt;li&gt;c.i.g.AbstractServer exposes ServerSetup&lt;br&gt;
  &lt;li&gt;c.i.g.util.GreenMailUtil exposes sendTextEmail(...)&lt;br&gt;
&lt;/ul&gt;
&lt;li&gt;New JBoss service wrapper (see the &lt;a href=&#034;http://www.icegreen.com/greenmail&#034;&gt;project page&lt;/a&gt;)&lt;br&gt;
&lt;/ul&gt;
&lt;p/&gt;
&lt;b&gt;Credits:&lt;/b&gt;&lt;br&gt;
Marcel May added the JBoss service and contributed the logging changes. Thanks!&lt;br&gt;
&lt;p/&gt;
&lt;b&gt;Upcoming changes:&lt;/b&gt;&lt;br&gt;
For 1.4 we plan to replace the current Foedus smtp and pop implementation with &lt;a href=&#034;http://subetha.tigris.org&#034; rel=&#034;nofollow&#034;&gt;http://subetha.tigris.org&lt;/a&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://waelchatila.com:80/2007/12/19/1198107540000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2007/12/19/1198107540000.html</guid>
    <pubDate>Wed, 19 Dec 2007 23:39: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 &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>RXTX on Gumstix</title>
    <link>http://waelchatila.com:80/2007/08/24/1187975400000.html</link>
    
      
        <description>
          &lt;p&gt;
Since it could be tricky to get the RXTX sources compiling properly for the gumstix platforms I thought I&#039;d spare anyone the pain by providing my binaries. 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#034;http://www.icegreen.com/rxtx_gumstix/librxtxSerial_PXA255.so&#034;&gt;librxtxSerial_PXA255.so &lt;/a&gt; (Connex / Basix)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#034;http://www.icegreen.com/rxtx_gumstix/librxtxSerial_PXA270.so&#034;&gt;librxtxSerial_PXA270.so &lt;/a&gt; (Verdex)&lt;/li&gt;
&lt;/ul&gt;

However, since you&#039;re here, I would advise against using java on the gum. Sure, the programs themselves are a breeze to develop, but getting jam and classpath to compile and run properly can very well take a considerable amount of time. Just think of the reason why you are reading this. Chances are you probably have troubles getting the RXTX sources to compile or run smoothly. Just do yourself a favor, write it in small fast c/c++ or something.
        </description>
      
      
    
    
    
    <category>Unix/Linux</category>
    
    <comments>http://waelchatila.com:80/2007/08/24/1187975400000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2007/08/24/1187975400000.html</guid>
    <pubDate>Fri, 24 Aug 2007 17:10:00 GMT</pubDate>
  </item>
  
  <item>
    <title>Groovy vs BeanShell</title>
    <link>http://waelchatila.com:80/2007/05/09/1178775480000.html</link>
    
      
        <description>
          Below is a quick and dirty test to compare the speed performance between bean shell and groovy. Bean shell is an order of magnitude faster. If you don&#039;t need groovy closure and other nice groovy features...just use bean shell. It&#039;s only one small jar away.


&lt;div class=&#034;codeSample&#034;&gt;
public static void main(String[] args) throws EvalError {
        StringBuilder script = new StringBuilder();
        for (int i=0;i&lt;900;i++) {
            script.append(&#034;res&#034;);
            script.append(i);
            script.append(&#034;=&#034;);
            script.append(i+&#034;+&#034;+i+&#034;*&#034;+i);
            script.append(&#034;;\n&#034;);
        }
        GroovyShell groovyShell = new GroovyShell();
        Interpreter bsh = new Interpreter();

        long t = System.currentTimeMillis();
        groovyShell.evaluate(script.toString());
        System.out.println(System.currentTimeMillis() - t);

        t = System.currentTimeMillis();
        for (int i=0;i&lt;1000;i++) {
            int j = i+i*i;
        }
        System.out.println(System.currentTimeMillis() - t);

        t = System.currentTimeMillis();
        bsh.eval(script.toString());
        System.out.println(System.currentTimeMillis() - t);

    }
&lt;/div&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://waelchatila.com:80/2007/05/09/1178775480000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2007/05/09/1178775480000.html</guid>
    <pubDate>Thu, 10 May 2007 05:38:00 GMT</pubDate>
  </item>
  
  </channel>
</rss>
