<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>The Avid Mind - Home</title>
  <id>tag:theavidmind.upstrat.com,2008:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.7.0">Mephisto Noh-Varr</generator>
  <link href="http://theavidmind.upstrat.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://theavidmind.upstrat.com/" rel="alternate" type="text/html"/>
  <updated>2007-11-23T10:06:43Z</updated>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-11-23:1568</id>
    <published>2007-11-23T08:37:00Z</published>
    <updated>2007-11-23T10:06:43Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/11/23/a-simple-way-to-generate-formatted-pdf-documents" rel="alternate" type="text/html"/>
    <title>A Simple Way to Generate formatted PDF Documents</title>
<content type="html">
            &lt;p&gt;&lt;img src='http://theavidmind.upstrat.com/assets/2007/11/23/documents-small.jpg' alt='' /&gt;&lt;/p&gt;


	&lt;h3&gt;The Problem&lt;/h3&gt;


	&lt;p&gt;Most of the applications we make are in aid of current manual systems.  The whole reason clients come to us is because they want to streamline and automate parts of their processes but they still have to deal with the reality of the current, paper-based way of doing things.  So it happens that recently I&#8217;ve gotten a sudden influx of requests to be able to generate printable pre-filled forms.&lt;/p&gt;


	&lt;p&gt;There are multiple ways to go about doing this.  The easiest way would&#8217;ve been to just allow the user to click &#8216;print&#8217; on their browser and serve them a formatted print.css page.  However, a couple of projects back we ran into a problem using this approach &#8211; we could never get the same result across multiple computers.  We tried restricting the browsers used to firefox but even that didn&#8217;t play nice with the differing operating systems.  Using &lt;span class='caps'&gt;CSS&lt;/span&gt; to generate printable forms wasn&#8217;t an option.&lt;/p&gt;


	&lt;p&gt;The next ideal way would be to be able to generate a pdf using from an html output.  This would be great because we could maybe use the existing templates and just generate the pdf from that.  After looking around a while it seemed that &lt;a href='http://sublog.subimage.com/articles/2007/05/29/html-css-to-pdf-using-ruby-on-rails'&gt;PrinceXML was the way to go&lt;/a&gt;.  Unfortunately for me, it didn&#8217;t come free.  Alternatives such as &lt;a href='http://htmldoc.rubyforge.org/'&gt;&lt;span class='caps'&gt;HTML&lt;/span&gt; Doc&lt;/a&gt; just didn&#8217;t cut it.&lt;/p&gt;


	&lt;p&gt;Next in my quest was&lt;a href='http://www.accesspdf.com/pdftk/'&gt; pdftk&lt;/a&gt;  I thought maybe I could just design the templates by hand using Scribus and then just fill_form the values using pdftk.  Again I hit a roadblock when I found that some of the forms had dynamic content (e.g. tables) that couldn&#8217;t be handled by this approach.&lt;/p&gt;


	&lt;p&gt;I was back to using &lt;a href='http://ruby-pdf.rubyforge.org/pdf-writer/'&gt;&lt;span class='caps'&gt;PDF&lt;/span&gt;::Writer&lt;/a&gt;.  The problem with pdf-writer is that it&#8217;s pretty raw.  It allows you to do a lot of things with PDFs but you have to deal with lines, points, x/y coordinates, and all of the details.  I didn&#8217;t have the time nor the patience to deal with all that for the amount of printables that were coming in.&lt;/p&gt;


	&lt;h3&gt;The Solution?&lt;/h3&gt;


	&lt;p&gt;So I decided to write my own little library that would fix all that.   Introducing &lt;span class='caps'&gt;PDF&lt;/span&gt;::Cell &#8211; it&#8217;s a library based on &lt;span class='caps'&gt;PDF&lt;/span&gt;::Writer that allows you to layout documents in a straightforward manner without thinking about the nitty-gritty details about how exactly to position the elements.  The model for laying out stuff is loosely based on &lt;a href='http://code.whytheluckystiff.net/shoes/'&gt;Ruby Shoes&#8217;s&lt;/a&gt; concept of stacks and flows.  Here&#8217;s an example:&lt;/p&gt;


&lt;code&gt;
pdf = PDF::Writer.new
biodata = PDF::Cell::Base.new(pdf)

