<?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:users614</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/614" rel="self"/>
  <title>Maciej Piechotka</title>
  <updated>Thu Oct 16 19:05:56 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor55316</id>
    <published>2008-10-16T19:05:56-07:00</published>
    <title>[Java] On Leapyear</title>
    <content type="html">

&lt;pre&gt;import java.util.Scanner;

public class LeapYear {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);

		System.out.println(&amp;quot;Please input a year&amp;quot;);
		int input = in.nextInt();
		
		if (input % 4 == 0 &amp;amp;&amp;amp; (input % 100 != 0 || input % 400 == 0)) {
			System.out.println(&amp;quot;The year: &amp;quot; + input + &amp;quot; is a leapyear&amp;quot;);
		} else {
			System.out.println(&amp;quot;The year: &amp;quot; + input + &amp;quot; is NOT leapyear&amp;quot;);
		}
	}
}

&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/534-leapyear/refactors/55316" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor53259</id>
    <published>2008-10-07T14:34:59-07:00</published>
    <title>[Python] On Permutation of values</title>
    <content type="html">&lt;p&gt;You looking for cartesian product. Here is a simle solution using generators.&lt;/p&gt;

&lt;p&gt;Be aware that the generator is returned not a list (to save memory).&lt;/p&gt;

&lt;pre&gt;def cart(*lists):
    if not lists:
        for x in L:
            yield [x]
    else:
        for x in L:
            for y in cart(lists[0], *lists[1:]):
                yield [x] + y

def perm(arg):
    if len(arg) == 0:
        return [[]]
    
    a = []
    for i in arg:
        a.append(xrange(i))
    return cart(*a)
&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/523-permutation-of-values/refactors/53259" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor28379</id>
    <published>2008-09-21T23:45:48-07:00</published>
    <title>[Ruby] On Conditional Assignment</title>
    <content type="html">&lt;p&gt;@danielharan:&lt;/p&gt;

&lt;p&gt;Well -  -100 &amp;lt; 10 but (-100)** &amp;gt; 10**2 as 10000 &amp;gt; 100.&lt;/p&gt;

&lt;p&gt;@Tien Dung:&lt;/p&gt;

&lt;p&gt;Sorry for voting 1 on the second refactoring. I meant 5 but clicked in wrong place. Do anybody knowns how to change it?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/500-conditional-assignment/refactors/28379" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor17389</id>
    <published>2008-09-16T10:42:26-07:00</published>
    <title>[C] On A Java-like function split</title>
    <content type="html">&lt;p&gt;YAR - it ommits the separators and have much more cleaner structure.&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

const int ALLOC_BLOCK = 16;

void
process_escape_block (char **iter, char **out, int *offset, char esp)
{
  char *begin, *end;

  begin = *iter;
  while(**iter != esp)
    (*iter)++;
  end = (*iter)++;

  *out = realloc(*out, *offset + (end - begin) + 1);
  strncpy(*out + *offset, begin, end - begin);
  *offset = *offset + (end - begin);
}

char *
process_block (char **iter, const char sep, const char esp)
{
  char *out;
  int   len;

  out = NULL;
  len = 0;

  while(1)
    {
      char *begin, *end;

      begin = *iter;
      while(**iter != sep &amp;amp;&amp;amp; **iter != esp &amp;amp;&amp;amp; **iter != '\0')
        (*iter)++;
      end = *iter;

      out = realloc(out, len + (end - begin) + 1);
      strncpy(out + len, begin, end - begin);
      len += (end - begin);
      
      if(**iter == esp)
      	{
      	  (*iter)++;
      	  process_escape_block(iter, &amp;amp;out, &amp;amp;len, esp);
      	}
      else if(**iter == sep)
      	{
      	  (*iter)++;
      	  break;
      	}
      else
      	{
      	  break;
      	}
    }
  return out;
}

