<?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:users337friends</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/337/friends" rel="self"/>
  <title>Eineki friends</title>
  <updated>Tue May 31 22:13:16 -0700 2011</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code1690</id>
    <published>2011-05-31T22:13:16-07:00</published>
    <updated>2011-06-01T08:10:43-07:00</updated>
    <title>[PHP] JSON Literals in PHP</title>
    <content type="html">&lt;p&gt;On a forum I was reading, someone wanted to use JSON-style arrays instead of the more verbose PHP-style arrays in a PHP script. I spent a couple of minutes whipping up this PHP preprocessor to be silly, but it turned out to be kind of neat in the end and seemed like a prime target for some refactoring. Have at it!&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php
/*
$foo = {
    &amp;quot;bar&amp;quot;: [
        &amp;quot;baz&amp;quot;,
        &amp;quot;refactor&amp;quot;,
        {
            &amp;quot;my&amp;quot;: &amp;quot;code&amp;quot;
        }
    ]
};

Becomes:

$foo = array (
   'bar' =&amp;gt; array (
        0 =&amp;gt; 'baz',
        1 =&amp;gt; 'refactor',
        2 =&amp;gt; array (
           'my' =&amp;gt; 'code',
        )
    )
);
*/

$file = fopen($argv[1], &amp;quot;r&amp;quot;);
$json = &amp;quot;&amp;quot;;
$depth = 0;

while (!feof($file)) {
    $chr = fgetc($file);
    
    switch ($state) {
        case 0:
            echo $chr;
        
            if ($chr == '=' || $chr == '(' || $chr == ',') {
                $state = 1;
            }
            break;
            
        case 1:
            if ($chr == '[' || $chr == '{') {
                $json .= $chr;
                
                $depth = 1;
                $state = 2;
            } else if (preg_match(&amp;quot;/\s/&amp;quot;, $chr)) {
                echo $chr;
            } else {
                echo $chr;
                $state = 0;
            }
            break;
            
        case 2:
            $json .= $chr;
        
            if ($chr == '[' || $chr == '{') {
                $depth++;
            } else if ($chr == ']' || $chr == '}') {
                $depth--;
            }
            
            if ($depth == 0) {
                $code = var_export(json_decode($json), true);
                $code = str_replace(&amp;quot;stdClass::__set_state&amp;quot;, &amp;quot;&amp;quot;, $code);
                echo $code;
                
                $json = &amp;quot;&amp;quot;;
                $state = 0;
            }
            
            break;
    }
}
?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1690-json-literals-in-php" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16012</id>
    <published>2008-08-29T21:03:20-07:00</published>
    <title>[Ruby] On Too many assignments and conditional statements</title>
    <content type="html">&lt;p&gt;I couldn't quite discern what exactly you are trying to do. I'm guessing there is a much better way to do it. But based on what I could gather:&lt;/p&gt;

&lt;pre&gt;class Commentor
  def comment_type
    self.class.to_s.downcase
  end
  
  def comment
    comments.find_by_comment_type(comment_type)
  end
  
  def build_comment(*args)
    comments.build(*args)
  end
  
  def add_comment(text)
    if comment
      comment.text += text
    else
      build_comment(:text =&amp;gt; text, :comment_type =&amp;gt; comment_type)
    end
  end
end

class Header &amp;lt; ActiveRecord::Base
  include Commentor
  has_many :comments
end

class Project &amp;lt; ActiveRecord::Base
  include Commentor
  has_one :comment
end

class Comment &amp;lt; ActiveRecord::Base
  belongs_to :header
  belongs_to :traslation
end

# Usage:
# translation.add_comment(&amp;quot;This is a comment&amp;quot;)&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/466-too-many-assignments-and-conditional-statements/refactors/16012" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15934</id>
    <published>2008-08-28T22:02:18-07:00</published>
    <title>[Ruby] On Code to detect the web browser</title>
    <content type="html">&lt;p&gt;@Nicol&#195;&#161;s - I don't think the detect method does what you think it does. You can do the following, but I decided I liked the other form better.&lt;/p&gt;

