<?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>fleshyorgans &#187; programming</title> <atom:link href="http://fleshy.org.nz/category/programming/feed/" rel="self" type="application/rss+xml" /><link>http://fleshy.org.nz</link> <description>Essays from a guy with too much pontification on his hands</description> <lastBuildDate>Tue, 10 Jan 2012 06:16:41 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Link: A Brief, Incomplete, and Mostly Wrong History of Programming Languages</title><link>http://fleshy.org.nz/2010/05/11/link-a-brief-incomplete-and-mostly-wrong-history-of-programming-languages/</link> <comments>http://fleshy.org.nz/2010/05/11/link-a-brief-incomplete-and-mostly-wrong-history-of-programming-languages/#comments</comments> <pubDate>Tue, 11 May 2010 15:24:39 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[programming]]></category> <category><![CDATA[tumblr]]></category> <category><![CDATA[code]]></category> <category><![CDATA[computer science]]></category> <category><![CDATA[funlinks]]></category> <category><![CDATA[languages]]></category> <category><![CDATA[links]]></category> <guid
isPermaLink="false">http://fleshyorgans.tumblr.com/post/589786575</guid> <description><![CDATA[<a
href="http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html">One Div Zero: A Brief, Incomplete, and Mostly Wrong History of Programming Languages</a>]]></description> <content:encoded><![CDATA[<p><a
href="http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html">One Div Zero: A Brief, Incomplete, and Mostly Wrong History of Programming Languages</a><br
/></p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2010/05/11/link-a-brief-incomplete-and-mostly-wrong-history-of-programming-languages/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Coding: Rails Issues with :include</title><link>http://fleshy.org.nz/2008/02/23/coding-rails-issues-with-include/</link> <comments>http://fleshy.org.nz/2008/02/23/coding-rails-issues-with-include/#comments</comments> <pubDate>Sat, 23 Feb 2008 17:10:26 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[code]]></category> <category><![CDATA[rails]]></category> <category><![CDATA[ruby]]></category> <guid
isPermaLink="false">http://fleshy.org.nz/yum/2008/02/23/coding-rails-issues-with-include/</guid> <description><![CDATA[This is a sort of code analysis and something I discovered with :include usage in Rails. (This is in rails 1.1.6, so YMMV. I believe the latest Rails opts to use inner SELECTs rather than JOIN statements. Also, this is kind of long.) I have the following association set that represents a document repository. User [...]]]></description> <content:encoded><![CDATA[<p>This is a sort of code analysis and something I discovered with :include usage in Rails. (This is in rails 1.1.6, so YMMV. I believe the latest Rails opts to use inner SELECTs rather than JOIN statements.</p><p> Also, this is kind of long.)<br
/> <span
id="more-805"></span></p><p> I have the following association set that represents a document repository.<br
/> <br/><br
/> User 1-n Folders<br
/> User 1-n Roles<br
/> Folder 1-n Documents<br
/> Documents n-n Brands<br
/> <br/><br
/> Folders n-n Viewer Roles<br
/> Folders n-n Manager Roles<br
/> <br/><br
/> Lastly, Users n -(polymorphic through)- n Brands</p><p> In order to display a tree of Folders a given user can view, that User must<br
/> be a manager or viewer of a Folder, and his Brands contain Brand of at<br
/> least one Document under that Folder (a Document associated with a Brand under a folder lets the user view that Folder iff that user has the Brand.)</p><p> So the way this was originally implemented was a recursive loop<br
/> something like this:</p><blockquote><p> def show_subfolders(folder)<br
/> User.folders.each do |folder|<br
/> show_subfolders(folder)<br
/> end<br
/> end</p><p>Class User<br
/> def folders<br
/> Folder.find(:all,:conditions => &#8216;parent = folder&#8217;,<br
/> :include => [:manager_roles, :viewer_roles, {:documents => :brands]]<br
/> ).each do<br
/> |folder|<br
/> if method_to_check_brands(folder) &#038;&#038; method_to_check_view_perms(folder)<br
/> yield(folder)<br
/> end<br
/> end<br
/> end</p></blockquote><p> The eventual problems that developed with this logic were the following:</p><ol><li>second-level includes are problematic in Rails, this generated<br
/> outer joins against seven tables</li><li>massive join, recursively called. I believe the Big O* is (c!)^n,<br
/> glancing quickly</li><li>Indexes don&#8217;t help, because the outer joins sort of blow the<br
/> performance gains away</li><li>All data is being selected, so just sheer amount of data transfer<br
/> slowed things down</li><li>The yield adds a lot of crap to the callstack</li><li>Brand and View/Manage permissioning was already happening in the code</li></ol><p> With 245 documents under 30 folders, mysql logged slow queries that<br
/> had to examine 320,000 rows &#8212; and that was multiple times.</p><p> The solution? Remove the :includes. Since permissioning and<br
/> restriction was already happening in code, I let Rails do its own<br
/> thing and select when necessary. This lowered the response time from<br
/> 10+ seconds for page view to 0.5 seconds. (And for what it&#8217;s worth,<br
/> doing the join statements manually, or removing the second-level :includes only brings it down to 2 or 3 seconds.)</p><p>By reducing the stuff that needs to join, indices are are used more<br
/> efficiently, and letting Rails do a find for Folder.documents on each<br
/> iteration ends up being a lot faster than trying to join with the<br
/> view/manage/brands permissions.</p><p> The More You Know!</p><p>* It&#8217;s been over a decade since I actually figured out the order of an algorithm. I&#8217;m sort of guessing, here.</p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2008/02/23/coding-rails-issues-with-include/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Quick and dirty hack for acts_as_attachment file movement</title><link>http://fleshy.org.nz/2007/12/10/quick-and-dirty-hack-for-acts_as_attachment-file-movement/</link> <comments>http://fleshy.org.nz/2007/12/10/quick-and-dirty-hack-for-acts_as_attachment-file-movement/#comments</comments> <pubDate>Mon, 10 Dec 2007 20:59:17 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[ruby]]></category> <guid
isPermaLink="false">http://fleshy.org.nz/yum/archives/786</guid> <description><![CDATA[Say you&#8217;re working on something that uses acts_as_attachment. Also say that the person who wrote it decided that all the different models&#8217; attachments would save in the same place. Also suppose that you want to change the file location of all those uploads. Well, here&#8217;s a quick and dirty migration that&#8217;ll save you from moving [...]]]></description> <content:encoded><![CDATA[<p>Say you&#8217;re working on something that uses acts_as_attachment. Also say that the person who wrote it decided that all the different models&#8217; attachments would save in the same place. Also suppose that you want to change the file location of all those uploads.</p><p><em>Well</em>, here&#8217;s a quick and dirty migration that&#8217;ll save you from moving files manually.</p><p><a
href="http://pastie.caboo.se/126613">Automove Files for Storage Changes, with acts_as_attachment</a></p><p>Originally I wanted to do something like  Attachment.new( OldAttachment.find(?).attributes ), but there were issues with that because acts_as_attachment wants uploaded data to be a tmp file or some crap. This ended up being the easier way, all in all.</p><p>Use with care.<br
/></p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2007/12/10/quick-and-dirty-hack-for-acts_as_attachment-file-movement/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Seriously Word Press, WTH?</title><link>http://fleshy.org.nz/2007/11/04/seriously-word-press-wth/</link> <comments>http://fleshy.org.nz/2007/11/04/seriously-word-press-wth/#comments</comments> <pubDate>Mon, 05 Nov 2007 04:30:16 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[cats]]></category> <category><![CDATA[code]]></category> <category><![CDATA[php]]></category> <guid
isPermaLink="false">http://fleshy.org.nz/yum/archives/777</guid> <description><![CDATA[While trying to figure out how to remove formatting from &#8216;wp_list_cats&#8217; in Word Press, I discovered this awesome bit. Click the thumbnail for the full glory of the code. You will notice that in my screenshot, the final function call to &#8216;list_cats&#8217; at the end is truncated. This is because there are eighteen parameters. Again [...]]]></description> <content:encoded><![CDATA[<p>While trying to figure out how to remove formatting from &#8216;wp_list_cats&#8217; in Word Press, I discovered this awesome bit. Click the thumbnail for the full glory of the code.<br
/> <a
class="imagelink" href="http://fleshy.org.nz/yum/wp-content/uploads/2007/11/wp_list_cats.png" title="WP List Cats Insanity!"><img
id="image775" src="http://src.sencha.io//http://fleshy.org.nz/yum/wp-content/uploads/2007/11/wp_list_cats.thumbnail.png" alt="WP List Cats Insanity!" /></a></p><p>You will notice that in my screenshot, the final function call to &#8216;list_cats&#8217; at the end is truncated. This is because there are <strong>eighteen parameters</strong>. Again with the clicking.<br
/> <a
class="imagelink" href="http://fleshy.org.nz/yum/wp-content/uploads/2007/11/list_cats.png" title="list_cats even more insane!"><img
id="image776" src="http://src.sencha.io//http://fleshy.org.nz/yum/wp-content/uploads/2007/11/list_cats.thumbnail.png" alt="list_cats even more insane!" /></a></p><p>Also, there&#8217;s an awesome feature in the WP DB object such that if one requeries the same table on the same page, apparently pagination offset is lost. This means that the main index page listing posts cannot also have a recent posts list &#8212; because you either will have recent posts starting with whatever the main list offset is, or you will only ever have as many posts on the index page as the recent posts query returns.</p><p>WIN!<br
/></p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2007/11/04/seriously-word-press-wth/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PHP and Payflow Pro FOR THE LOSE</title><link>http://fleshy.org.nz/2007/10/29/php-and-payflow-pro-for-the-lose/</link> <comments>http://fleshy.org.nz/2007/10/29/php-and-payflow-pro-for-the-lose/#comments</comments> <pubDate>Mon, 29 Oct 2007 20:51:55 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[php]]></category> <category><![CDATA[ruby]]></category> <guid
isPermaLink="false">http://fleshy.org.nz/yum/archives/774</guid> <description><![CDATA[Posting this cause I wan&#8217;t aware and the only other post I found was dated January. Since Paypal purchased Verisign they are discontinuing the pfpro extension to PHP. And in fact, what I&#8217;m reading is that Sept 2009 is the end of life for that functionality, meaning requests will not work beyond that point. For [...]]]></description> <content:encoded><![CDATA[<p>Posting this cause I wan&#8217;t aware and the only other post I found was dated January.</p><p>Since Paypal purchased Verisign they are discontinuing the pfpro extension to PHP. And in fact, what I&#8217;m reading is that Sept 2009 is the end of life for that functionality, meaning requests will not work beyond that point.</p><p>For sites using pfpro that ned to transition, the solution is<br
/> 1) use the java sdk<br
/> 2) use the .net sdk<br
/> 3) write your own api to utilize curl and https<br
/> 4) use a public api for curl and https a la <a
href="http://www.paypaldeveloper.com/pdn/board/message?message.uid=28775#U28775">This post from the paypal developer forum</a></p><p>ALSO&#8230;<br
/> this means if you&#8217;re installing a 64 bit system, you&#8217;re pretty much screwed because there are no new libraries/binaries released for pfpro under that platform&#8230; unless you&#8217;re running a .net or java solution.</p><p>Sucks.</p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2007/10/29/php-and-payflow-pro-for-the-lose/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Vim tip: keyboard shortcuts</title><link>http://fleshy.org.nz/2007/10/26/vim-tip-keyboard-shortcuts/</link> <comments>http://fleshy.org.nz/2007/10/26/vim-tip-keyboard-shortcuts/#comments</comments> <pubDate>Fri, 26 Oct 2007 15:32:23 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[code]]></category> <category><![CDATA[keyboard]]></category> <category><![CDATA[vim]]></category> <guid
isPermaLink="false">http://fleshy.org.nz/yum/archives/771</guid> <description><![CDATA[Finally got around to learning how to define keyboard shortucts in vim. It&#8217;s easy! map &#60;desiredkey&#62; &#60;targetaction&#62; So, for example, I split windows vertically and want to navigate via ctrl+pagedown or pageup. Here&#8217;s what I did (include &#60; and &#62; when defining) map &#60;c-pageup&#62; &#60;c-w&#62;h map &#60;c-pagedown&#62; &#60;c-w&#62;l Found via a vim wiki search [ad#Google [...]]]></description> <content:encoded><![CDATA[<p>Finally got around to learning how to define keyboard shortucts in vim. It&#8217;s easy!</p><p><code><br
/> map &lt;desiredkey&gt; &lt;targetaction&gt;<br
/> </code><br
/> So, for example, I split windows vertically and want to navigate via ctrl+pagedown or pageup.</p><p>Here&#8217;s what I did (include &lt; and &gt; when defining)<br
/> <code><br
/> map &lt;c-pageup&gt; &lt;c-w&gt;h<br
/> map &lt;c-pagedown&gt; &lt;c-w&gt;l<br
/> </code></p><p>Found via <a
href="http://vim.wikia.com/wiki/Alternative_tab_navigation">a vim wiki search</a><br
/> [ad#Google Adsense small leaderboard]<br
/></p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2007/10/26/vim-tip-keyboard-shortcuts/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Vim awesomeness.</title><link>http://fleshy.org.nz/2007/09/28/vim-awesomeness/</link> <comments>http://fleshy.org.nz/2007/09/28/vim-awesomeness/#comments</comments> <pubDate>Fri, 28 Sep 2007 17:56:17 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[code]]></category> <category><![CDATA[vim]]></category> <guid
isPermaLink="false">http://fleshy.org.nz/yum/archives/763</guid> <description><![CDATA[If you use Vim as your text editor, try this :TOhtml This will generate an HTML version of your source code, complete with color scheme. It&#8217;s pretty sweet. Example here (opens a new window) This just tickles me.]]></description> <content:encoded><![CDATA[<p>If you use Vim as your text editor, try this<br
/> :TOhtml</p><p>This will generate an HTML version of your source code, complete with color scheme. It&#8217;s pretty sweet.</p><p><a
target="_new" href="/part_item_rga.rb.html">Example here</a> (opens a new window)</p><p>This just tickles me.<br
/></p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2007/09/28/vim-awesomeness/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Odd SQL Server errors</title><link>http://fleshy.org.nz/2007/08/31/odd-sql-server-errors/</link> <comments>http://fleshy.org.nz/2007/08/31/odd-sql-server-errors/#comments</comments> <pubDate>Fri, 31 Aug 2007 18:01:13 +0000</pubDate> <dc:creator>Jonathan Warner</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[code]]></category> <category><![CDATA[sql]]></category> <guid
isPermaLink="false">http://fleshy.org.nz/yum/archives/759</guid> <description><![CDATA[Maybe someone will find this post and explain to me why SQL Server behaves like this. My question isn&#8217;t &#8220;how should I rewrite this query&#8221;, but &#8220;why does SQL Server act like this&#8221;. The behavior I see is that for some reason it&#8217;s easier to do TOP bignumber than TOP smallnumber. In my instance, TOP [...]]]></description> <content:encoded><![CDATA[<p>Maybe someone will find this post and explain to me why SQL Server behaves like this. My question isn&#8217;t &#8220;how should I rewrite this query&#8221;, but &#8220;why does SQL Server act like this&#8221;. The behavior I see is that for some reason it&#8217;s easier to do TOP bignumber than TOP smallnumber. In my instance, TOP 3 takes up to 2 minutes to return results, whereas TOP 5 is instantaneous.</p><p><span
id="more-759"></span><br
/> Situation, selecting the first 3 Announcements for particular User Roles at a particular Organization.</p><p>There is an announcement table and a meta table containing org/role join information.</p><p>The (somewhat crappy) query is like so:<br
/> <code>SELECT TOP 3 b.announcement_title FROM announcements b<br
/> WHERE b.anouncement_id IN (<br
/> SELECT<br
/> &nbsp;&nbsp;DISTINCT a.announcement_id<br
/> FROM<br
/> &nbsp;&nbsp;announcements b, announcement_role_org aro<br
/> WHERE<br
/> &nbsp;&nbsp;aro.announcement_id = b.announcement_id<br
/> &nbsp;&nbsp; AND<br
/> &nbsp;&nbsp;aro.role_id = $role_id<br
/> &nbsp;&nbsp; AND<br
/> &nbsp;&nbsp;aro.org_id = $org_id<br
/> )<br
/> </code></p><p>Yes, I know it should have been written as a join.</p><p>This is the problem:</p><ul><li>When the outer select says TOP 3, the server chugs forever and doesn&#8217;t return a result (at least, doesn&#8217;t return a result within 2 minutes, I killed the select after that time limit).</li><li>When the outer select says TOP 5 or TOP 6, it returns results fairly instantly</li></ul><p>WTF?<br
/> For the record, the inner select for the $role and $org I specified only ever return 6 results.</p><p>Oh, lastly&#8230; if I say NOT IN (returns 210 results), it doesn&#8217;t seem to matter what TOP value I have.</p><p>WHY???<br
/></p> ]]></content:encoded> <wfw:commentRss>http://fleshy.org.nz/2007/08/31/odd-sql-server-errors/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
