<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Serabe Reloaded &#187; programming</title>
	<atom:link href="http://www.serabe.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.serabe.com</link>
	<description>Conecto ergo sum. Non conecto ergo urgueo.</description>
	<lastBuildDate>Wed, 14 Jul 2010 18:12:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Status update for GeoGebra.</title>
		<link>http://www.serabe.com/2010/07/12/status-update-for-geogebra/</link>
		<comments>http://www.serabe.com/2010/07/12/status-update-for-geogebra/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 20:41:04 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[GeoGebra]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[geogebra]]></category>
		<category><![CDATA[gsoc]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=522</guid>
		<description><![CDATA[My contributions for the first part of the first part of GSoC 2010 can be divided in two: general improvements and coding. General improvements I made a few general improvements on GeoGebra: Refactored build.dir in ant build file. Previously, build.dir wasn&#8217;t in the root directory. A few ant tasks were added, such compile-grammar, compile-oe (outside [...]]]></description>
			<content:encoded><![CDATA[<p>My contributions for the first part of the first part of GSoC 2010 can be divided in two: general improvements and coding.</p>
<h3>General improvements</h3>
<p>I made a few general improvements on GeoGebra:</p>
<ol>
<li>Refactored build.dir in ant build file. Previously, build.dir wasn&#8217;t in the root directory.</li>
<li>A few ant tasks were added, such compile-grammar, compile-oe (outside Eclipse), run-easyb and run-easyb-outside-eclipse.</li>
<li>SVN properties were set in order to work outside Eclipse. This way, .class files will be kept out of the repo without the intervention of any Eclipse plugin.</li>
<li>Easyb, a BDD groovy-based framework, has been included in order to test GeoGebra. It is not RSpec, but I guess it&#8217;ll do.</li>
</ol>
<h3>Coding</h3>
<p>First, I started creating a few <strong>EquationPoint</strong> classes,  currently there are six <strong>EquationPoint </strong>children classes:</p>
<p><a href="http://www.serabe.com/wp-content/uploads/2010/07/Selección_003.png" ><img class="alignnone size-full wp-image-524" title="EquationPoint type hierarchy" src="http://www.serabe.com/wp-content/uploads/2010/07/Selección_003.png" alt="EquationPoint type hierarchy" width="384" height="254" /></a></p>
<ul>
<li><strong>EquationFreePoint</strong> represents an independent point.</li>
<li><strong>EquationSymbolicPoint</strong> represents a dependent point,  <strong>EquationSpecialSymbolicPoint</strong> standing only for the locus point.</li>
<li><strong>EquationNormalPoint</strong> and <strong>EquationPointVectorPoint</strong> are only auxiliar elements.</li>
</ul>
<p>Then, a few <strong>EquationElement</strong> classes were added, these stand for the different constructions:</p>
<p><a href="http://www.serabe.com/wp-content/uploads/2010/07/Selección_001.png" ><img class="alignnone size-full wp-image-525" title="EquationElement type hierarchy" src="http://www.serabe.com/wp-content/uploads/2010/07/Selección_001.png" alt="EquationElement type hierarchy" width="384" height="364" /></a></p>
<p><strong>EquationElement</strong> is an abstract class containing a few basic methods:</p>
<ul>
<li><strong>forPoint</strong>: Given an EquationPoint, returns a String with the equation that means that the point is in the construction.</li>
<li><strong>isAlgebraic</strong>: returns true if the construction is algebraic, and false otherwise.</li>
</ul>
<p>Both <strong>EquationGenericCircle</strong> and <strong>EquationGenericLine</strong> are abstractions of specific line and circle contructions, all of them algebraic. <strong>EquationGenericSegment</strong> is to segment what <strong>EquationGenericLine</strong> is to lines. Obviously, <strong>EquationGenericSegment</strong> is not algebraic.</p>
<p>All of these classes are used together by<strong> EquationScope</strong>.</p>
<h3>A pause for a screenshot.</h3>
<p><a href="http://www.serabe.com/wp-content/uploads/2010/07/Selección_002_modificada.png" ><img title="Screenshot" src="http://www.serabe.com/wp-content/uploads/2010/07/Selección_002_modificada-300x132.png" alt="Screeenshot" width="300" height="132" /></a></p>
<p>Click for enlarge.</p>
<h3>A glimpse into the future.</h3>
<p>What to do next?:</p>
<ul>
<li><span style="text-decoration: line-through;">Maybe Equation should be a proper class, not just a String.</span></li>
<li>More equations.</li>
<li>Working out the locus equation.</li>
<li><span style="text-decoration: line-through;">Not using an algorithm twice.</span></li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2010/07/12/status-update-for-geogebra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing your own JRuby extension. Part II: Creating your first class.</title>
		<link>http://www.serabe.com/2010/03/12/writing-your-own-jruby-extension-part-ii-creating-your-first-class/</link>
		<comments>http://www.serabe.com/2010/03/12/writing-your-own-jruby-extension-part-ii-creating-your-first-class/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 23:06:04 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=481</guid>
		<description><![CDATA[What&#8217;s the point of coding a JRuby extension if you don&#8217;t create classes? Well, I cannot think of any case, but if you find one, please, let me know. Do you remember Java&#8217;s classes hierarchy? If so, you&#8217;ll realize  that Java objects inherit from java.lang.Object by default but that is not actually what we need. [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="nofollow" href="http://www.flickr.com/photos/53326337@N00/3783473433/" title="More Mormon Matryoshki"  target="_blank"><img class="alignright" style="border: 0px initial initial;" src="http://farm4.static.flickr.com/3057/3783473433_98d837343a_m.jpg" border="0" alt="More Mormon Matryoshki" width="240" height="143" title="Writing your own JRuby extension. Part II: Creating your first class." /></a><br />
What&#8217;s the point of coding a JRuby extension if you don&#8217;t create classes? Well, I cannot think of any case, but if you find one, please, let me know.</p>
<p>Do you remember Java&#8217;s classes hierarchy? If so, you&#8217;ll realize  that Java objects inherit from java.lang.Object by default but that is not actually what we need. But how can we tell JRuby that our object inherits from Object, the king of Ruby world? The answer is so simple: just extend RubyObject! (There is a RubyBasicObject too) Taken from Nokogiri::XML::Node:</p>
<p><script src="http://gist.github.com/281421.js"></script></p>
<p>Of course, you can extend any other class, as long as it is a &#8220;Ruby object&#8221;. For example, Nokogiri::XML::Document extends from Nokogiri::XML::Node, and we do not need to do anything special to reflect it, just extend XmlNode like XmlDocument does:</p>
<p><script src="http://gist.github.com/281426.js"></script></p>
<p>After talking a bit about hierarchy, let&#8217;s talk about Java constructors. At least two parameters are needed: a org.jruby.Ruby object and a org.jruby.RubyClass object. Being the importance of the former quite obvious, the reason for the latter may not be so clear. Let me show you some real world code: Nokogiri::XML::Node&#8217;s dup method. Take a look at the following test:</p>
<p><script src="http://gist.github.com/284316.js"></script></p>
<p>Both new and dup methods in subclass rely on Nokogiri::XML::Node&#8217;s. In <a href="http://github.com/tenderlove/nokogiri/blob/master/ext/nokogiri/xml_node.c#L281" >here</a>, you can see the this snippet of code:</p>
<p><script src="http://gist.github.com/284318.js"></script></p>
<p>The <code>rb_obj_class</code> method returns the class of an object, in this case, <em>self</em>. This way, the new node will be an instance of the same class as the original node. That&#8217;s the reason a RubyClass is needed in the constructor, in order to know which is the actual class being instantiated.</p>
<p>By the way, do not forget to call super with the Ruby and RubyClass objects.</p>
<p>Next step: creating methods.</p>
<p><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License"  target="_blank"><img src="http://www.serabe.com/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" title="Writing your own JRuby extension. Part II: Creating your first class." /></a> <a href="http://www.photodropper.com/photos/"  target="_blank">photo</a> credit: <a rel="nofollow" href="http://www.flickr.com/photos/53326337@N00/3783473433/" title="quinn.anya"  target="_blank">quinn.anya</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2010/03/12/writing-your-own-jruby-extension-part-ii-creating-your-first-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Writing your own JRuby extension. First problem.</title>
		<link>http://www.serabe.com/2010/01/11/writing-your-own-jruby-extension-first-problem/</link>
		<comments>http://www.serabe.com/2010/01/11/writing-your-own-jruby-extension-first-problem/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 23:09:22 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[jruby extension tutorial]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=478</guid>
		<description><![CDATA[Maybe, when requiring your just created extension, you get a LoadError. If it is the first time you require it, it is quite likely that you have not followed JRuby requiring conventions. If you want to know how require works, you can find the best documentation ever about it in the comment before org.jruby.runtime.load.LoadService class. [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="nofollow" href="http://www.flickr.com/photos/99909414@N00/3981364314/" title="Denial"  target="_blank"><img class="alignleft" style="border: 0px initial initial;" src="http://farm3.static.flickr.com/2422/3981364314_d4b30cb739_m.jpg" border="0" alt="Denial" width="240" height="159" title="Writing your own JRuby extension. First problem." /></a><br />
Maybe, when requiring your just created extension, you get a LoadError. If it is the first time you require it, it is quite likely that you have not followed JRuby requiring conventions. If you want to know how require works, you can find the best documentation ever about it in the comment before <a href="http://github.com/jruby/jruby/blob/master/src/org/jruby/runtime/load/LoadService.java#L42" title="Github" >org.jruby.runtime.load.LoadService</a> class.</p>
<p><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License"  target="_blank"><img src="http://www.serabe.com/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" title="Writing your own JRuby extension. First problem." /></a> <a href="http://www.photodropper.com/photos/"  target="_blank">photo</a> credit: <a rel="nofollow" href="http://www.flickr.com/photos/99909414@N00/3981364314/" title="cesarastudillo"  target="_blank">cesarastudillo</a></small></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2010/01/11/writing-your-own-jruby-extension-first-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing your own JRuby extension. Part I: BasicLibraryService.</title>
		<link>http://www.serabe.com/2010/01/08/writing-your-own-jruby-extension-part-i/</link>
		<comments>http://www.serabe.com/2010/01/08/writing-your-own-jruby-extension-part-i/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 00:22:44 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[extensions]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=445</guid>
		<description><![CDATA[Note: not code in this post, but you can see the code in Github. Follow the links! Writing a JRuby extension is very easy, but there are almost not post out there about it. As far as I know, there is only one, Ola&#8217;s. It is a really good tutorial indeed, but it lacks some [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note:</strong> not code in this post, but you can see the code in Github. Follow the links!</p>
<p>Writing a JRuby extension is very easy, but there are almost not post out there about it. As far as I know, there is only one, <a rel="nofollow" href="http://ola-bini.blogspot.com/2006/10/jruby-tutorial-4-writing-java.html" title="JRuby Tutorial 4. Ola Bini's blog." >Ola&#8217;s</a>. It is a really good tutorial indeed, but it lacks some details that might be not-that-easy to solve. Please, take some time to read it and, if some details are different, do follow Ola&#8217;s way.</p>
<p>Everything&#8217;s ready now, so let&#8217;s start talking about <a href="http://github.com/jruby/jruby/blob/master/src/org/jruby/runtime/load/BasicLibraryService.java" title="Github" >BasicLibraryService</a>. If you take a look at <a href="http://github.com/tenderlove/nokogiri/tree/java" title="Github repo" >Nokogiri4J sourcecode</a>, in <a href="http://github.com/tenderlove/nokogiri/tree/java/ext/java/nokogiri/" title="Github repo" >ext/java/nokogiri</a> folder, you will see a <a href="http://github.com/tenderlove/nokogiri/blob/java/ext/java/nokogiri/NokogiriService.java" title="Github repo" >NokogiriService.java</a> file. NokogiriService implements <a href="http://github.com/jruby/jruby/blob/master/src/org/jruby/runtime/load/BasicLibraryService.java" title="Github repo" >BasicLibraryService</a>. This interface consists only of the method basicLoad which receives a Ruby object.</p>
<p>We will use this method to define classes and methods in the Ruby world. For defining a module, defineModule method is used with the name of the module. After that, modules and classes under that module can be defined easily by using the methods defineModuleUnder, which takes the name as parameter, and defineClassUnder, which takes the name and few parameters more. Let&#8217;s dive into it.</p>
<p>defineClassUnder needs three arguments. The first one is the class&#8217; name. The second, is the parent class. If you have defined it previously, just passed it,  otherwise use RubyObject by calling the method getObject on the Ruby instance. The third parameter is an ObjectAllocator. ObjectAllocators returns intances of the classes in Java world. When instantiating Nokogiri::XML::Comment in Ruby world, JRuby will ask the ObjectAllocator for an instance of the Java class. It passes a Ruby object and the RubyClass being instantiated to the allocate method in the ObjectAllocator (more on RubyClass in following posts).</p>
<p>Finally, we will need to define some methods. Easiest way is by using the defineAnnotatedMethods. It takes a Java class as parameter. For knowing what this method does, you need to know a bit more about @JRubyMethod annotation (more on it in following post, have you realized the &#8220;Part I&#8221; in the title?). As you define methods, you may need to undefine some in a subclass. So easy! Use the undefineMethod method, which takes the name of the method as parameter (surprisingly, it undefines a method by redefining it!).</p>
<p>Next time, <a href="http://bit.ly/b5vZMp" >Implementing your first class</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2010/01/08/writing-your-own-jruby-extension-part-i/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>If you are (un)happy with Ruby 1.8.7</title>
		<link>http://www.serabe.com/2009/02/12/if-you-are-unhappy-with-ruby-187/</link>
		<comments>http://www.serabe.com/2009/02/12/if-you-are-unhappy-with-ruby-187/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 00:55:33 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[and i really want to show it]]></category>
		<category><![CDATA[i am not happy and i know it]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=341</guid>
		<description><![CDATA[There are two interesting topics in the Ruby Forum being discussed right now. Both opened by George Brown (the guy behind Prawn). They are: If you are happy with the direction of Ruby 1.8.7+, respond If you are unhappy with the direction of Ruby 1.8.7+, respond I&#8217;ve read every single message because backwards compatibility in [...]]]></description>
			<content:encoded><![CDATA[<p>There are two interesting topics in the Ruby Forum being discussed right now. Both opened by George Brown (the guy behind Prawn). They are:</p>
<ul>
<li><a href="http://www.ruby-forum.com/topic/178355" >If you are happy with the direction of Ruby 1.8.7+, respond</a></li>
<li><a href="http://www.ruby-forum.com/topic/178354" >If you are unhappy with the direction of Ruby 1.8.7+, respond</a></li>
</ul>
<p>I&#8217;ve read every single message because backwards compatibility in Ruby 1.8.7 is something that I do not fully understand. It all started with this <a href="http://www.jaimeiniesta.com/2008/11/01/cuidado-con-ubuntu-810-viene-con-ruby-187/#comment-501" >comment</a> in Jaime&#8217;s blog. There, Jaime wondered if Ubuntu did the right thing by updating Ruby to 1.8.7, even if that version breaks rails (in fact, it did). Well, in this case, my humble opinion was yes, Ubuntu did well by updating Ruby. But now, let&#8217;s consider other things.</p>
<p>So far, I&#8217;ve seen two kind of complains against Ruby 1.8.7:</p>
<ul>
<li>Coding working in 1.8.6 that doesn&#8217;t work in 1.8.7. I&#8217;ve been talking James Coglan about it, and the one of the errors was that his code relied on the order of the keys in a hash. But, there are other he hasn&#8217;t been able to fix, and is something regarding regular expression. I am unhappy with this kind of &#8220;new features&#8221;.
<li>
<li>Other people is complaining about working code in 1.8.7 that does not work in 1.8.6. I really understand them, because they program really cool gems and they have to test if they have used not-valid-1.8.6 code. I wouldn&#8217;t care too much about but we must keep in mind that 1.8.7 is a minor release.</li>
</ul>
<p>Finally, I just want to say that, as many people has pointed out before me, it would be better to migrate to 1.9.1. Common! It has been already released! Anyway, that&#8217;s not the point of the discussion. It is all about a minor release with too many changes (I&#8217;m not talking about bugfixes). Do I like the new things? Yes, I do (except some that I cannot really understand). Am I happy with Ruby 1.8.7? No, I&#8217;m not because it is suppose to be a minor version release and it is making too much noise.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2009/02/12/if-you-are-unhappy-with-ruby-187/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problem 3</title>
		<link>http://www.serabe.com/2008/10/12/problem-3/</link>
		<comments>http://www.serabe.com/2008/10/12/problem-3/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 14:13:42 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Maths]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyEuler]]></category>
		<category><![CDATA[euler project]]></category>
		<category><![CDATA[problem 3]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RbEuler]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=259</guid>
		<description><![CDATA[Wording: (Original) The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Solution: First the code: PLAIN TEXT RUBY: include Math def prime_factors&#40;num, factor=2&#41; &#160; return &#91;&#93;&#160; if num &#60;= 1 &#160; next_pf = &#40;factor..&#40;sqrt&#40;num&#41;.ceil&#41;&#41;.find&#40;lambda &#123;num&#125;&#41;&#123; &#124;x&#124; num%x == 0 &#125; &#160; return [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Wording:</strong> (<a href="http://projecteuler.net/index.php?section=problems&#038;id=3"  title="Project Euler">Original</a>) The prime factors of 13195 are 5, 7, 13 and 29.<br />
What is the largest prime factor of the number 600851475143 ?</p>
<p><strong>Solution:</strong><br />
First the code:</p>
<div class="igBar"><span id="lruby-2"><a href="#" onclick="javascript:showPlainTxt('ruby-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-2">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">include</span> Math</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> prime_factors<span style="color:#006600; font-weight:bold;">&#40;</span>num, factor=<span style="color:#006666;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> num &lt;= <span style="color:#006666;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; next_pf = <span style="color:#006600; font-weight:bold;">&#40;</span>factor..<span style="color:#006600; font-weight:bold;">&#40;</span>sqrt<span style="color:#006600; font-weight:bold;">&#40;</span>num<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">ceil</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span>num<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> |x| num%x == <span style="color:#006666;color:#800000;">0</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#91;</span>next_pf<span style="color:#006600; font-weight:bold;">&#93;</span> + prime_factors<span style="color:#006600; font-weight:bold;">&#40;</span>num/next_pf, next_pf<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">puts</span> prime_factors<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">600851475143</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">max</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The code is a direct port from the one in PyEuler. It is based mainly in the idea that the first factor of a number is always prime.</p>
<p>Line 3 breaks recursion and line 4 works out the next prime factor (actually, it finds the smallest factor). For doing this, it uses find method. If no element match the criteria, then it returns the number (that is what the lambda block is for).</p>
<p>Finally, line 5 merges the results and line 8 print the result.</p>
<p>This time just one code is showed.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/10/12/problem-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programmers Jokes.</title>
		<link>http://www.serabe.com/2008/08/29/programmers-jokes/</link>
		<comments>http://www.serabe.com/2008/08/29/programmers-jokes/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 14:53:56 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[GOTAM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[jokes]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=235</guid>
		<description><![CDATA[In C we had to code our own bugs. In C++ we can inherit them. C gives you enough rope to hang yourself. C++ also gives you the tree object to tie it to. With C you can shoot yourself in the leg. With C++ you can reuse the bullet. A computer without COBOL and [...]]]></description>
			<content:encoded><![CDATA[<p>In C we had to code our own bugs. In C++ we can inherit them.</p>
<p>C gives you enough rope to hang yourself. C++ also gives you the tree object to tie it to.</p>
<p>With C you can shoot yourself in the leg. With C++ you can reuse the bullet.</p>
<p>A computer without COBOL and Fortran is like a piece of chocolate cake without ketchup and mustard.</p>
<p>Why all Pascal programmers ask to live in Atlantis?<br />
Because it is below C level.</p>
<p><a href="http://www.workjoke.com/programmers-jokes.html" >Programmers Jokes.</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/08/29/programmers-jokes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hug a developer today.</title>
		<link>http://www.serabe.com/2008/08/28/hug-a-developer-today/</link>
		<comments>http://www.serabe.com/2008/08/28/hug-a-developer-today/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 09:55:23 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Humor]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vÃ­deo]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=232</guid>
		<description><![CDATA[Hug a developer today. They are in pain. At least, I work for a Open Source project, so I have no boss... but me. Anyway, you can hug me if you want . Taken from.]]></description>
			<content:encoded><![CDATA[<p><embed src="http://blip.tv/play/gYwjwZJqjdEh" type="application/x-shockwave-flash" width="640" height="390" allowscriptaccess="always" allowfullscreen="true"></embed> </p>
<p>Hug a developer today. They are in pain. At least, I work for a Open Source project, so I have no boss... but me.</p>
<p>Anyway, you can hug me if you want <img src='http://www.serabe.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' title="Hug a developer today." /> .</p>
<p><a href="http://develop-one.net/blog/2008/08/27/HugADeveloper.aspx" >Taken from</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/08/28/hug-a-developer-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RMagick4J 0.3.6</title>
		<link>http://www.serabe.com/2008/08/16/rmagick4j-036/</link>
		<comments>http://www.serabe.com/2008/08/16/rmagick4j-036/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 23:03:38 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[rmagick4j]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=228</guid>
		<description><![CDATA[I am glad to announce a new version of rmagick4j. RMagick4J aims to implement the ImageMagick funcionality and the C portions of RMagick for make it works in JRuby. Current stable version: 0.3.6 Project URL: http://code.google.com/p/rmagick4j/ Installation: gem install rmagick4j Google Summer of Code project should be thanked for making this new release possible. In [...]]]></description>
			<content:encoded><![CDATA[<p>I am glad to announce a new version of rmagick4j.</p>
<p>RMagick4J aims to implement the ImageMagick funcionality and the C<br />
portions of RMagick for make it works in JRuby.</p>
<p>Current stable version: 0.3.6<br />
Project URL: <a rel="nofollow" href="http://code.google.com/p/rmagick4j/" >http://code.google.com/p/rmagick4j/</a><br />
Installation: <code>gem install rmagick4j</code></p>
<p>Google Summer of Code project should be thanked for making this new<br />
release possible.</p>
<p>In release 0.3.6 you can find the next improvements:</p>
<ul>
<li>More Draw primitives (clip-path [creatin a clip-path and using a<br />
clip-path], fill-rule, rotate, scale [reimplemented], skewX, slewY,<br />
stroke-linecap, stroke-linejoin, stroke-miterlimit, translate).</li>
<li>Solve a bug with transparent stroke and line primitive.</li>
<li> Added the following Draw instance methods:</li>
<ul>
<li>annotate</li>
<li>get_multiline_type_metrics</li>
</ul>
<li>Solved a bug that caused the background become black while resizing<br />
images with alpha channel.</li>
</ul>
<p>Please try out your applications with rmagick4j and help us provide<br />
feedback.  It is our goal to make a fully-compatible implementation of<br />
RMagick4j in JRuby.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/08/16/rmagick4j-036/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RMagick: Dibujar con patrones</title>
		<link>http://www.serabe.com/2008/07/22/rmagick-dibujar-con-patrones/</link>
		<comments>http://www.serabe.com/2008/07/22/rmagick-dibujar-con-patrones/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 22:16:30 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rmagick]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=218</guid>
		<description><![CDATA[Una interesante cualidad de la clase Draw de RMagick es la posibilidad de definir patrones a travÃ©s del mÃ©todo pattern. En primer lugar, lo bÃ¡sico: PLAIN TEXT RUBY: require 'rubygems' require 'RMagick' &#160; include Magick Ahora definamos el patrÃ³n. Para ello, necesitamos cinco parÃ¡metros, el nombre, dos nÃºmeros que recomiendo ponerlos a cero (despuÃ©s de [...]]]></description>
			<content:encoded><![CDATA[<p>Una interesante cualidad de la clase Draw de RMagick es la posibilidad de definir patrones a travÃ©s del mÃ©todo <a href="http://www.imagemagick.org/RMagick/doc/draw.html#pattern" >pattern</a>.</p>
<p>En primer lugar, lo bÃ¡sico:</p>
<div class="igBar"><span id="lruby-6"><a href="#" onclick="javascript:showPlainTxt('ruby-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-6">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> 'rubygems'</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> 'RMagick'</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">include</span> Magick </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ahora definamos el patrÃ³n. Para ello, necesitamos cinco parÃ¡metros, el nombre, dos nÃºmeros que recomiendo ponerlos a cero (despuÃ©s de unas cuantas pruebas, no he notado diferencias notables) y despuÃ©s las dimensiones del patrÃ³n.</p>
<div class="igBar"><span id="lruby-7"><a href="#" onclick="javascript:showPlainTxt('ruby-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-7">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">draw = Draw.<span style="color:#9900CC;">new</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">draw.<span style="color:#9900CC;">pattern</span><span style="color:#006600; font-weight:bold;">&#40;</span>'circles', <span style="color:#006666;color:#800000;">0</span>, <span style="color:#006666;color:#800000;">0</span>, <span style="color:#006666;color:#800000;">10</span>, <span style="color:#006666;color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; draw.<span style="color:#9900CC;">stroke</span> 'none'</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; draw.<span style="color:#9900CC;">fill</span> 'red'</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; draw.<span style="color:#9900CC;">rectangle</span> <span style="color:#006666;color:#800000;">0</span>, <span style="color:#006666;color:#800000;">0</span>, <span style="color:#006666;color:#800000;">10</span>, <span style="color:#006666;color:#800000;">10</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; draw.<span style="color:#9900CC;">stroke</span> 'LightGreen'</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; draw.<span style="color:#9900CC;">fill</span> 'blue'</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; draw.<span style="color:#9900CC;">circle</span> <span style="color:#006666;color:#800000;">5</span>, <span style="color:#006666;color:#800000;">5</span>, <span style="color:#006666;color:#800000;">5</span>, <span style="color:#006666;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ya, por Ãºltimo, dibujamos un cuadrado y lo plasmamos en una imagen de 300x300.</p>
<div class="igBar"><span id="lruby-8"><a href="#" onclick="javascript:showPlainTxt('ruby-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-8">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">draw.<span style="color:#9900CC;">stroke</span> 'circles'</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">draw.<span style="color:#9900CC;">stroke_width</span> <span style="color:#006666;color:#800000;">25</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">draw.<span style="color:#9900CC;">fill</span> 'none'</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">draw.<span style="color:#9900CC;">polygon</span> <span style="color:#006666;color:#800000;">150</span>,<span style="color:#006666;color:#800000;">0</span>, <span style="color:#006666;color:#800000;">300</span>,<span style="color:#006666;color:#800000;">150</span>, <span style="color:#006666;color:#800000;">150</span>,<span style="color:#006666;color:#800000;">300</span>, <span style="color:#006666;color:#800000;">0</span>,<span style="color:#006666;color:#800000;">150</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">img = Image.<span style="color:#9900CC;">new</span> <span style="color:#006666;color:#800000;">300</span>, <span style="color:#006666;color:#800000;">300</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">draw.<span style="color:#9900CC;">draw</span> img</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">img.<span style="color:#9900CC;">write</span> 'pattern.<span style="color:#9900CC;">jpg</span>' </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>ObteniÃ©ndose el siguiente resultado:</p>
<div id="attachment_221" class="wp-caption alignnone" style="width: 310px"><a href="http://www.serabe.com/wp-content/uploads/2008/07/pattern.jpg" ><img src="http://www.serabe.com/wp-content/uploads/2008/07/pattern.jpg" alt="Dibujo con patrÃ³n como brocha" title="Dibujando con patrÃ³n." width="300" height="300" class="size-medium wp-image-221" /></a><p class="wp-caption-text">Dibujo con patrÃ³n como brocha</p></div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/07/22/rmagick-dibujar-con-patrones/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