&lt;pre&gt;def test_web_browser
  %w(Firefox/3 Firefox/2 MSIE\ 6 MSIE\ 7 Opera).detect do |agent|
    request.user_agent =~ Regexp.new(agent)
  end.gsub(/\W+/, &amp;quot;&amp;quot;)
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/462-code-to-detect-the-web-browser/refactors/15934" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15923</id>
    <published>2008-08-28T18:50:37-07:00</published>
    <title>[Ruby] On simplify multiple gsub</title>
    <content type="html">

&lt;pre&gt;class Normalizer &amp;lt; Struct.new(:string)
  REPLACEMENTS = {
    0x92 =&amp;gt; &amp;quot;&amp;amp;#39;&amp;quot;,
    0x91 =&amp;gt; &amp;quot;&amp;amp;#39;&amp;quot;,
    0x96 =&amp;gt; &amp;quot;-&amp;quot;,
    0xAE =&amp;gt; &amp;quot;(R)&amp;quot;,
    0x99 =&amp;gt; &amp;quot;(TM)&amp;quot;,
    0xBD =&amp;gt; &amp;quot;1/2&amp;quot;,
    0xBE =&amp;gt; &amp;quot;3/4&amp;quot;,
    0xBC =&amp;gt; &amp;quot;1/4&amp;quot;,
    0xB0 =&amp;gt; &amp;quot; degree &amp;quot;,
    0xBA =&amp;gt; &amp;quot; degrees &amp;quot;
  }
  
  def normalize
    string.enum_for(:each_byte).map { |char| REPLACEMENTS[char] || char.chr }.join
  end
  
  def normalize!
    string.replace(normalize)
  end
end

# Normalizer.new(data).normalize!&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/459-simplify-multiple-gsub/refactors/15923" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15921</id>
    <published>2008-08-28T18:32:22-07:00</published>
    <title>[Ruby] On Code to detect the web browser</title>
    <content type="html">

&lt;pre&gt;def test_web_browser
  catch(:match) do
    [&amp;quot;Firefox/3&amp;quot;, &amp;quot;Firefox/2&amp;quot;, &amp;quot;MSIE 6&amp;quot;, &amp;quot;MSIE 7&amp;quot;, &amp;quot;Opera&amp;quot;].each do |ua|
      throw(:match, ua.gsub(/[^a-z0-9]/i, &amp;quot;&amp;quot;)) if request.user_agent =~ Regexp.new(ua)
    end
    nil
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/462-code-to-detect-the-web-browser/refactors/15921" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15821</id>
    <published>2008-08-27T13:42:51-07:00</published>
    <title>[Ruby] On simplify multiple gsub</title>
    <content type="html">&lt;p&gt;Perhaps I wasn't clear with my previous post. The normalize method does the same thing you are doing with gsub.&lt;/p&gt;

&lt;pre&gt;&amp;quot;\xBD + \xBC&amp;quot;.chars.normalize.to_s
=&amp;gt; &amp;quot;1/2 + 1/4&amp;quot;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/459-simplify-multiple-gsub/refactors/15821" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15802</id>
    <published>2008-08-27T04:07:04-07:00</published>
    <title>[Ruby] On simplify multiple gsub</title>
    <content type="html">&lt;p&gt;Why not use ActiveSupport::Multibyte::Chars instead?&lt;/p&gt;

&lt;pre&gt;data.chars.normalize!

&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/459-simplify-multiple-gsub/refactors/15802" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15380</id>
    <published>2008-08-20T14:06:04-07:00</published>
    <title>[Ruby] On Code transactions</title>
    <content type="html">

&lt;pre&gt;require 'transaction/simple/group'

def transact(objects, action)
  group = Transaction::Simple::Group.new(*objects)
  group.start_transaction
  
  if objects.all? { |object| object.send(action) }
    group.commit_transaction
  else
    group.abort_transaction
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/452-code-transactions/refactors/15380" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15378</id>
    <published>2008-08-20T13:51:49-07:00</published>
    <title>[Ruby] On Link to if else simple condition.</title>
    <content type="html">&lt;p&gt;You should be using named routes, not hashes, for URLs. After you change that it won't be so bad to have just a plain old if statement in your view.&lt;/p&gt;