char **
split (char *str, const char sep, const char esc)
{
  const int ALLOC_BLOCK = 16;
  
  char     **ret;
  int        ret_alloc;
  int        ret_iter;
  char      *iter;

  ret = NULL;
  ret_alloc = 0;
  ret_iter = 0;
  
  iter = str;
  while(1)
    {
      if(ret_iter == ret_alloc)
      	{
      	  ret_alloc += ALLOC_BLOCK;
      	  ret = realloc(ret, ret_alloc);
      	}

      if(*iter == '\0')
      	break;
      
      ret[ret_iter++] = process_block(&amp;amp;iter, sep, esc);
    }
  ret[ret_iter] = NULL;

  return ret;
}&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/494-a-java-like-function-split/refactors/17389" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor17388</id>
    <published>2008-09-16T10:06:49-07:00</published>
    <title>[C] On A Java-like function split</title>
    <content type="html">&lt;p&gt;May be something like that? The addition of error-checking should be relativly easy (removed to be clear).&lt;/p&gt;

&lt;p&gt;I'm not sure what your code do - especially with the memory allocation:
&lt;br /&gt;ret = (char **) malloc (sizeof (char *)); // Array of string of size 1?
&lt;br /&gt;ret[nParts] = (char *) malloc (sizeof (char)); // String of size 0? (&amp;quot;\0&amp;quot;)&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

const int ALLOC_BLOCK = 16;

char **
split (char *str, const char sep, const char esc)
{
  char **ret;        /* Allocated block */
  int    ret_alloc;  /* How much we allocated */
  int    ret_iter;   /* The current pointer index */
  char  *iter;       /* The current character */
  char  *iter_begin; /* The start of current */
  int    in_escape;  /* If currently in escape block */

  /* Initial allocation */
  ret_alloc = ALLOC_BLOCK;
  ret = malloc(sizeof(char *) * ret_alloc);
  ret_iter = 0;

  /* Main loop */
  iter = str;
  iter_begin = iter;
  in_escape = 0;
  while(1)
    {
      if(*iter == esc) /* If escape character */
  	    {
  	      if(in_escape)
  	        in_escape = 1;
      	  else
      	    in_escape = 0;
      	}
      else if(*iter == sep || *iter == 0) /* If separator */
      	{
      	  /* Copy from the beginning */
      	  ret[ret_iter++] = strndup(iter_begin, iter - iter_begin);
      	  /* Allocate block if near empty */
      	  if(ret_iter == ret_alloc)
      	    {
      	      ret_alloc += ALLOC_BLOCK;
      	      ret = realloc(NULL, sizeof(char *) * ret_alloc);
      	    }
      	  if (*iter) /* If it is not the end */
      	    {
      	      iter_begin = (iter + 1);
      	    }
      	  else /* It is the end */
      	    {
      	      break;
      	    }
      	}
      else
      	{
      	  /* Do nothing */
      	}
      iter++;
    }
  ret[ret_iter] = NULL; /* Terminating NULL */
  return ret;
}&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/494-a-java-like-function-split/refactors/17388" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15295</id>
    <published>2008-08-19T08:14:37-07:00</published>
    <title>[Java] On fileContentsEquals</title>
    <content type="html">&lt;p&gt;I'm tring once more - I've posted 3 minutes after the orginal post but it get spammed:&lt;/p&gt;

&lt;pre&gt;private static boolean areSame(File f1, File f2) throws IOException
{
  if(f1 == f2)
    return true;
  if(f1 == null || f2 == null)
    return false;

  MappedByteBuffer buf1 = new FileInputStream(f1).getChannel().map(FileChannel.MapMode.READ_ONLY, 0, f1.length);
  MappedByteBuffer buf2 = new FileInputStream(f2).getChannel().map(FileChannel.MapMode.READ_ONLY, 0, f1.length);
  return buf1.equals(buf2);
}&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/441-filecontentsequals/refactors/15295" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15294</id>
    <published>2008-08-19T08:09:27-07:00</published>
    <title>[Ruby] On simple pluralize</title>
    <content type="html">&lt;p&gt;Only in the i18n/l10n frameworks.&lt;/p&gt;