biodata.build :width =&amp;gt; 500, :font_size =&amp;gt; 8 do
  header &quot;Crew File #245: Jack Black (2/M of MV Nautilus)&quot;, :shaded =&amp;gt; true, 
                                                            :font_size =&amp;gt; 15 

  desc &quot;The Content&quot; 
  cell :width =&amp;gt; 375 do
    cell :width =&amp;gt; 125 do
      text &quot;&amp;lt;b&amp;gt;Given Name&amp;lt;/b&amp;gt;&quot; 
      text &quot;Jack&quot; 
    end
    cell :width =&amp;gt; 125 do
      text &quot;&amp;lt;b&amp;gt;Middle Name&amp;lt;/b&amp;gt;&quot; 
      text &quot;James&quot; 
    end
    cell :width =&amp;gt; 125 do
      text &quot;&amp;lt;b&amp;gt;Family Name&amp;lt;/b&amp;gt;&quot; 
      text &quot;Black&quot; 
    end
    cell :width =&amp;gt; 250 do
      text &quot;&amp;lt;b&amp;gt;Address&amp;lt;/b&amp;gt;&quot; 
      text &quot;#124 Main Street&quot; 
    end
    cell :width =&amp;gt; 125 do
      text &quot;&amp;lt;b&amp;gt;Contact No&amp;lt;/b&amp;gt;&quot; 
      text &quot;123-456-789&quot; 
    end
  end
  cell :width =&amp;gt; 125, :height =&amp;gt; 125 do
    text &quot;Photo Here&quot; 
  end
end
&lt;/code&gt;

	&lt;p&gt;And &lt;a href='http://theavidmind.upstrat.com/assets/2007/11/23/biodata_result.pdf'&gt;here&#8217;s the result of the above code&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Now for the explanation.  The overall box is given a width of 500. (it uses pdf-writer&#8217;s measurements not mine)  The width is strict &#8211;  meaning everything else will adjust, just not the width.  We add a cell to the box with 375 width &#8211; let&#8217;s call this the &#8220;Content&#8221; box.  Within the Content box we add 3 cells each with a width of 125.  These 3 boxes add up to exactly 375 &#8211; the limit of the Content box.  Then we add another cell with a width of 250.  Clearly this won&#8217;t fit into the Content box&#8217;s width so &lt;span class='caps'&gt;PDF&lt;/span&gt;::Cell automatically puts it below the previous 3 cells!  And that&#8217;s basically it.  Using that simple concept of cells you can potentially generate any layout your document needs.&lt;/p&gt;


	&lt;p&gt;I recently added support for tables within cells.  Images within cells are coming up shortly although, if you know how to use pdf-writer, you can hack it yourself for now.&lt;/p&gt;


	&lt;h3&gt;Installation&lt;/h3&gt;


	&lt;p&gt;To install just copy/paste the following into your rails root directory:&lt;/p&gt;


&lt;code&gt;
ruby script/plugin install svn://svn.upstrat.com/plugins/pdf_cell/trunk
&lt;/code&gt;

	&lt;p&gt;That&#8217;s it! You should be ready to go.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-11-04:1567</id>
    <published>2007-11-04T08:00:00Z</published>
    <updated>2007-11-23T08:37:08Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/11/4/speeding-up-ruby-with-lua" rel="alternate" type="text/html"/>
    <title>Speeding up Ruby with Lua</title>
<content type="html">
            &lt;p&gt;&lt;img src='http://theavidmind.upstrat.com/assets/2007/11/4/886183_59063888.jpg' alt='' /&gt;&lt;/p&gt;


	&lt;p&gt;Everyone knows &lt;a href='http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&#38;lang=all'&gt;ruby is slow&lt;/a&gt;.  That&#8217;s why I find that the ruby community is more obsessed with optimization than any other.  One of the solutions tossed around to improve the performance of ruby programs is to forgo ruby in the complex computations and &lt;a href='http://on-ruby.blogspot.com/2006/07/rubyinline-making-making-things-faster.html'&gt;switch&lt;/a&gt; &lt;a href='http://fixnum.org/ruby_c.html'&gt;to&lt;/a&gt; &lt;a href='http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html'&gt;C.&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;I don&#8217;t doubt this will work.  In fact, based on all the stuff I&#8217;ve read, this is really a great way to speed up your app while still using the wonder (and joy) that is ruby.  However I am loathe to go back to C.  I mean, the whole reason I moved to ruby was because I wanted to use a high-level language and all the cool concepts not available to lower level languages.&lt;/p&gt;


	&lt;p&gt;Enter &lt;a href='http://www.lua.org/'&gt;Lua&lt;/a&gt;.  I&#8217;ve been reading about Lua for a while now.  I know it&#8217;s &lt;a href='http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&#38;lang=all'&gt;fast&lt;/a&gt; ; it&#8217;s used in WoW and a &lt;a href='http://www.lua.org/uses.html'&gt;whole lot of other stuff&lt;/a&gt;.  It&#8217;s also a high level language which I find has a lot in common with lisp (something I&#8217;ve always wanted to learn).  It&#8217;s also designed to be embedded into applications; much the same way ruby was initially designed as a tool for admins.  It got me thinking that maybe Lua can help me speed up Ruby.&lt;/p&gt;


	&lt;p&gt;I found a nifty little library that allows lua to be called from within ruby called &lt;a href='http://rubyluabridge.rubyforge.org/'&gt;rubyluabridge&lt;/a&gt;.  I installed it on my machine and decided to run the classic fibonacci benchmark test.&lt;/p&gt;


	&lt;h4&gt;Code&lt;/h4&gt;