&lt;pre&gt;## View [html_rails]
&amp;lt;span class=&amp;quot;bluelinks-allsmall&amp;quot;&amp;gt;
	&amp;lt;% if user.normal? %&amp;gt;
		&amp;lt;%= link_to &amp;quot;Normal&amp;quot;, formatted_howto_path(howto, :normal) %&amp;gt;
	&amp;lt;% else %&amp;gt;
		&amp;lt;%= link_to &amp;quot;Executive&amp;quot;, formatted_howto_path(howto, :executive) %&amp;gt;
	&amp;lt;% end %&amp;gt;
&amp;lt;/span&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/453-link-to-if-else-simple-condition/refactors/15378" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15370</id>
    <published>2008-08-20T11:19:40-07:00</published>
    <title>[JavaScript] On Setting focus after alert</title>
    <content type="html">&lt;p&gt;Form elements can be disabled. Ofcourse in this case the focus is set after enabling the element. But would that suit your needs? I was just curious, why do you need to disable the events?&lt;/p&gt;

&lt;pre&gt;//msg is the string to show in the alert.
//obj is the input to focus
function msgFocus(msg, obj){
    obj.disabled = true;
    alert(msg);
    setTimeout(function() { 
        obj.disabled = false; 
        obj.focus(); 
    }, 50);
}&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/442-setting-focus-after-alert/refactors/15370" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15352</id>
    <published>2008-08-20T05:21:15-07:00</published>
    <title>[Ruby] On Method for sorting</title>
    <content type="html">&lt;p&gt;Here is your sort algorithm refactored in a more Ruby-like fashion. Hopefully it makes it much clearer as to what is going on.&lt;/p&gt;

&lt;pre&gt;def sort(array)
  array.inject([]) do |sorted,element|
    small, large = sorted.partition { |item| item &amp;lt; element }
    (small &amp;lt;&amp;lt; element) + large
  end
end

&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/449-method-for-sorting/refactors/15352" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15348</id>
    <published>2008-08-20T04:22:14-07:00</published>
    <title>[Ruby] On Default value for user column</title>
    <content type="html">&lt;p&gt;I disagree with the others that it belongs in the model. This is most certainly display logic and would traditionally belong in a helper method. Except helper methods are rather ugly for this kind of thing. Thus, I give you a (basic) presenter:&lt;/p&gt;

&lt;pre&gt;## Helper
module ApplicationHelper
  def present(object)
    object.class.const_get(&amp;quot;Presenter&amp;quot;).new(object)
  end
end

## Presenter
class User::Presenter &amp;lt; Struct.new(:user)
  def city
    user.city.blank? ? &amp;quot;Not specified&amp;quot; : user.city.capitalize
  end
  
  def method_missing(method, *args, &amp;amp;block)
    user.send(method, *args, &amp;amp;block)
  end
end

## View [html_rails]
&amp;lt;%= present(@user).city %&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/446-default-value-for-user-column/refactors/15348" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15312</id>
    <published>2008-08-19T17:43:24-07:00</published>
    <title>[Ruby] On Method for sorting</title>
    <content type="html">&lt;p&gt;Although I understand that you are probably trying to learn the logic behind sorting, Ruby has it's own built-in sort method. So, from a refactoring point of view, all you need is something like this:&lt;/p&gt;

&lt;pre&gt;puts &amp;quot;Enter words, blank row quits.&amp;quot;        

while !(line = gets.chomp).empty?
  (lines ||= []) &amp;lt;&amp;lt; line
end

puts &amp;quot;sorted: #{lines.sort}&amp;quot;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/449-method-for-sorting/refactors/15312" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15306</id>
    <published>2008-08-19T15:43:59-07:00</published>
    <title>[Ruby] On How to benchmark</title>
    <content type="html">&lt;p&gt;Use script/performance/benchmarker to call each version. However, I would suggest that you only worry about the quality of the code here. The performance differences will be negligible.&lt;/p&gt;

&lt;p&gt;Also, I present to you an additional refactoring:&lt;/p&gt;

