<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users4</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/4" rel="self"/>
  <title>Gary Haran</title>
  <updated>Thu Dec 20 22:23:31 -0800 2007</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor1223</id>
    <published>2007-12-20T22:23:31-08:00</published>
    <title>[Ruby] On Challenge: Ugliest Ruby FizzBuzz</title>
    <content type="html">&lt;p&gt;Mine runs faster than yours&lt;/p&gt;

&lt;pre&gt;puts '1'
puts '2'
puts 'buzz'
puts '4'
puts 'fizz'
puts 'buzz'
puts '7'
puts '8'
puts 'buzz'
puts 'fizz'
puts '11'
puts 'buzz'
puts '13'
puts '14'
puts 'fizzbuzz'
puts '16'
puts '17'
puts 'buzz'
puts '19'
puts 'fizz'
puts 'buzz'
puts '22'
puts '23'
puts 'buzz'
puts 'fizz'
puts '26'
puts 'buzz'
puts '28'
puts '29'
puts 'fizzbuzz'
puts '31'
puts '32'
puts 'buzz'
puts '34'
puts 'fizz'
puts 'buzz'
puts '37'
puts '38'
puts 'buzz'
puts 'fizz'
puts '41'
puts 'buzz'
puts '43'
puts '44'
puts 'fizzbuzz'
puts '46'
puts '47'
puts 'buzz'
puts '49'
puts 'fizz'
puts 'buzz'
puts '52'
puts '53'
puts 'buzz'
puts 'fizz'
puts '56'
puts 'buzz'
puts '58'
puts '59'
puts 'fizzbuzz'
puts '61'
puts '62'
puts 'buzz'
puts '64'
puts 'fizz'
puts 'buzz'
puts '67'
puts '68'
puts 'buzz'
puts 'fizz'
puts '71'
puts 'buzz'
puts '73'
puts '74'
puts 'fizzbuzz'
puts '76'
puts '77'
puts 'buzz'
puts '79'
puts 'fizz'
puts 'buzz'
puts '82'
puts '83'
puts 'buzz'
puts 'fizz'
puts '86'
puts 'buzz'
puts '88'
puts '89'
puts 'fizzbuzz'
puts '91'
puts '92'
puts 'buzz'
puts '94'
puts 'fizz'
puts 'buzz'
puts '97'
puts '98'
puts 'buzz'
puts 'fizz'&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/192-challenge-ugliest-ruby-fizzbuzz/refactors/1223" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor671</id>
    <published>2007-10-31T14:59:33-07:00</published>
    <title>[JavaScript] On I care about older browsers without JS</title>
    <content type="html">&lt;p&gt;No sir.  This was client side JS sent to us via an ad server.  The entirity of their code is like that.  They declare a variable and set a value to it and the next line they redeclare it with a different value.  Everything about their ad server is random and it boggled my mind so much I thought I'd share.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/121-i-care-about-older-browsers-without-js/refactors/671" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code121</id>
    <published>2007-10-30T22:30:23-07:00</published>
    <updated>2007-10-31T14:59:35-07:00</updated>
    <title>[JavaScript] I care about older browsers without JS</title>
    <content type="html">&lt;p&gt;I found this great piece of code from an ad server and thought to myself that I should learn to make my own JS legacy compliant.  Can anyone please tell me if they know a better way to do this?  Thanks in advance.&lt;/p&gt;

&lt;pre&gt;document.write ('&amp;lt;noscript&amp;gt;\n');
document.write (imageClick);
document.write (&amp;quot;&amp;lt;/noscript&amp;gt;&amp;quot;);&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/121-i-care-about-older-browsers-without-js" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor652</id>
    <published>2007-10-30T15:41:28-07:00</published>
    <title>[JavaScript] On Curry</title>
    <content type="html">&lt;p&gt;I would use bindAsEventListener here so that you can use the event.&lt;/p&gt;

&lt;pre&gt;# W/ Prototype and W/out currying
$(imgID).observe(&amp;quot;mouseover&amp;quot;, 
  function(event) {
    this.mouseOver(i)
}.bindAsEventListener(this));&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/94-curry/refactors/652" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor650</id>
    <published>2007-10-30T15:32:03-07:00</published>
    <title>[JavaScript] On Random URL</title>
    <content type="html">&lt;p&gt;I much prefer Fu86's refactor but honestly this kind of stuff should not be done in Javascript.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/117-random-url/refactors/650" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code118</id>
    <published>2007-10-30T15:29:16-07:00</published>
    <updated>2011-11-25T00:03:08-08:00</updated>
    <title>[Ruby] Is This String Postal?</title>
    <content type="html">&lt;p&gt;We've had the debate over wether it was a good idea or not to do this.&lt;/p&gt;