fib.rb
&lt;code&gt;
t = Time.now
def fib(n)
  if n == 1 or n == 2
    return 1
  else
    return fib(n-1) + fib(n-2)
  end
end

answer = fib(ARGV[0].to_i)
puts &quot;Answer: #{answer}&quot; 
puts &quot;Calculation Time: #{Time.now - t}&quot; 
&lt;/code&gt;

new_fib.rb
&lt;code&gt;
t = Time.now
require 'rubyluabridge'
l = Lua::State.new
l.eval &amp;lt;&amp;lt;-LUA_END
  function fib(n)
    if n == 1 or n == 2 then 
      return 1
    else
      return fib(n-1) + fib(n-2)
    end
  end
LUA_END

l.eval &quot;answer = fib(#{ARGV[0]})&quot; 
puts &quot;Answer: #{l.answer.to_i}&quot; 
puts &quot;Calculation Time: #{Time.now - t}&quot; 
&lt;/code&gt;

	&lt;p&gt;Here are the results:&lt;/p&gt;


fib.rb 20
&lt;pre&gt;
Answer: 6765
Calculation Time: 0.071339
&lt;/pre&gt;

new_fib.rb 20
&lt;pre&gt;
Answer: 6765
Calculation Time: 0.034658
&lt;/pre&gt;

fib.rb 33
&lt;pre&gt;
Answer: 3524578
Calculation Time: 11.272733
&lt;/pre&gt;

new_fib.rb 33
&lt;pre&gt;
Answer: 3524578
Calculation Time: 2.103146
&lt;/pre&gt;

	&lt;h4&gt;Conclusion&lt;/h4&gt;


	&lt;p&gt;There is definitely an improvement in the processing time of the app with lua embedded.  This is more apparent the more complex the calculation.&lt;/p&gt;


	&lt;p&gt;But the most striking thing is that there is very little change in the syntax of the code.  If you&#8217;ll look at the embedded lua function fib(), it is almost identical to the ruby original.  We got all that speed (around 500% in this example) for code that is essentially similar.  I find it  looks a lot better then lisp. (parentheses anyone?)&lt;/p&gt;


	&lt;p&gt;So there you have it, embedding lua into ruby for a quick performance boost.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-10-30:1418</id>
    <published>2007-10-30T01:55:00Z</published>
    <updated>2007-10-30T01:56:14Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/10/30/two-factor-authentication" rel="alternate" type="text/html"/>
    <title>Two-factor Authentication</title>
<content type="html">
            &lt;p&gt;&lt;img src='http://theavidmind.upstrat.com/assets/2007/10/30/cctv.png' alt='' /&gt;&lt;/p&gt;


	&lt;p&gt;Website authentication is usually done with using the username-password model:  The user has a unique username and a password to prove that he owns that username.  The programmer and the system administrator can put in all the encryption and security updates they can but if a hacker somehow manages to access a username and password (e.g. admin / password) then all the other measures become useless.&lt;/p&gt;


	&lt;p&gt;Enter multifactor-authentication.  One-factor authentication is something you know &#8211; your username and password.  The second factor is usually something you have &#8211; some form of key.  On the web, it is not so easy to implement two-factor authentication.  Usually, what passes for two-factor authentication &lt;a href='http://worsethanfailure.com/Articles/WishItWas-TwoFactor-.aspx'&gt;doesn&#8217;t quite cut it.&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;There is an interesting idea out there though that aims to solve this called &lt;a href='http://benlog.com/articles/2007/02/06/beamauth-two-factor-web-authentication-with-a-bookmark/'&gt;BeamAuth&lt;/a&gt;  The idea is simpe &#8211; use bookmarks as a key.  Using a little javascript, a bookmark, and the little-known fragment identifier, Ben Adida has developed a system that allows the user to securely send an encrypted key along with the login information.  Seamless two-factor authentication!&lt;/p&gt;


	&lt;p&gt;BeamAuth is a new idea and I haven&#8217;t heard of any sites that use it yet.  Unfortunately the demo app doesn&#8217;t work right now so I haven&#8217;t really seen it in action.  However, the idea is simple and it looks easy enough to implement.  I haven&#8217;t seen any holes in the idea yet maybe &lt;a href='http://www.schneier.com'&gt;Bruce Schneier&lt;/a&gt; or &lt;a href='http://www.grc.com'&gt;Steve Gibson&lt;/a&gt; would know better but I don&#8217;t think they&#8217;ve heard of the idea yet.  I might try it out myself soon and see if it&#8217;s as effective as it seems.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-10-25:1280</id>
    <published>2007-10-25T13:55:00Z</published>
    <updated>2007-10-25T13:57:31Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/10/25/and-we-re-back" rel="alternate" type="text/html"/>
    <title>And...We're Back</title>
<content type="html">
            &lt;p&gt;Wow.  Can&#8217;t believe it&#8217;s been months since we last updated the blog.  We&#8217;ve been very busy.  Well, I think we&#8217;ve got things more or less under control now and we can go back to blogging.  Stay tuned!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-05-16:41</id>
    <published>2007-05-16T11:00:00Z</published>
    <updated>2007-05-16T11:01:22Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/5/16/ruby-presentation-in-malaysia" rel="alternate" type="text/html"/>
    <title>Ruby Presentation in Malaysia</title>
<content type="html">
            &lt;p&gt;I recently went to Malaysia to do a quick workshop on Ruby on Rails for the Open Source Health Care Alliance.  Presenting with me was Aizat.  I think the workshop went well.  Here&#8217;re the slides.&lt;/p&gt;


&amp;lt;object type='application/x-shockwave-flash' height='348' width='425' data='https://s3.amazonaws.com:443/slideshare/ssplayer.swf?id=48391&#38;doc=ruby-on-rails-48391-14201'&gt;&amp;lt;param name='movie' value='https://s3.amazonaws.com:443/slideshare/ssplayer.swf?id=48391&#38;doc=ruby-on-rails-48391-14201' /&gt;&amp;lt;/object&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>Cyx</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-04-23:40</id>
    <published>2007-04-23T18:25:00Z</published>
    <updated>2007-04-23T18:33:59Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/4/23/trouble-with-rspec-controller-specs" rel="alternate" type="text/html"/>
    <title>Trouble with RSpec Controller Specs</title>
<content type="html">
            &lt;p&gt;I had a lot of head scratching just moments ago. Basically it had something to do with controller specs and our in-house plugin ActiveCRUD.&lt;/p&gt;


	&lt;p&gt;What happens is when you do something like :&lt;/p&gt;


&lt;code&gt;
context &quot;the Category create page&quot; do
  controller_name :categories

  specify &quot;should render new if parameters are invalid&quot; do
    post :create, :category =&amp;gt; valid_category(:name =&amp;gt; nil)

    response.should render_template(:new)
  end
end
&lt;/code&gt;

	&lt;p&gt;You aren&#8217;t able to even reach &lt;em&gt;response.should render&lt;/em&gt; since doing the &lt;em&gt;post :create&lt;/em&gt; will raise the exception.&lt;/p&gt;


	&lt;p&gt;What happens in our plugin is the same with most of beast-inspired applications. You have code like&lt;/p&gt;


&lt;code&gt;
def create
  @category.attributes = params[:category]
  @category.save!
  redirect_to category_path
end

private
  def rescue_action(exception)
    # render invalid model here, etc
  end
end
&lt;/code&gt;

	&lt;p&gt;But rSpec happily overrides the controller&#8217;s rescue_action method, which means all the expectations we have from our rescue_action are gone.&lt;/p&gt;


	&lt;p&gt;Right now I did some tweaks to our plugin, catching the exception manually and calling rescue_action_with_validation and then using alias_method_chain.&lt;/p&gt;


	&lt;p&gt;Hopefully I&#8217;ll have a more elegant solution in the future. But hey, they say that tests transform our code into more manageable pieces. I hope that&#8217;s what&#8217;s happening now.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>Cyx</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-04-22:39</id>
    <published>2007-04-22T17:55:00Z</published>
    <updated>2007-12-17T15:40:58Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/4/22/valid-model-parameters" rel="alternate" type="text/html"/>
    <title>Valid Model Parameters</title>
<content type="html">
            &lt;p&gt;While writing tests in rails, we frequently use the pattern :&lt;/p&gt;


&lt;code&gt;
@article = create_article(:title =&amp;gt; nil)
@article.should have_at_least(1).error_on(:title)
&lt;/code&gt;

	&lt;p&gt;and in the bottom of the test, we define a create_article. For the next model, say Project, you define also another one in the bottom.&lt;/p&gt;


	&lt;p&gt;Previously at our company, we&#8217;ve been extracting most of our valid model parameters into a module like so&lt;/p&gt;


&lt;code&gt;
module ValidParameters
  def valid_article
    { :title =&amp;gt; 'My Article' }
  end
end
&lt;/code&gt;

	&lt;p&gt;Which is very useful when you need to create a model, and the last thing we want is unnecessarily having &lt;span class='caps'&gt;DAMP&lt;/span&gt; code.&lt;/p&gt;


	&lt;p&gt;But what of combining the two approaches?&lt;/p&gt;


	&lt;p&gt;I just created a module, which I&#8217;ll extract to a plugin at a future date which does exactly that. Basically you add parameters with a &lt;span class='caps'&gt;DSL&lt;/span&gt;-like syntax :&lt;/p&gt;


&lt;code&gt;
module ValidParameters
  valid :article, :title =&amp;gt; 'My Article'
  valid :project, :name =&amp;gt; 'Hedgehog', :owner_id =&amp;gt; 1
end
&lt;/code&gt;

	&lt;p&gt;and in your tests you can then do either :&lt;/p&gt;


&lt;code&gt;
post :create, :article =&amp;gt; valid_article
&lt;/code&gt;

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


&lt;code&gt;
lamba { create_article }.should have_difference(Article, :count)
&lt;/code&gt;

	&lt;p&gt;or finally with invalid parameters&lt;/p&gt;


&lt;code&gt;
lambda { create_article(:title =&amp;gt; nil) }.should_not have_difference(Article, :count)
&lt;/code&gt;

	&lt;p&gt;Neat huh?&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>Cyx</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-04-11:37</id>
    <published>2007-04-11T16:28:00Z</published>
    <updated>2007-04-11T16:37:17Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/4/11/safari-http-accept-language" rel="alternate" type="text/html"/>
    <title>Safari http-accept-language</title>
<content type="html">
            &lt;p&gt;Recently I&#8217;ve been working with a Globalized rails application. I&#8217;ve been testing the app heavily, and often bouncing back between internet explorer and Firefox in order to make sure things are working.&lt;/p&gt;


	&lt;p&gt;After my latest upload though, the client said that the application was throwing an application error. I asked which page. He said the homepage. That made me wonder a lot.&lt;/p&gt;


	&lt;p&gt;After some hours I suddenly realized that maybe he was using Safari or some other browser. So I tried safari.  There it was. The application error.&lt;/p&gt;


	&lt;p&gt;It boiled down to the ff lines of code:&lt;/p&gt;


&lt;code&gt;
      request_language = request.env['HTTP_ACCEPT_LANGUAGE']
      request_language = request_language.nil? ? nil : 
        Locale.normalize(request_language[/[^,;]+/])
&lt;/code&gt;

	&lt;p&gt;What happens is in Firefox the &lt;span class='caps'&gt;HTTP&lt;/span&gt;_ACCEPT_LANGUAGE is in the format&lt;/p&gt;


&lt;code&gt;
en-us,en;q=0.5
&lt;/code&gt;

	&lt;p&gt;Whereas in safari, its just a plain &lt;strong&gt;en&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;I added an additional case checking if the string matches two chars in the iso format. Hope this works for all browsers, will have to check Opera and Konqueror probably, which I&#8217;ve added somewhere in my personal &lt;a href='http://www.rousette.org.uk/projects/'&gt;todolist&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>Cyx</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-03-25:35</id>
    <published>2007-03-25T19:27:00Z</published>
    <updated>2007-03-25T19:33:22Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/3/25/rethinking-deployment-strategy" rel="alternate" type="text/html"/>
    <title>Rethinking Deployment Strategy</title>
<content type="html">
            &lt;p&gt;Currently on one of the servers where we deploy rails, we use the Apache + Nginx + Mongrel setup, primarily for the following reasons :&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;The Server has apache 1.3 already, and it&#8217;s really a pain to try updating it since it&#8217;s all tied up to cpanel&lt;/li&gt;
		&lt;li&gt;Apache 1.3 proxying doesn&#8217;t support the ! directive, which basically is the strategy for skipping static images&lt;/li&gt;
		&lt;li&gt;Because of the reason above, we use mongrel both for clustering and static file sending support.&lt;/li&gt;
		&lt;li&gt;Mongrel, for obvious reasons, best of which is ease of use and deployment.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Now I&#8217;m thinking of just Apache + Mongrel, with no send file support. Basically the setup will rely on using rails&#8217; asset host feature. Will post back if this works.&lt;/p&gt;


	&lt;p&gt;Also, im thinking of using pen as a load balancer, for ease of use and simplicity of getting it up and running (nginx config is a pain compared to pen)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>Cyx</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-03-21:34</id>
    <published>2007-03-21T11:42:00Z</published>
    <updated>2007-03-21T11:49:17Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/3/21/best-authorization-plugin-for-rails" rel="alternate" type="text/html"/>
    <title>Best Authorization Plugin for Rails</title>
<content type="html">
            &lt;p&gt;Ok, I think I&#8217;ve finally seen the authorization which fully satisfies my &lt;span class='caps'&gt;DSL&lt;/span&gt; taste.&lt;/p&gt;


	&lt;p&gt;Head on over to http://www.writertopia.com/developers/authorization to see what i mean.&lt;/p&gt;


	&lt;p&gt;Basically it allows you to define authorization&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Globally (throughout the entire app)&lt;/li&gt;
		&lt;li&gt;For one model class (i.e. Group, Article)&lt;/li&gt;
		&lt;li&gt;For an instance of the model class.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;In addition, it features grammars!&lt;/p&gt;


	&lt;p&gt;(taken from the site : )&lt;/p&gt;


	&lt;p&gt;&lt;img src='http://www.writertopia.com/images/developers/authorization_example.gif?1150951656' alt='' /&gt;&lt;/p&gt;


	&lt;p&gt;&amp;lt; checking out to read the source&#8230; &amp;gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>Cyx</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-02-22:33</id>
    <published>2007-02-22T05:53:00Z</published>
    <updated>2007-03-16T10:15:50Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/2/22/pretty-restful-resources" rel="alternate" type="text/html"/>
    <title>Pretty Restful Resources</title>
<content type="html">
            &lt;p&gt;Have you ever questioned the rails way? We have.&lt;/p&gt;


&lt;code&gt;
http://mydomain.com/articles/1;edit
&lt;/code&gt;

	&lt;p&gt;I&#8217;ve always had an itchy feeling when coding for this kind of &lt;span class='caps'&gt;URL&lt;/span&gt; ever since restful rails got out. Looking into resources.rb, we came up with a plugin that makes that &lt;span class='caps'&gt;URL&lt;/span&gt; look like this :&lt;/p&gt;


&lt;code&gt;
http://mydomain.com/articles/1:edit
&lt;/code&gt;

	&lt;p&gt;So far, we haven&#8217;t had any problems yet. Nesting doesn&#8217;t also reveal any problems. We have declarations like :&lt;/p&gt;


&lt;code&gt;
map.resources :admin do |admin|
  admin.resources :products, :name_prefix =&amp;gt; 'admin_' do |product|
    product.resources :sections, :name_prefix =&amp;gt; 'admin_products'
  end
end

&lt;/code&gt;

	&lt;p&gt;Nothing seems to be broken as of now.&lt;/p&gt;


	&lt;p&gt;If you&#8217;re interested, check out the plugin @ svn://svn.upstrat.com/plugins/pretty_resources/trunk&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>Cyx</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2007-02-11:32</id>
    <published>2007-02-11T21:24:00Z</published>
    <updated>2008-01-03T06:53:52Z</updated>
    <link href="http://theavidmind.upstrat.com/2007/2/11/back-to-nginx" rel="alternate" type="text/html"/>
    <title>Back to Nginx</title>
<content type="html">
            &lt;p&gt;After much head scratching, I just realized after re-reading the specs of mod_proxy in &lt;a href='http://httpd.apache.org/docs/1.3/mod/mod_proxy.html#proxypass'&gt;1.3 spec&lt;/a&gt; that the mod_proxy version for apache 1.3.x doesn&#8217;t support the style&lt;/p&gt;


&lt;code&gt;
ProxyPass /images !
&lt;/code&gt;

	&lt;p&gt;Looking closely at the spec&lt;/p&gt;


&lt;code&gt;
Syntax: ProxyPass path url
Default: None
&lt;/code&gt;

	&lt;p&gt;vs this one (in &lt;a href='http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass'&gt;the 2.0 spec&lt;/a&gt;)&lt;/p&gt;


&lt;code&gt;
Description:    Maps remote servers into the local server URL-space
Syntax:    ProxyPass [path] !|url
&lt;/code&gt;

	&lt;p&gt;pretty much shows the unobvious difference that there is an exclamation point for v2.0 onwards.&lt;/p&gt;


	&lt;p&gt;With all that, I have opted to return to nginx (at least for now) with the new setup. Right now everything seems blazingly fast (and nginx has a new release, surprise surprise) so at long last, mongrel is no longer serving static files..&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2006-11-22:27</id>
    <published>2006-11-22T00:36:00Z</published>
    <updated>2006-11-22T00:42:18Z</updated>
    <link href="http://theavidmind.upstrat.com/2006/11/22/compiling-ruby" rel="alternate" type="text/html"/>
    <title>"Compiling" Ruby</title>
<content type="html">
            We mostly deal with server-side applications.  However, every so often someone comes up to us and asks if we can create and install an application on their PC. This used to present us with a bit of a dilemma since server-side applications are by nature, not that easy to install. This is usally okay since you&#8217;re really only going to be doing it once.  Client-side applications on the other hand have to be really easy setup to use.  Here are some of the requirements for distrubting an app:
	&lt;ol&gt;
	&lt;li&gt;You cannot have the customer setup their own database on their computer&lt;/li&gt;
		&lt;li&gt;You can&#8217;t have the customer install their own webserver&lt;/li&gt;
		&lt;li&gt;You definitely cannot have the customer install the compiler/interpreter that you need to run your application.  &lt;/li&gt;
		&lt;li&gt;You cannot have the customer click more than one thing. (Anymore than one click, and things start to get really messy)&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;We&#8217;ve discovered the first steps to a solution to this dilemma for our rails apps thanks to a &lt;a href='http://www.erikveen.dds.nl/distributingrubyapplications/index.html'&gt;fascinating project on distrubuting ruby applications&lt;/a&gt; and another one for &lt;a href='http://www.erikveen.dds.nl/distributingrubyapplications/rails.html'&gt;rails applciations&lt;/a&gt;.  It&#8217;s not perfect but it&#8217;s good enough until we hear something from the &lt;a href='http://jruby.codehaus.org/'&gt;JRuby&lt;/a&gt;, &lt;a href='http://xruby.com'&gt;XRuby&lt;/a&gt;, &lt;a href='http://wiki.rubygarden.org/ruby/page/show/Rite'&gt;Rite&lt;/a&gt;, or &lt;a href='http://www.atdot.net/yarv/'&gt;&lt;span class='caps'&gt;YARV&lt;/span&gt;&lt;/a&gt; projects along the lines of an actual compiler for ruby.&lt;/p&gt;


They&#8217;re pretty straightforward guides to &#8220;compiling&#8221; your ruby application here are a few lessons learned in our foray into this brave new world:
	&lt;ul&gt;
	&lt;li&gt;Make sure you use a portable database solution like SQLite.  Everything is stored in one file and you can easily ship it with your app&lt;/li&gt;
		&lt;li&gt;Take a second look at your applcation if it has file-upload features.&lt;/li&gt;
		&lt;li&gt;Thank &lt;a href='http://www.erikveen.dds.nl/index.html'&gt;the man&lt;/a&gt;.  It&#8217;s people like him that make the world a better place.&lt;/li&gt;
	&lt;/ul&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2006-11-21:26</id>
    <published>2006-11-21T01:47:00Z</published>
    <updated>2006-11-21T01:55:46Z</updated>
    <link href="http://theavidmind.upstrat.com/2006/11/21/lists" rel="alternate" type="text/html"/>
    <title>Lists!</title>
<content type="html">
            &lt;p&gt;People deal with a lot of things.  Everyday, life make demands of us that sometimes just drive us crazy.  But for some reason, We cannot escape it.  It is ingrained in today&#8217;s society to handle many things at a time. in fact, productivity and efficiency have almost been synonymous with the ability to multitask.&lt;/p&gt;


	&lt;p&gt;&lt;img src='http://theavidmind.upstrat.com/assets/2006/11/21/bread_butter.png' alt='' /&gt;&lt;/p&gt;


	&lt;p&gt;I&#8217;m not going to write about doing less or simplifying life.  Sometimes that&#8217;s just not possible.   We want to make the best of everyday and so we have to tackle a  lot of things.  It&#8217;s the ability to do many things that make us such amazing beings.&lt;/p&gt;


	&lt;p&gt;Today&#8217;s little article is about lists.  I&#8217;m a software developer and my life revolves around projects, feature requests, bugs, tasks, enhancements,  and whatnot.  You can begin to see that even my focused little nook of the world is riddled with its own barrage of todos and problems.  It could literally &lt;a href='http://www.youtube.com/watch?v=E_k60zGE874'&gt;drive programmers crazy&lt;/a&gt;.  The only solution that I can think of is so simple that many don&#8217;t do it &#8211; make a list.&lt;/p&gt;


Lists are wonderful things.  
	&lt;ol&gt;
	&lt;li&gt;They remind you of the stuff you need to do.  &lt;/li&gt;
		&lt;li&gt;They keep you focused on the things you really need to be doing.  &lt;/li&gt;
		&lt;li&gt;They help set your priorities as you constantly reorder and reorganize them as new information arises.  &lt;/li&gt;
		&lt;li&gt;Last, and my favorite, it feels oh so good when you cross-off an item from your list.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;The important thing is to keep it organized and up to date as new issues arise.  If you don&#8217;t believe me, take it from a &lt;a href='http://www.joelonsoftware.com/articles/fog0000000245.html'&gt;battle-hardened software guru&lt;/a&gt; .&lt;/p&gt;


	&lt;p&gt;I&#8217;ll stop yapping now, (I&#8217;ve got some stuff to do) but I&#8217;ll leave you with a great (and old) anecdote concerning this particular topic:&lt;/p&gt;


	&lt;p&gt;A man approached &lt;a href='http://en.wikipedia.org/wiki/Jp_morgan'&gt;JP Morgan&lt;/a&gt;, held up an envelope, and said, “Sir, in my hand I
hold a guaranteed formula for success, which I will gladly sell you for $25,000.”
“Sir,” JP Morgan replied, “I do not know what is in the envelope, however if you
show me, and I like it, I give you my word as a gentleman that I will pay you what
you ask.” The man agreed to the terms, and handed over the envelope. JP Morgan
opened it, and extracted a single sheet of paper. He gave it one look, a mere glance,
then handed the piece of paper back to the gent. And paid him the agreed-upon
$25,000.&lt;/p&gt;


The Paper:
	&lt;ol&gt;
	&lt;li&gt;Every morning, write a  list of the things  that need to be done that day.&lt;/li&gt;
		&lt;li&gt;Do them.&lt;/li&gt;
	&lt;/ol&gt;
          </content>  </entry>
  <entry xml:base="http://theavidmind.upstrat.com/">
    <author>
      <name>amcvega</name>
    </author>
    <id>tag:theavidmind.upstrat.com,2006-10-30:25</id>
    <published>2006-10-30T05:33:00Z</published>
    <updated>2006-10-30T05:34:23Z</updated>
    <link href="http://theavidmind.upstrat.com/2006/10/30/ruby-gtk-and-windows" rel="alternate" type="text/html"/>
    <title>Ruby, Gtk, and Windows</title>
<content type="html">
            &lt;p&gt;I hate to admit it, but I&#8217;ll come clean.  I have a Windows laptop.  Hopefully that will change soon.  In the meantime however I will have to make do with some problems of using Windows.  One  of these annoyances is getting ruby and gtk to work.&lt;/p&gt;


	&lt;p&gt;It&#8217;s not really a problem.  You just have to dig a little to get it right, but just to make sure I don&#8217;t forget, here&#8217;s a little reminder for all those of you who want to run Ruby-Gtk in Windows.&lt;/p&gt;


	&lt;p&gt;First, go to the &lt;a href='http://ruby-gnome2.sourceforge.jp/hiki.cgi?Install+Guide+for+Windows'&gt;official ruby-gtk project&lt;/a&gt; and read a little.&lt;/p&gt;


	&lt;p&gt;Second make sure you read the bottom part concerning iconv.dll and it&#8217;s evil twin brother in your ruby_install_dir&lt;/p&gt;


	&lt;p&gt;Third, don&#8217;t forget the Gtk.init when you&#8217;re doing the third suggested test.  You might be splitting hairs for no reason.&lt;/p&gt;
          </content>  </entry>
</feed>