&lt;p&gt;However it allows you keep things dry:&lt;/p&gt;

&lt;pre&gt;## Helper

def pluralize(string, length)
  if length &amp;gt; 1
    string.pluralize
  else
    string
  end
end

## View

&amp;lt;%= pluralize(&amp;quot;Favorites&amp;quot;, @resource.favorites.length) %&amp;gt;
&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/444-simple-pluralize/refactors/15294" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15243</id>
    <published>2008-08-18T10:40:38-07:00</published>
    <title>[Java] On fileContentsEquals</title>
    <content type="html">&lt;p&gt;1. Yes. It will work on bytes
&lt;br /&gt;2. May be something like that - 3 lines in NIO.&lt;/p&gt;

&lt;pre&gt;public static boolean fileContentsEquals(File file1, File file2) throws IOException {
  ByteBuffer buf1 = new FileInputStream(file1).getChannel().map(MapMode.READ_ONLY, 0, file1.length());
  ByteBuffer buf2 = new FileInputStream(file2).getChannel().map(MapMode.READ_ONLY, 0, file2.length());
  return buf1.equals(buf2);
}&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/441-filecontentsequals/refactors/15243" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15079</id>
    <published>2008-08-15T08:47:51-07:00</published>
    <title>[Ruby] On CSV turn in to an array of hashes</title>
    <content type="html">&lt;p&gt;May be something like that:&lt;/p&gt;

&lt;pre&gt;require 'enumerator'

def fix_send_to_array(array)
  recipients = []
  array.split(',').each_cons(2) do |arr|
    recipients &amp;lt;&amp;lt; {:name =&amp;gt; arr[0], :email =&amp;gt; arr[1]}
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/437-csv-turn-in-to-an-array-of-hashes/refactors/15079" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15024</id>
    <published>2008-08-14T13:45:19-07:00</published>
    <title>[Ruby] On Split an array into half</title>
    <content type="html">&lt;p&gt;The same rounding:&lt;/p&gt;

&lt;pre&gt;artists = [1, 2, 3]
column_1 = artists[0...(artists.size/2.0).ceil]
column_2 = artists[(artists.size/2.0).ceil...artists.size]&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/435-split-an-array-into-half/refactors/15024" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15023</id>
    <published>2008-08-14T13:41:51-07:00</published>
    <title>[Ruby] On Split an array into half</title>
    <content type="html">&lt;p&gt;Something like that (a bit different rounding):&lt;/p&gt;

&lt;pre&gt;artists = [1, 2, 3]
column_1 = artists[0, artists.size/2]
column_2 = artists[artists.size/2...artists.size]&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/435-split-an-array-into-half/refactors/15023" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14773</id>
    <published>2008-08-10T18:43:08-07:00</published>
    <title>[Ruby] On Caesar Cipher</title>
    <content type="html">&lt;p&gt;Modification of Fabien Jakimowicz's code&lt;/p&gt;

&lt;pre&gt;def caesar(text, shift)
  text.split('').collect! {|letter| (letter[0] + shift).chr}.join
end
&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/427-caesar-cipher/refactors/14773" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14666</id>
    <published>2008-08-08T21:39:42-07:00</published>
    <title>[Ruby] On Same function repeated but with diff global vars!</title>
    <content type="html">&lt;p&gt;May be something like that:&lt;/p&gt;

&lt;p&gt;PS. Usage of global variables is not recommended.&lt;/p&gt;

&lt;pre&gt;%w{user network thumbnail}.each do |obj|
  module_eval &amp;lt;&amp;lt;-&amp;quot;EOS&amp;quot;, __FILE__, __LINE__
    def #{obj}_path(path)
      rpp = $#{obj}_remote_pictures_paths
      pre = rpp[digest(path, rpp.length)]
      &amp;quot;\#{pre}/\#{path}&amp;quot;
    end
  EOS
