<?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>Fuller Web Development &#187; Code</title>
	<atom:link href="http://braydon.com/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://braydon.com/blog</link>
	<description>JavaScript, PHP, and Python Web Development by Braydon Fuller</description>
	<lastBuildDate>Fri, 06 Aug 2010 08:05:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress Tip: Modifying the Loop, Custom Posts Query to include all Post Types</title>
		<link>http://braydon.com/blog/2010/08/wordpress-tip-modifying-the-loop-custom-posts-query-to-include-all-post-types/</link>
		<comments>http://braydon.com/blog/2010/08/wordpress-tip-modifying-the-loop-custom-posts-query-to-include-all-post-types/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 07:45:47 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=1012</guid>
		<description><![CDATA[The default post_type in query_posts is &#8216;post&#8217;, so other post types will not be in the loop unless they are specified. Here is an example of what you could include at the top of your template to include all post types.

global $wp_query;
$p = array('post_type' => array('article', 'gallery','post','project'));
$q = array_merge($wp_query->query_vars, $p);
query_posts($q);

]]></description>
			<content:encoded><![CDATA[<p>The default post_type in query_posts is &#8216;post&#8217;, so other post types will not be in the loop unless they are specified. Here is an example of what you could include at the top of your template to include all post types.</p>
<p><code><br />
global $wp_query;<br />
$p = array('post_type' => array('article', 'gallery','post','project'));<br />
$q = array_merge($wp_query->query_vars, $p);<br />
query_posts($q);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2010/08/wordpress-tip-modifying-the-loop-custom-posts-query-to-include-all-post-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;The 1,11,2 Problem&#8221;, natural sorting of numbers and characters.</title>
		<link>http://braydon.com/blog/2010/08/the-1112-problem-natural-sorting-of-numbers-and-characters/</link>
		<comments>http://braydon.com/blog/2010/08/the-1112-problem-natural-sorting-of-numbers-and-characters/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 21:11:31 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=1006</guid>
		<description><![CDATA[I&#8217;m sure everyone has run into this problem! You&#8217;re looking at a list in your file browser, or a maybe a list of tracks, the filenames or track numbers contain both numbers and characters, and the ordering is against logic: &#8220;1,11,2&#8243; instead of &#8220;1,2,11&#8243;. Often times we will rename filenames to be have a preceding [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure everyone has run into this problem! You&#8217;re looking at a list in your file browser, or a maybe a list of tracks, the filenames or track numbers contain both numbers and characters, and the ordering is against logic: &#8220;1,11,2&#8243; instead of &#8220;1,2,11&#8243;. Often times we will rename filenames to be have a preceding zero to fix the problem, &#8220;01, 02, 11&#8243;, however that isn&#8217;t compulsory!  This error happens because the numbers are seen to the software as as &#8220;string&#8221; of characters and their numeric value is not considered when it is sorted. Here is a great resource with examples in many programming languages on how to sort the &#8220;strings&#8221; considering both the alpha and numeric values in the &#8220;strings&#8221;: <a href="http://www.davekoelle.com/alphanum.html">The Alphanum Algorithm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2010/08/the-1112-problem-natural-sorting-of-numbers-and-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress URL Rewrite</title>
		<link>http://braydon.com/blog/2010/07/wordpress-url-rewrite/</link>
		<comments>http://braydon.com/blog/2010/07/wordpress-url-rewrite/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 01:11:56 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=853</guid>
		<description><![CDATA[WordPress has it&#8217;s own URL management system, and when developing websites it&#8217;s convenient to be able to add new rules dynamically. I&#8217;ve used this for two websites, music.vtechphones.com and for a site I am building now. It&#8217;s also great to keep all modifications in one place, so upgrades are easier, and easier for another developer [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress has it&#8217;s own URL management system, and when developing websites it&#8217;s convenient to be able to add new rules dynamically. I&#8217;ve used this for two websites, <a href="http://music.vtechphones.com">music.vtechphones.com</a> and for a site I am building now. It&#8217;s also great to keep all modifications in one place, so upgrades are easier, and easier for another developer to pick up!</p>
<p>Create a new plugin, and you place your rules into it doing something similar to the PHP below:</p>
<pre>

add_filter('rewrite_rules_array','wp_insert_my_rewrite_rules');
add_filter('init','flush_rules');

// Remember to flush_rules() when adding rules
function flush_rules(){
  global $wp_rewrite;
  $wp_rewrite->flush_rules();
}

// Adding a new rule
function wp_insert_my_rewrite_rules($rules){
  $newrules = array();

  $newrules['(articles)$'] = 'index.php?post_type=article';
  $newrules['(gallery)$'] = 'index.php?post_type=gallery';
  $newrules['(projects)$'] = 'index.php?post_type=project';
  $newrules['(blog)$'] = 'index.php?post_type=post';

  return $newrules + $rules;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2010/07/wordpress-url-rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Performance Part 3: Python 3000 and Transforming Large Lists into Seperate Smaller Lists</title>
		<link>http://braydon.com/blog/2008/12/python-performance-part-3-python-3000-and-transforming-large-lists-into-seperate-smaller-lists/</link>
		<comments>http://braydon.com/blog/2008/12/python-performance-part-3-python-3000-and-transforming-large-lists-into-seperate-smaller-lists/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 13:30:00 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=125</guid>
		<description><![CDATA[
Preface
This is a redux of Python Performance Part 1, where the fastest method was using the reduce builtin function in Python2.5. December 3rd, Python 3000 final was released so I have downloaded it and gone over some of these scripts again. In Python 3000 the reduce function is no longer a builtin, and has moved [...]]]></description>
			<content:encoded><![CDATA[<div class="text" id="extended">
<h2>Preface</h2>
<p>This is a redux of <a href="/blog/2009/2/11/python-performance-part-1">Python Performance Part 1</a>, where the fastest method was using the reduce builtin function in Python2.5. December 3rd, Python 3000 final was released so I have downloaded it and gone over some of these scripts again. In Python 3000 the reduce function is no longer a builtin, and has moved to the module functools. When doing some general comparisons between Python2.5 and Python 3000, the later seemed to always run slightly slower. This is due to the new IO system and unicode indentifiers, as I was told in #python channel by Crys_. It was also recommended that I also compare my tests with <a href="http://en.wikipedia.org/wiki/List_comprehension">List Comprehension</a>, of which is new to me.</p>
<h2>List Comprehension</h2>
<pre>from oids import oids as a
c = 3
res = [a[x:x+c] for x in [c*x for x in range(int(round(len(a)/c)))]]
</pre>
<h3>Python 3k Times</h3>
<pre>real  0m0.218s
user  0m0.180s
sys   0m0.016s

real  0m0.262s
user  0m0.204s
sys   0m0.032s

real  0m0.287s
user  0m0.244s
sys   0m0.008s
</pre>
<h3>Python 2.5 Times</h3>
<pre>real  0m0.244s
user  0m0.220s
sys   0m0.016s

real  0m0.229s
user  0m0.208s
sys   0m0.020s

real  0m0.251s
user  0m0.236s
sys   0m0.020s
</pre>
<p>
This makes it the fastest method, beating the previous fastest time of 0.34s. Even better, there is little difference between Python2.5 and Python3000 here.
</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2008/12/python-performance-part-3-python-3000-and-transforming-large-lists-into-seperate-smaller-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Performance Part 2 Redux: Split &amp; Reduce Large Strings for &#039;A Href&#039; Hypertext</title>
		<link>http://braydon.com/blog/2008/06/python-performance-part-2-redux-split-reduce-large-strings-for-a-href-hypertext/</link>
		<comments>http://braydon.com/blog/2008/06/python-performance-part-2-redux-split-reduce-large-strings-for-a-href-hypertext/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 13:37:21 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=129</guid>
		<description><![CDATA[
split_2.py
def get_value(a):
    return a[1:a.find("&#62;")-1]
hrefs = map(get_value,open("hypertext.html","r").read().split("&#60;a href="))

Timing Comparison: ~ 300% Performance Improvement
Note: hypertext.html is 48MB.
braydon@bgf:~/python_tests/extract$ time python split.py 

real    0m1.263s
user    0m1.112s
sys     0m0.156s

braydon@bgf:~/python_tests/extract$ time python split_2.py 

real    0m0.392s
user    0m0.268s
sys     0m0.120s

split.py
Previously, I had found [...]]]></description>
			<content:encoded><![CDATA[<div class="text" id="extended">
<h2>split_2.py</h2>
<pre>def get_value(a):
    return a[1:a.find("&gt;")-1]
hrefs = map(get_value,open("hypertext.html","r").read().split("&lt;a href="))
</pre>
<h2>Timing Comparison: ~ 300% Performance Improvement</h2>
<p>Note: hypertext.html is 48MB.</p>
<pre>braydon@bgf:~/python_tests/extract$ time python split.py 

real    0m1.263s
user    0m1.112s
sys     0m0.156s

braydon@bgf:~/python_tests/extract$ time python split_2.py 

real    0m0.392s
user    0m0.268s
sys     0m0.120s
</pre>
<h2>split.py</h2>
<p>Previously, I had found the best solution to my problem was to split() the large string up by the &#8220;&gt;&#8221; character, and then reduce to a list of hyperlinks. </p>
<pre>def is_ahref(a,b):
    y = b.find("&lt;a href=")
    if y != -1: a.append(b[y+9:-1])
    return a

def preduce(fn,ls,a):
    ls.insert(0,a)
    return reduce(fn,ls)

hrefs = preduce(is_ahref,open("hypertext.html","r").read().split("&gt;"),[])
</pre>
<p>There is a better solution. Splitting the text up by the &#8220;&gt;&#8221; character is wasteful; there are many &#8220;&gt;&#8221;s in html, and most of them that will not have hyperlinks. We don&#8217;t need to even check if the item in the list is an href if we split the string into a list that all will have an href, and then reduce it as before. </p>
<pre>def is_ahref(a,b):
    z = b.find("&gt;")
    a.append(b[1:z-1])
    return a

def preduce(fn,ls,a):
    ls.insert(0,a)
    return reduce(fn,ls)

fc = open("hypertext.html","r").read().split("&lt;a href=")
hrefs = preduce(is_ahref,fc,[])
</pre>
<p>However because the size of the list will be exactly the same as it started, we shouldn&#8217;t need to use reduce(), but rather we can just map() a fuction to run through the entire list, &#8216;reducing&#8217; it to a list of just the hyperlinks.</p>
<h2>split_2.py</h2>
<pre>def get_value(a):
    return a[1:a.find("&gt;")-1]
hrefs = map(get_value,open("hypertext.html","r").read().split("&lt;a href="))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2008/06/python-performance-part-2-redux-split-reduce-large-strings-for-a-href-hypertext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Performance Part 2: Parsing Large Strings for &#039;A Href&#039; Hypertext</title>
		<link>http://braydon.com/blog/2008/06/python-performance-part-2-parsing-large-strings-for-a-href-hypertext/</link>
		<comments>http://braydon.com/blog/2008/06/python-performance-part-2-parsing-large-strings-for-a-href-hypertext/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 13:39:46 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=133</guid>
		<description><![CDATA[
Goal
Write a fast Python script that will take a large string and reduce it to a list of all of the hyperlinks in the html string; such as [”http://world.org”,”/tree”].
Attempt 1: Self-Recursion 
f = open('hypertext_sm.html','r')
ahrefs = []
count = []
def find_ahref(h):
    a = h.find("&#60;a href=")
    if a != -1:
   [...]]]></description>
			<content:encoded><![CDATA[<div class="text" id="extended">
<h2>Goal</h2>
<p>Write a fast Python script that will take a large string and reduce it to a list of all of the hyperlinks in the html string; such as [”http://world.org”,”/tree”].</p>
<h2>Attempt 1: Self-Recursion </h2>
<pre>f = open('hypertext_sm.html','r')
ahrefs = []
count = []
def find_ahref(h):
    a = h.find("&lt;a href=")
    if a != -1:
        a = a+9
        b = a + h[a:-1].find("&gt;")-1
        ahrefs.append(h[a:b])
        find_ahref(h[b:-1])

find_ahref(f.read())
f.close()
</pre>
<h3>Summary</h3>
<p>Fairly fast with small strings, however with large strings it causes a memory overload from the large string being stored multiple times from the self-recursion, causing the script to fail.</p>
<h2>Attempt 2: Reduce</h2>
<pre>f = open('hypertext_sm.html','r')
def find_ahref(a,b):
    try:
        c = a[1] + str(b)
        x = c.find("&lt;a href=")
        y = c[x:-1].find("&gt;")
        if x != -1 and y != -1:
            a[0].append(c[x+9:x+y-1])
            return (a[0],"")
        else:
            return (a[0],c)
    except:
        return ([],str(a)+str(b))

hrefs = reduce(find_ahref,f.read())[0]
f.close()
</pre>
<h3>Summary</h3>
<p>Not as fast as the previous with smaller strings, however it does not overload the memory and it atually completed parsing the larger string (43Mb). Because it took nearly 7min to run though it is difficult for in to be a solution.</p>
<h2>Attempt: 3: While Readline</h2>
<pre>
f = open('hypertext.html','r')

ahrefs = []
def find_ahref(h):
    a = h.find("&lt;a href=")
    if a != -1:
        a = a+9
        b = a + h[a:-1].find("&gt;")-1
        ahrefs.append(h[a:b])
        find_ahref(h[b:-1])

while True:
    line = f.readline()
    if line:
        find_ahref(line)
    else:
        break

f.close()
</pre>
<h3>Summary</h3>
<p>This is pretty fast with both small and large strings (with many lines). However if it was handed a very large single line it would crumble as Attempt 1: Self-Recursion.</p>
<h2>Attempt 4: Map/Reducer Readlines</h2>
<pre>f = open('hypertext.html','r')
def ahref_reducer(a,b):
    try:
        c = a[1] + str(b)
        x = c.find("&lt;a href=")
        y = c[x:-1].find("&gt;")
        if x != -1 and y != -1:
            a[0].append(c[x+9:x+y-1])
            return (a[0],"")
        else:
            return (a[0],c)
    except:
        return ([],str(a)+str(b))

def get_ahrefs(line):
    return reduce(ahref_reducer,line)[0]

lines = f.readlines()
hrefs = map(get_ahrefs,lines)
f.close()
</pre>
<h3>Summary</h3>
<p>Slower but doesn’t destroy memory. However, it doesn’t really meet the goal either as it returns a nasty list with empty parts.</p>
<h2>Attempt 5: Reduce Recurse Readlines</h2>
<pre>f = open('hypertext.html','r')

def find_ahref(z,htxt):
    a = htxt.find("&lt;a href=")
    if a != -1:
        a = a+9
        b = a+htxt[a:-1].find("&gt;")-1
        href = htxt[a:b]
        z.append(href)
        return find_ahref(z,htxt[b:-1])
    else:
        return z

def preduce(fn,ls,a):
    ls.insert(0,a)
    return reduce(fn,ls)

lines = f.readlines()
hrefs = preduce(find_ahref,lines,[])

f.close()
</pre>
<h3>Summary</h3>
<p>Fast, although it relies on their being many multiple lines.</p>
<h2>Attempt 6: Something Completly Different</h2>
<p>Instead of looking for the “a href” first we will look for the end “&gt;” and search for the “a href” to that point.</p>
<pre>hrefs = []

f = open("hypertext.html","r")
f_str = f.read()
f.close()

while True:
    b = f_str.find("&gt;")
    if b == -1:
        break
    a = f_str[0:b].find("&lt;a href=")
    if a != -1:
        hrefs.append(f_str[a+9:b-1])
    f_str = f_str[b+1:-1]
</pre>
<h3>Summary</h3>
<p>While good in theory, it does not handle large strings well; and by well I mean not at all. However it did get the correct hrefs from a smaller list.</p>
<h2>Attempt 7: Split &amp; (P)Reduce</h2>
<p>Rather than breaking the large string up by line, we will break it up by a character “&gt;”.</p>
<pre>def is_ahref(a,b):
    y = b.find("&lt;a href=")
    if y != -1: a.append(b[y+9:-1])
    return a

def preduce(fn,ls,a):
    ls.insert(0,a)
    return reduce(fn,ls)

hrefs = preduce(is_ahref,open("hypertext.html","r").read().split("&gt;"),[])
</pre>
<h3>Summary</h3>
<p>This is the fastest of them all, slightly faster than Reduce Recurse Readlines, and can even handle large single string lines quickly.</p>
<h2>Conclusion</h2>
<ul>
<li>Self-recursion is not good when passing around the same string to itself.
</li>
<li>Concatenating a long list of charaters from a string and checking for “a href” does not destroy memory but is very slow.
</li>
<li>Breaking a large string into smaller ones is faster and deosn’t destroy memory.
</li>
<li>Reading by line is only one way to make a large string (or file) into smaller strings.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2008/06/python-performance-part-2-parsing-large-strings-for-a-href-hypertext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Performance Part 1: Transforming Large Lists into Seperate Smaller Lists</title>
		<link>http://braydon.com/blog/2008/06/python-performance-part-1-transforming-large-lists-into-seperate-smaller-lists/</link>
		<comments>http://braydon.com/blog/2008/06/python-performance-part-1-transforming-large-lists-into-seperate-smaller-lists/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 13:39:26 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=138</guid>
		<description><![CDATA[
Goal
Write a fast Python script that will take a large list and break it up into smaller sub-lists based on a set size; such as transforming [a,b,c,d,e,f] into [[a,b],[c,d],[e,f]].
Attempt 1: Map/Reduce (0.93s)
#import a list of 247,213 integers
from oids import oids

def pre(a):
    return (list(), a, 0)

def make_sets(a,b):
    set_size = 8
 [...]]]></description>
			<content:encoded><![CDATA[<div class="text" id="extended">
<h2>Goal</h2>
<p>Write a fast Python script that will take a large list and break it up into smaller sub-lists based on a set size; such as transforming [a,b,c,d,e,f] into [[a,b],[c,d],[e,f]].</p>
<h2>Attempt 1: Map/Reduce (0.93s)</h2>
<pre>#import a list of 247,213 integers
from oids import oids

def pre(a):
    return (list(), a, 0)

def make_sets(a,b):
    set_size = 8
    if a[2] == set_size - 1 or a[0] == list():
        a[0].append([a[1]])
        return (a[0],b[1],0)
    else:
        a[0][-1].append(a[1])
        return (a[0],b[1],a[2]+1)

reduce(make_sets,map(pre,oids))
</pre>
<h3>Times</h3>
<pre>real    0m0.935s
user    0m0.896s
sys     0m0.032s

real    0m0.948s
user    0m0.920s
sys     0m0.028s

real    0m0.929s
user    0m0.900s
sys     0m0.024s
</pre>
<h2>Attempt 2: For-loop (0.41s)</h2>
<pre>
from oids import oids

output = list()
count = 0
set_size = 8
for oid in oids:
    if count == set_size or output == list():
        output.append([oid])
        count = 0
    else:
        output[-1].append(oid)
        count = count + 1
</pre>
<h3>Times</h3>
<pre>real    0m0.429s
user    0m0.404s
sys     0m0.024s

real    0m0.396s
user    0m0.384s
sys     0m0.012s

real    0m0.410s
user    0m0.396s
sys     0m0.012s
</pre>
<h2>Attempt 3: Map (0.48s)</h2>
<pre>from oids import oids

output = list()
set_size = 8
count = [0]

def break_apart(a):
    if count[-1] == set_size or output == list():
        output.append([a])
        count.append(0)
    else:
        output[-1].append(a)
        count.append(count[-1] + 1)

map(break_apart,oids)
</pre>
<h3>Timing</h3>
<pre>real    0m0.484s
user    0m0.476s
sys     0m0.012s

real    0m0.483s
user    0m0.464s
sys     0m0.016s

real    0m0.482s
user    0m0.452s
sys     0m0.028s
</pre>
<h2>Attempt 4: Reduce (0.34s)</h2>
<pre>from oids import oids

def seperate(a,b,length=8):
    try:
        if len(a[-1]) == length:
            a.append([b])
            return a
        else:
            a[-1].append(b)
            return a
    except:
        return [[a,b]]

oids = reduce(seperate,oids)
</pre>
<h3>Timing</h3>
<pre>real    0m0.323s
user    0m0.308s
sys     0m0.016s

real    0m0.329s
user    0m0.300s
sys     0m0.028s

real    0m0.353s
user    0m0.332s
sys     0m0.020s
</pre>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2008/06/python-performance-part-1-transforming-large-lists-into-seperate-smaller-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Importance in Rewriting Code</title>
		<link>http://braydon.com/blog/2008/01/the-importance-in-rewriting-code/</link>
		<comments>http://braydon.com/blog/2008/01/the-importance-in-rewriting-code/#comments</comments>
		<pubDate>Thu, 03 Jan 2008 22:33:51 +0000</pubDate>
		<dc:creator>Braydon Fuller</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://braydon.com/blog/?p=141</guid>
		<description><![CDATA[
I needed a way of translating “644″, an object permission setting, into something more readable.
I wanted to be able to do the following:


def determinePermissions(obj):
    obj_usr= {&#34;owner&#34;:obj.owner, &#34;group&#34;:obj.group, &#34;everyone&#34;:True}

    usr = {
        &#34;owner&#34;:cherrypy.session.get(&#39;user&#39;),

        &#34;group&#34;:cherrypy.session.get(&#39;group&#39;),
   [...]]]></description>
			<content:encoded><![CDATA[<div class="text" id="extended">
<p>I needed a way of translating “644″, an object permission setting, into something more readable.</p>
<p>I wanted to be able to do the following:
</p>
<div class="syntax">
<pre><span class="k">def</span> <span class="nf">determinePermissions</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="n">obj_usr</span><span class="o">=</span> <span class="p">{</span><span class="s">&quot;owner&quot;</span><span class="p">:</span><span class="n">obj</span><span class="o">.</span><span class="n">owner</span><span class="p">,</span> <span class="s">&quot;group&quot;</span><span class="p">:</span><span class="n">obj</span><span class="o">.</span><span class="n">group</span><span class="p">,</span> <span class="s">&quot;everyone&quot;</span><span class="p">:</span><span class="bp">True</span><span class="p">}</span>

    <span class="n">usr</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&quot;owner&quot;</span><span class="p">:</span><span class="n">cherrypy</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;user&#39;</span><span class="p">),</span>

        <span class="s">&quot;group&quot;</span><span class="p">:</span><span class="n">cherrypy</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;group&#39;</span><span class="p">),</span>
        <span class="s">&quot;everyone&quot;</span><span class="p">:</span><span class="bp">True</span>

    <span class="p">}</span>
    <span class="n">perms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">translatePermissions</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
    <span class="n">r</span><span class="p">,</span> <span class="n">w</span> <span class="o">=</span> <span class="bp">False</span><span class="p">,</span> <span class="bp">False</span>

    <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&quot;owner&quot;</span><span class="p">,</span> <span class="s">&quot;group&quot;</span><span class="p">,</span> <span class="s">&quot;everyone&quot;</span><span class="p">]:</span>

        <span class="n">r</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">perms</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">obj_user</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">==</span> <span class="n">usr</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">else</span> <span class="n">r</span>

        <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">perms</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">obj_user</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">==</span> <span class="n">usr</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">else</span> <span class="n">w</span>

    <span class="k">if</span> <span class="n">usr</span><span class="p">[</span><span class="s">&quot;owner&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;root&quot;</span><span class="p">:</span>
        <span class="n">r</span><span class="p">,</span> <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span><span class="p">,</span> <span class="bp">True</span>

    <span class="k">return</span> <span class="p">{</span><span class="s">&quot;read&quot;</span><span class="p">:</span><span class="n">r</span><span class="p">,</span> <span class="s">&quot;write&quot;</span><span class="p">:</span><span class="n">w</span><span class="p">}</span>
</pre>
</div>
<p>So I first wrote this [unexecuted]:</p>
</p>
<div class="syntax">
<pre>    <span class="k">def</span> <span class="nf">translatePermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>

        <span class="n">obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">oid</span><span class="o">=</span><span class="n">object_id</span><span class="p">)</span>
        <span class="n">user</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">everyone</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s">&quot;3c&quot;</span><span class="p">,</span><span class="nb">str</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">permissions</span><span class="p">)):</span><span class="o">&lt;/</span><span class="n">p</span><span class="o">&gt;&lt;</span><span class="n">p</span><span class="o">&gt;</span>        <span class="k">if</span> <span class="n">owner</span> <span class="o">==</span> <span class="mf">6</span><span class="p">:</span>

            <span class="n">owner</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="n">owner</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="k">if</span> <span class="n">owner</span> <span class="o">==</span> <span class="mf">4</span><span class="p">:</span>
            <span class="n">owner</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>

            <span class="n">owner</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="n">owner</span> <span class="o">==</span> <span class="mf">0</span><span class="p">:</span>

            <span class="n">owner</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="n">owner</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span><span class="o">&lt;/</span><span class="n">p</span><span class="o">&gt;&lt;</span><span class="n">p</span><span class="o">&gt;</span>        <span class="k">if</span> <span class="n">group</span> <span class="o">==</span> <span class="mf">6</span><span class="p">:</span>

            <span class="n">group</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="n">group</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="k">if</span> <span class="n">group</span> <span class="o">==</span> <span class="mf">4</span><span class="p">:</span>
            <span class="n">group</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>

            <span class="n">group</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="n">group</span> <span class="o">==</span> <span class="mf">0</span><span class="p">:</span>

            <span class="n">group</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="n">group</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span><span class="o">&lt;/</span><span class="n">p</span><span class="o">&gt;&lt;</span><span class="n">p</span><span class="o">&gt;</span>        <span class="k">if</span> <span class="n">everyone</span> <span class="o">==</span> <span class="mf">6</span><span class="p">:</span>

            <span class="n">everyone</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="n">everyone</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="k">if</span> <span class="n">everyone</span> <span class="o">==</span> <span class="mf">4</span><span class="p">:</span>
            <span class="n">everyone</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>

            <span class="n">everyone</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="n">everyone</span> <span class="o">==</span> <span class="mf">0</span><span class="p">:</span>

            <span class="n">everyone</span><span class="p">[</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="n">everyone</span><span class="p">[</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span><span class="o">&lt;/</span><span class="n">p</span><span class="o">&gt;&lt;</span><span class="n">p</span><span class="o">&gt;</span>        <span class="k">return</span> <span class="p">{</span><span class="s">&quot;owner&quot;</span><span class="p">:</span> <span class="n">owner</span><span class="p">,</span> <span class="s">&quot;group&quot;</span><span class="p">:</span> <span class="n">group</span><span class="p">,</span> <span class="s">&quot;everyone&quot;</span><span class="p">:</span> <span class="n">everyone</span><span class="p">}</span>
</pre>
</div>
<p>And then I rewrote it to the following:</p>
</p>
<div class="syntax">
<pre>    <span class="k">def</span> <span class="nf">translatePermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">object_id</span><span class="p">):</span>
        <span class="n">rw</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="n">obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">oid</span><span class="o">=</span><span class="n">object_id</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s">&quot;3c&quot;</span><span class="p">,</span><span class="nb">str</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">permissions</span><span class="p">)):</span>

            <span class="k">if</span> <span class="n">value</span> <span class="o">==</span> <span class="mf">6</span><span class="p">:</span>
                <span class="n">r</span> <span class="o">=</span> <span class="bp">True</span>

                <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="mf">4</span><span class="p">:</span>

                <span class="n">r</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="n">w</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="mf">2</span><span class="p">:</span>

                <span class="n">r</span> <span class="o">=</span> <span class="bp">False</span>
                <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="n">r</span> <span class="o">=</span> <span class="bp">False</span>
                <span class="n">w</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="n">rw</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">&quot;read&quot;</span><span class="p">:</span><span class="n">r</span><span class="p">,</span> <span class="s">&quot;write&quot;</span><span class="p">:</span><span class="n">w</span><span class="p">})</span>

        <span class="k">return</span> <span class="p">{</span><span class="s">&quot;owner&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="s">&quot;group&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">1</span><span class="p">],</span> <span class="s">&quot;everyone&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">2</span><span class="p">]}</span>
</pre>
</div>
<p>And then checking for read and write rather than going through each possibility of v, as well as passing an object prior to reduce multiple seeks:</p>
</p>
<div class="syntax">
<pre>    <span class="k">def</span> <span class="nf">checkPermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="n">rw</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s">&quot;3c&quot;</span><span class="p">,</span><span class="nb">str</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">permissions</span><span class="p">)):</span>

            <span class="k">if</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">6</span> <span class="ow">or</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">4</span><span class="p">:</span>

                <span class="n">r</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">r</span> <span class="o">=</span> <span class="bp">False</span>

            <span class="k">if</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">6</span> <span class="ow">or</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">2</span><span class="p">:</span>

                <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">w</span> <span class="o">=</span> <span class="bp">False</span>

            <span class="n">rw</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">&quot;read&quot;</span><span class="p">:</span><span class="n">r</span><span class="p">,</span> <span class="s">&quot;write&quot;</span><span class="p">:</span><span class="n">w</span><span class="p">})</span>
        <span class="k">return</span> <span class="p">{</span><span class="s">&quot;owner&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="s">&quot;group&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">1</span><span class="p">],</span> <span class="s">&quot;everyone&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">2</span><span class="p">]}</span>
</pre>
</div>
<p>But with Python2.5 you can go even further and reduce it to:</p>
</p>
<div class="syntax">
<pre>    <span class="k">def</span> <span class="nf">translatePermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="n">rw</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s">&quot;3c&quot;</span><span class="p">,</span><span class="nb">str</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">permissions</span><span class="p">)):</span>

            <span class="n">r</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">6</span> <span class="ow">or</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">4</span> <span class="k">else</span> <span class="bp">False</span>

            <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">6</span> <span class="ow">or</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">2</span> <span class="k">else</span> <span class="bp">False</span>

            <span class="n">rw</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">&quot;read&quot;</span><span class="p">:</span><span class="n">r</span><span class="p">,</span> <span class="s">&quot;write&quot;</span><span class="p">:</span><span class="n">w</span><span class="p">})</span>
        <span class="k">return</span> <span class="p">{</span><span class="s">&quot;owner&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="s">&quot;group&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">1</span><span class="p">],</span> <span class="s">&quot;everyone&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">2</span><span class="p">]}</span>
</pre>
</div>
<p>From 32 lines at the start to 8 lines in the end! <img src='http://braydon.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  And both together they look like this:</p>
</p>
<div class="syntax">
<pre><span class="k">def</span> <span class="nf">determinePermissions</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="n">obj_usr</span><span class="o">=</span> <span class="p">{</span><span class="s">&quot;owner&quot;</span><span class="p">:</span><span class="n">obj</span><span class="o">.</span><span class="n">owner</span><span class="p">,</span> <span class="s">&quot;group&quot;</span><span class="p">:</span><span class="n">obj</span><span class="o">.</span><span class="n">group</span><span class="p">,</span> <span class="s">&quot;everyone&quot;</span><span class="p">:</span><span class="bp">True</span><span class="p">}</span>

    <span class="n">usr</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s">&quot;owner&quot;</span><span class="p">:</span><span class="n">cherrypy</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;user&#39;</span><span class="p">),</span>

        <span class="s">&quot;group&quot;</span><span class="p">:</span><span class="n">cherrypy</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;group&#39;</span><span class="p">),</span>
        <span class="s">&quot;everyone&quot;</span><span class="p">:</span><span class="bp">True</span>

    <span class="p">}</span>
    <span class="n">perms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">translatePermissions</span><span class="p">(</span><span class="n">object_id</span><span class="p">)</span>
    <span class="n">r</span><span class="p">,</span> <span class="n">w</span> <span class="o">=</span> <span class="bp">False</span><span class="p">,</span> <span class="bp">False</span>

    <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&quot;owner&quot;</span><span class="p">,</span> <span class="s">&quot;group&quot;</span><span class="p">,</span> <span class="s">&quot;everyone&quot;</span><span class="p">]:</span>

        <span class="n">r</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">perms</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="s">&quot;read&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">obj_user</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">==</span> <span class="n">usr</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">else</span> <span class="n">r</span>

        <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">perms</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="s">&quot;write&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">obj_user</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">==</span> <span class="n">usr</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">else</span> <span class="n">w</span>

    <span class="k">if</span> <span class="n">usr</span><span class="p">[</span><span class="s">&quot;owner&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;root&quot;</span><span class="p">:</span>
        <span class="n">r</span><span class="p">,</span> <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span><span class="p">,</span> <span class="bp">True</span>

    <span class="k">return</span> <span class="p">{</span><span class="s">&quot;read&quot;</span><span class="p">:</span><span class="n">r</span><span class="p">,</span> <span class="s">&quot;write&quot;</span><span class="p">:</span><span class="n">w</span><span class="p">}</span><span class="o">&lt;/</span><span class="n">p</span><span class="o">&gt;&lt;</span><span class="n">p</span><span class="o">&gt;</span><span class="k">def</span> <span class="nf">translatePermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>

    <span class="n">rw</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">struct</span><span class="o">.</span><span class="n">unpack</span><span class="p">(</span><span class="s">&quot;3c&quot;</span><span class="p">,</span><span class="nb">str</span><span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">permissions</span><span class="p">)):</span>

        <span class="n">r</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">6</span> <span class="ow">or</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">4</span> <span class="k">else</span> <span class="bp">False</span>

        <span class="n">w</span> <span class="o">=</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">6</span> <span class="ow">or</span> <span class="n">v</span> <span class="o">==</span> <span class="mf">2</span> <span class="k">else</span> <span class="bp">False</span>

        <span class="n">rw</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">&quot;read&quot;</span><span class="p">:</span><span class="n">r</span><span class="p">,</span> <span class="s">&quot;write&quot;</span><span class="p">:</span><span class="n">w</span><span class="p">})</span>
    <span class="k">return</span> <span class="p">{</span><span class="s">&quot;owner&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="s">&quot;group&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">1</span><span class="p">],</span> <span class="s">&quot;everyone&quot;</span><span class="p">:</span> <span class="n">rw</span><span class="p">[</span><span class="mf">2</span><span class="p">]}</span>
</pre>
</div>
<p>Poetry!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://braydon.com/blog/2008/01/the-importance-in-rewriting-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