&lt;pre&gt;class String 
  def postal?  
    self.match(/[a-zA-Z]{1}\d{1}[a-zA-Z]{1}([\x20-])*\d{1}[a-zA-Z]{1}\d{1}/) ? true : false
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/118-is-this-string-postal" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor383</id>
    <published>2007-10-11T19:55:00-07:00</published>
    <title>[Ruby] On Iffy</title>
    <content type="html">&lt;p&gt;in the middle of all of this I had to add another else...  a coworker mentionned this example&lt;/p&gt;

&lt;pre&gt;p = Proc.new { |en, fr| lang.to_s == &amp;quot;en&amp;quot; ? en : fr }
breaker = case location_type
  when 'point'
    p.call('near', 'proximite')
  when 'street'
    p.call('on', 'sur')
  else
    p.call('in', 'dans')
end&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/75-iffy/refactors/383" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code75</id>
    <published>2007-10-11T19:15:38-07:00</published>
    <updated>2007-10-11T19:15:38-07:00</updated>
    <title>[Ruby] Iffy</title>
    <content type="html">&lt;p&gt;With all the magic surrounding ruby I can't help but think that there are shorter and more readable ways to do this.&lt;/p&gt;

&lt;pre&gt;if self.location_type.to_s == 'point'
  breaker = self.lang == 'fr' ? 'proximite' : 'near'
 else  
  breaker = self.lang == 'fr' ? 'dans' : 'in'
end&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/75-iffy" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor33</id>
    <published>2007-09-21T08:05:16-07:00</published>
    <title>[JavaScript] On Is this year a leap year?</title>
    <content type="html">&lt;p&gt;Indeed we could remove one of the conditions.  I replaced the condition with an integer value test instead, because JS automatically assumes that any value other than 0 is true.  Unfortunately it means more parenthesis but it still makes the code shorter.&lt;/p&gt;

&lt;p&gt;Can we find any other ways of making this shorter? :-D&lt;/p&gt;

&lt;p&gt;PS: you should add a way to add more than one code snippet so you can show two pieces of code that work together.  I'd love to show the test portion of this code in the same thread.&lt;/p&gt;

&lt;pre&gt;Object.extend(Date.prototype, {
  isLeap: function(){
    var year = this.getFullYear();
    return !(year % 4) &amp;amp;&amp;amp; !!(year % 100) || !(year % 400);
  }
});&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/14-is-this-year-a-leap-year/refactors/33" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code14</id>
    <published>2007-09-21T07:16:53-07:00</published>
    <updated>2011-11-15T12:53:13-08:00</updated>
    <title>[JavaScript] Is this year a leap year?</title>
    <content type="html">&lt;p&gt;I'm pretty sure we can figure out a shorter and more elegant way to do this :-D&lt;/p&gt;

&lt;pre&gt;Object.extend(Date.prototype, {
  isLeap: function(){
    var year = this.getFullYear();
    return (year % 4 == 0 &amp;amp;&amp;amp; year % 100 != 0) || (year % 100 == 0 &amp;amp;&amp;amp; year % 400 == 0);
  }
});&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/14-is-this-year-a-leap-year" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor10</id>
    <published>2007-09-18T10:26:43-07:00</published>
    <title>[Ruby] On Ruby simple loop</title>
    <content type="html">&lt;p&gt;definitely less keystrokes&lt;/p&gt;

&lt;pre&gt;for i in (1..10)
  puts i
end&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/2-ruby-simple-loop/refactors/10" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code4</id>
    <published>2007-09-17T13:09:40-07:00</published>
    <updated>2007-09-17T13:09:40-07:00</updated>
    <title>[JavaScript] Hello World</title>
    <content type="html">&lt;p&gt;This is simply to test out the Javascript colors :-D&lt;/p&gt;

&lt;pre&gt;String.prototype.hello = function(){
  alert('hello world!');
}

Object.extend(String, {
  hello: function(){
    document.write('hello world');
  });
&lt;/pre&gt;</content>
    <author>
      <name>Gary Haran</name>
      <email>gary.haran@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/4-hello-world" rel="alternate"/>
  </entry>
</feed>