end&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/426-same-function-repeated-but-with-diff-global-vars/refactors/14666" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14587</id>
    <published>2008-08-06T21:23:18-07:00</published>
    <title>[PHP] On PHP5 Database Clas</title>
    <content type="html">&lt;p&gt;Sorry for late response - so what do you want which is not covered by MySQLi?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/391-php5-database-clas/refactors/14587" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14562</id>
    <published>2008-08-06T14:00:10-07:00</published>
    <title>[Ruby] On showing records in Ascending or Descening order on click</title>
    <content type="html">&lt;p&gt;Why you don't use JavaScript? You will have it wothout even hitting server.
&lt;br /&gt;You can of course fallback to hitting server.&lt;/p&gt;

&lt;p&gt;Do not use session for storing objects. You ask for problems (mostly performance problems).&lt;/p&gt;

&lt;pre&gt;## Users controller
class UsersController &amp;lt; ApplicationController

  def index
    by = %w{age salary}.include? params['by'] ? params['by'] : 'age'
    dir = %w{ASC DESC}.include? params['dir'] ? params['dir'] : 'DESC'
    @users = User.find(:all, :order =&amp;gt; &amp;quot;#{by} #{dir}&amp;quot;)
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/421-showing-records-in-ascending-or-descening-order-on-click/refactors/14562" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14561</id>
    <published>2008-08-06T13:54:55-07:00</published>
    <title>[Ruby] On showing records in Ascending or Descening order on click</title>
    <content type="html">&lt;p&gt;Why you don't use JavaScript?
&lt;br /&gt;Just sort the data on user page without hitting the database or even server.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/421-showing-records-in-ascending-or-descening-order-on-click/refactors/14561" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14428</id>
    <published>2008-08-03T09:02:18-07:00</published>
    <title>[Ruby] On Rails - Multiple instances and folder creation</title>
    <content type="html">&lt;p&gt;May be something like that?&lt;/p&gt;

&lt;p&gt;PS. Shouldn't short-name be called permalink?&lt;/p&gt;

&lt;pre&gt;## app/controller/accounts_controller.rb

 require 'FileUtils'

  def create
    @account = Account.create!(params[:account])
    @website = @account.websites.create!(params[:website])
    @user = @account.users.create!(params[:user])

    flash[:notice] = 'Your account was successfully created. Please login to begin :)'
    redirect_to login_path
  rescue RecordNotSaved
    render :layout =&amp;gt; 'signup', :action =&amp;gt; 'new'
  end

## In models (each)
  attr_protected :short_name
  before_create :set_short_name
  
  def set_short_name
    self.short_name ||= self.name.gsub(/\W+|\s+/, '-').downcase
  end

## In account model
  after_create :create_dir
    
  def create_dir
    FileUtils.mkdir_p(&amp;quot;public/content/#{self.short_name}&amp;quot;)
  end

## In website model
  belongs_to :account

  after_create :create_dir
    
  def create_dir
    %w{docs pictures users}.each do |d|
      FileUtils.mkdir_p(&amp;quot;public/content/#{self.account.short_name}/#{self.short_name}/#{d}&amp;quot;)
    end
  end&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/417-rails-multiple-instances-and-folder-creation/refactors/14428" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14294</id>
    <published>2008-08-01T07:03:53-07:00</published>
    <title>[Ruby] On Find the Intersection of Arrays with a Hash</title>
    <content type="html">&lt;p&gt;The sort is unnecessary in my code&lt;/p&gt;

&lt;pre&gt;pools = {1 =&amp;gt; [1,2,3], 2=&amp;gt; [3,4,5], 3=&amp;gt; [5,6,7]}
rej = Hash.new {0}
pools.values.flatten.reject! {|elem| rej[elem]++ != 1}
&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/413-find-the-intersection-of-arrays-with-a-hash/refactors/14294" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14240</id>
    <published>2008-07-31T22:03:29-07:00</published>
    <title>[Ruby] On Find the Intersection of Arrays with a Hash</title>
    <content type="html">&lt;p&gt;May be something like that&lt;/p&gt;

&lt;pre&gt;pools = {1 =&amp;gt; [1,2,3], 2=&amp;gt; [3,4,5], 3=&amp;gt; [5,6,7]}
rej = Hash.new {0}
pools.values.flatten.sort.reject! {|elem| rej[elem]++ != 1}
&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/413-find-the-intersection-of-arrays-with-a-hash/refactors/14240" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14231</id>
    <published>2008-07-31T20:31:29-07:00</published>
    <title>[Ruby] On Brainfuck Generator in Ruby</title>
    <content type="html">&lt;p&gt;A little bit different working - but in 3 lines&lt;/p&gt;

&lt;pre&gt;# generate_bf.rb
# (copyleft) Matt Gauger 2008
# Randomly generates a brainfuck program
# Commandline argument is used as the length of the program
# Otherwise, the program defaults to 140 characters in length to fit on Twitter

# generated Brainfuck code not guaranteed to do anything !!

length = ARGV.last.to_i || 140
chars = %w{&amp;lt; &amp;gt; + - . , [ ]}
puts Array.new(length) {chars[rand(chars.length)]}.join&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/412-brainfuck-generator-in-ruby/refactors/14231" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14115</id>
    <published>2008-07-30T18:55:16-07:00</published>
    <title>[Ruby] On Exercise: Deaf Grandma </title>
    <content type="html">&lt;p&gt;@Wolfbyte - to keep the ruby convention: 'granny_can_hear' shouldn't be named 'granny_hear?'?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/404-exercise-deaf-grandma/refactors/14115" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14083</id>
    <published>2008-07-30T11:46:33-07:00</published>
    <title>[Ruby] On Contoller refactoring</title>
    <content type="html">&lt;p&gt;Do it RESTful. Use fat models. It is very hard to do it in other way in RoR/Merb/... Create invitation model without any DB table associated (i.e. fake model).&lt;/p&gt;

&lt;p&gt;Alternativly you can send email in the constructor&lt;/p&gt;

&lt;pre&gt;## app/model/invitation.rb
class Invitation
  include Validatable

  attr_accessor ...

  def initialize(*args)
    ... # Set the parameters
  end

  def save
    if valid?
      send_email # Have to return non-0/non-nil on success
    else
      false
    end
  end
  
  def save!
    save || raise ProperException
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/406-contoller-refactoring/refactors/14083" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14044</id>
    <published>2008-07-29T20:28:57-07:00</published>
    <title>[Ruby] On Exercise: Deaf Grandma </title>
    <content type="html">&lt;p&gt;Only what within the task. You can change puts into whatever you want.&lt;/p&gt;

&lt;pre&gt;count_bye = 0
loop do
  word = gets.chomp

  if word == &amp;quot;BYE&amp;quot; 
    count_bye += 1
    if count_bye == 3
      puts &amp;quot;Bye son.&amp;quot;
      break
    end
  else
    count_bye = 0
  end

  if word != &amp;quot;BYE&amp;quot; and word.upcase == word
    puts &amp;quot;No. Not since #{1930 + rand(21)}.&amp;quot;
  else
    puts &amp;quot;I cannot hear you son!&amp;quot;
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/404-exercise-deaf-grandma/refactors/14044" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor13484</id>
    <published>2008-07-21T19:24:17-07:00</published>
    <title>[PHP] On PHP5 Database Clas</title>
    <content type="html">&lt;p&gt;1. Why not PEAR DB?
&lt;br /&gt;2. Why not MySQLi with precompiled queries (it has everything you need but faster and in standard)?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/391-php5-database-clas/refactors/13484" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor12714</id>
    <published>2008-07-07T14:55:37-07:00</published>
    <title>[Ruby] On Constructing a search query</title>
    <content type="html">&lt;p&gt;DON'T DO IT!
&lt;br /&gt;It is broken by design - you can easily inject SQL Code into it.&lt;/p&gt;

&lt;p&gt;PS. What it has in common with ferret?
&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Maciej Piechotka</name>
      <email>uzytkownik2@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/353-construct-search-query/refactors/12714" rel="alternate"/>
  </entry>
</feed>