&lt;pre&gt;def self.favorite?(object)
  if reflection = object.class.reflect_on_association(:favorites)
    send(&amp;quot;find_by_#{reflection.primary_key_name}&amp;quot;, object)
  end
end

# Example usage:
# script/performance/benchmarker 50 &amp;quot;User.first.favorites.favorite?(Yellowpage.first)&amp;quot;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/445-how-to-benchmark/refactors/15306" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15301</id>
    <published>2008-08-19T14:16:03-07:00</published>
    <title>[Ruby] On simple pluralize</title>
    <content type="html">

&lt;pre&gt;&amp;lt;%= pluralize(@resource.favorites.length, &amp;quot;Favorite&amp;quot;) %&amp;gt; &lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/444-simple-pluralize/refactors/15301" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15091</id>
    <published>2008-08-15T13:23:37-07:00</published>
    <title>[Ruby] On CSV turn in to an array of hashes</title>
    <content type="html">

&lt;pre&gt;require &amp;quot;csv&amp;quot;
require &amp;quot;enumerator&amp;quot;

def fix_send_to_array(recipients)
  CSV.parse_line(recipients).enum_slice(2).map do |name,email|
    { &amp;quot;name&amp;quot; =&amp;gt; name, &amp;quot;email&amp;quot; =&amp;gt; email }
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/437-csv-turn-in-to-an-array-of-hashes/refactors/15091" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15080</id>
    <published>2008-08-15T09:47:40-07:00</published>
    <title>[PHP] On Getter and Setter</title>
    <content type="html">&lt;p&gt;&amp;quot;Should you create a getter/setter function for every single var you send to the class?&amp;quot;&lt;/p&gt;

&lt;p&gt;I guess that's the general idea. Call me sloppy if you will but sometimes i tend to go around setters and getters, simply because it's simpler. Don't get me wrong though, i wouldn't want to encourage that kind of behaviour 'cause in the end it's a time bomb. &lt;/p&gt;

&lt;p&gt;But i guess that if you find yourself in a situation where you have loads of variables in a class that you need to be able to set and get from the outside then it might mean that the class design isn't very good, or that it should be divided into a set of smaller classes.&lt;/p&gt;

&lt;p&gt;In my very humble opinion a perfectly valid way to set a large amount of variables is through the constructor method when initializing new instances. But that won't help you if you want to get a hold of them at a later point. &lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/425-getter-and-setter/refactors/15080" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15044</id>
    <published>2008-08-14T20:13:05-07:00</published>
    <title>[Ruby] On A shorter way to declare class constants?</title>
    <content type="html">

&lt;pre&gt;class Report &amp;lt; ActiveRecord::Base
  %w[hits uniques].each { |const| const_set(const.upcase, const) }
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/436-a-shorter-way-to-declare-class-constants/refactors/15044" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15025</id>
    <published>2008-08-14T14:03:15-07:00</published>
    <title>[Ruby] On Split an array into half</title>
    <content type="html">

&lt;pre&gt;require &amp;quot;enumerator&amp;quot;

artists = [ 1, 2, 3 ]
column_1, column_2 = artists.enum_slice((artists.size / 2.0).round).to_a&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/435-split-an-array-into-half/refactors/15025" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15015</id>
    <published>2008-08-14T08:11:19-07:00</published>
    <title>[PHP] On Resize image to canvas</title>
    <content type="html">&lt;p&gt;Checking for GD lib might actually be prudent. I once lost hours trying to get something like a picture upload working on a new server. For some reason nothing gave out any error messages. &lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/433-resize-image-to-canvas/refactors/15015" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14966</id>
    <published>2008-08-13T13:53:29-07:00</published>
    <title>[PHP] On Adding seconds to a MySQL timestamp</title>
    <content type="html">&lt;p&gt;Wow, that's neat! And you're right, it is faster. What i really dig about it though is that it's much more readable. Good stuff!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/363-adding-seconds-to-a-mysql-timestamp/refactors/14966" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code433</id>
    <published>2008-08-13T11:50:19-07:00</published>
    <updated>2011-04-14T16:16:00-07:00</updated>
    <title>[PHP] Resize image to canvas</title>
    <content type="html">&lt;p&gt;The built in image functions found in PHP manage to boggle my mind to a point where i can no longer understand anything of what's going on. I'll just end up messing around long enough to get things right. &lt;/p&gt;

&lt;p&gt;For this reason i'm always trying to write up functions (which often end up horribly wrong) that would obfuscate all the mind boggling soup out of my sight. &lt;/p&gt;

&lt;p&gt;Anything to make the following more bearable to live with is very, very welcome. Thanks.&lt;/p&gt;

&lt;pre&gt;/**
 * Scale an image according to input canvas dimensions. 
 * No cropping will occur, the scaled image is &amp;quot;centered&amp;quot; to canvas.
 */

function imageToCanvas ($_image, $_canvasWidth, $_canvasHeight)
{
    if (is_string($_image)) {
        if (is_file($_image)) {
            $_image = imagecreatefromjpeg($_image);
        } else {
            return &amp;quot;Incorrect imagepath &amp;gt;&amp;gt; No file here &amp;quot; . $_image;
        }
    } 
    
    $width = imagesx($_image);
    $height = imagesy($_image);
    $image_aspect_ratio = $width / $height;
    $canvas_aspect_ratio = $_canvasWidth / $_canvasHeight;
    
    // scale by height
    if ($image_aspect_ratio &amp;lt; $canvas_aspect_ratio) {
        $new_height = $_canvasHeight;
        $new_width = ($new_height/$height) * $width;
    } 
    // scale by width
    else {
        $new_width = $_canvasWidth;
        $new_height = ($new_width/$width) * $height;
    }
    
    # offset values (ie. center the resized image to canvas)
    $xoffset = ($_canvasWidth - $new_width) / 2;
    $yoffset = ($_canvasHeight - $new_height) / 2;
    
    $image_resized = imagecreatetruecolor($_canvasWidth, $_canvasHeight);
    
    # fill colour
    $white = imagecolorallocate($image_resized, 255, 255, 255);
    imagefill($image_resized, 0, 0, $white);
    imagecopyresampled($image_resized, $_image, $xoffset, $yoffset, 0, 0, $new_width, $new_height, $width, $height);
    
    imagedestroy($_image);
    return $image_resized;
}&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/433-resize-image-to-canvas" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14903</id>
    <published>2008-08-12T19:26:09-07:00</published>
    <title>[PHP] On Array and ForEach Loop</title>
    <content type="html">&lt;p&gt;Yeah you're right, parsing XML &amp;quot;manually&amp;quot; isn't usually a very bright idea. But i don't see a problem with creating XML &amp;quot;manually&amp;quot; as long as it's quite simple and straightforward, though. &lt;/p&gt;

&lt;pre&gt;echo '&amp;lt;qdapi&amp;gt;';
foreach($payload as $key =&amp;gt; $value) {
    echo &amp;quot;&amp;lt;$key&amp;gt;$value&amp;lt;/$key&amp;gt;&amp;quot;;
}
echo '&amp;lt;/qdapi&amp;gt;';&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/430-array-and-foreach-loop/refactors/14903" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14880</id>
    <published>2008-08-12T10:28:35-07:00</published>
    <title>[ActionScript] On Isometric X/Y Grid pattern depth sort</title>
    <content type="html">&lt;p&gt;Umm, i don't know what you're trying to do. Maybe you could explain your snippet of code a bit more? I kind of got the idea that you're trying to do some 3D stuff, right? Am i close or am i just completely off the map?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/424-isometric-x-y-grid-pattern-depth-sort/refactors/14880" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor13170</id>
    <published>2008-07-15T19:42:30-07:00</published>
    <title>[PHP] On Adding seconds to a MySQL timestamp</title>
    <content type="html">&lt;p&gt;Good stuff!&lt;/p&gt;

&lt;p&gt;Gotta hate myself for letting that typo creep in :) I checked the input like three times before submitting but there it still is. &lt;/p&gt;

&lt;p&gt;I'm not entirely with you on the fourth amendment though. I wanted to leave it to a row of it's own only so that it wouldn't get obfuscated with the rest of the mess. After all the lines are pretty long as it is. &lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Juha Hollanti</name>
      <email>juha.hollanti@newave.fi</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/363-adding-seconds-to-a-mysql-timestamp/refactors/13170" rel="alternate"/>
  </entry>
</feed>

