<?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>OG Consulting &#187; Software Development</title>
	<atom:link href="http://og-consulting.com/category/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://og-consulting.com</link>
	<description>Leaders in Open Source</description>
	<lastBuildDate>Mon, 13 Jul 2009 22:30:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Procedural Flash Animation in Linux</title>
		<link>http://og-consulting.com/2006/03/18/procedural-flash-animation-in-linux/</link>
		<comments>http://og-consulting.com/2006/03/18/procedural-flash-animation-in-linux/#comments</comments>
		<pubDate>Sat, 18 Mar 2006 15:06:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/18/procedural-flash-animation-in-linux/</guid>
		<description><![CDATA[<p>This is an introduction to creating completely non-interactive, or procedural flash animation using  Linux.  The beauty of this is not that you can do more, or that it's prettier, or even faster to create.  The beauty lies in the power.  Once an animation procedure is set, the elements can be changed simply by including new images, colors, or messages.  In fact, I'm working on a simple web-form to generate the above animation by simply uploading elements and text inputs. </p>

  <p>But first, let's get to the tutorial, shall we?<br /></p>

<p>The door scene modeled in <a href="http://www.povray.org/" target="_blank">POV-ray</a> scene description language and is typical of Old San Juan, Puerto Rico Spanish Colonial architecture.  The real doors are beautiful.  If you ever get a chance to take a cruise from/to Puerto Rico, don't miss the chance to walk around Old San Juan (El Viejo San Juan) and check them out.  I rendered three frames with the doors rotated from 0 to 75 degrees to simulate... guess what?  Opening doors.  Clever, huh?</p>]]></description>
			<content:encoded><![CDATA[<div style="border: 1px solid #cccccc;padding: 10px;float: right;margin-left: 10px">
<object width="320" height="240" data="/files/images/slideshow.swf" type="application/x-shockwave-flash">
<param name="src" value="/files/images/slideshow.swf">
<img src="/files/images/puerta_open_sm.jpg" width="320" height="240">
</object>
</div>

  <p>This is an introduction to creating completely non-interactive, or procedural flash animation using  Linux.  The beauty of this is not that you can do more, or that it&#8217;s prettier, or even faster to create.  The beauty lies in the power.  Once an animation procedure is set, the elements can be changed simply by including new images, colors, or messages.  In fact, I&#8217;m working on a simple web-form to generate the above animation by simply uploading elements and text inputs. </p>

  <p>But first, let&#8217;s get to the tutorial, shall we?<br /></p>

<p>The door scene modeled in <a href="http://www.povray.org/" target="_blank">POV-ray</a> scene description language and is typical of Old San Juan, Puerto Rico Spanish Colonial architecture.  The real doors are beautiful.  If you ever get a chance to take a cruise from/to Puerto Rico, don&#8217;t miss the chance to walk around Old San Juan (El Viejo San Juan) and check them out.  I rendered three frames with the doors rotated from 0 to 75 degrees to simulate&#8230; guess what?  Opening doors.  Clever, huh?</p>

  <p>There&#8217;s a lot of POV code, here&#8217;s a little bit of what it looks like:</p>

<code>cylinder { &lt;0, 0.5, 0&gt;, &lt;0, -0.5, 0&gt;, 0.5<br />
     texture {<br />
        pigment { color rgb &lt;0.6, 0, 0&gt; }<br />
        normal { granite 0.02 turbulence &lt;0.5, 0.9, 0.2&gt; scale 0.25 }<br />
        finish { specular 0.1 reflection .1 }<br />
     }<br />
  }</code>

  <p>It&#8217;s pretty simple. You place objects in an X-Y-Z space (Cartesian coordinates) like a sphere, cylinder, box or any other of the predefined primitives. You can merge them, subtract them, intersect them in creative ways. Finally, you apply some sort of texture which includes a pigment, a surface (normal), and a finish (reflections effects etc). There are easier ways to model, but sometimes POV-ray&#8217;s scene description language is just the most elegant and easiest way to model something.</p>

  <p>The next step was to convert the png files to jpegs for inclusion in the flash animation. I used a little sprinkle of bash and a dash of kosher ImageMagick&#8217;s convert.<br /></p>

  <code>for file in *.png; do convert -quality 100 &quot;$file&quot; &quot;${file%.png}.jpg&quot;; done</code>

  <p>For each png file, convert the png file to a 100 percent quality jpeg file.  We use 100% quality because I&#8217;m going to let the swftools take care of the final compression.  There&#8217;s no sense in lossy compressing then lossy compressing again.  That&#8217;s just crazy talk.<br /></p>

  <p>We will now create the flash source file.  Open a new file slideshow.sc.  This is the textual language for the swftools Linux Flash toolkit.  I have never ever ever looked at a flash source file from any Macromedia product, so I have no idea if this animation description method looks/acts/walks/talks in anyway shape or form like Macromedia&#8217;s products.  Don&#8217;t know, don&#8217;t care.</p>


<code>.flash bbox=640x480 filename=&quot;slideshow.swf&quot; version=6 fps=25 compress background=white<br />
  <br />
  .jpeg s1 &quot;puerta_open03.jpg&quot;<br />
  .jpeg s2 &quot;puerta_open02.jpg&quot;<br />
  .jpeg s3 &quot;puerta_open01.jpg&quot;<br />
  .font font &quot;gilc____.ttf&quot;<br />
  .font arial &quot;arialbi.ttf&quot;<br />
  .text text1 text=&quot;Opening Doors&quot; font=font<br />
  .text text2 text=&quot;Opening Doors&quot; font=font<br />
  .text text3 text=&quot;Opening Doors&quot; font=font<br />
  .text text4 text=&quot;OG&quot; font=arial<br />
  .text text5 text=&quot;Experts in&quot; font=font<br />
  .text text6 text=&quot;Open Source&quot; font=font<br />
  <br />
  .put s1 scalex=640 scaley=480 alpha=100%<br />
  .put text1 scale=100% x=40 y=220 alpha=0%<br />
  <br />
  .frame 25<br />
  .put s2 scalex=640 scaley=480 alpha=0%<br />
  .change text1 alpha=100%<br />
  .put text2 scale=100% x=40 y=220<br />
  <br />
  .frame 100<br />
  .change s2 alpha=0%<br />
  .change text1 alpha=100%<br />
  .change text2 alpha=100%<br />
  <br />
  .frame 125<br />
  .change text1 alpha=0%<br />
  .change text2 alpha=100%<br />
  .change s2 alpha=100%<br />
  .put s3 scalex=640 scaley=480 alpha=0%<br />
  .put text3 scale=100% x=40 y=220<br />
</code>

  <p>And so on (that&#8217;s not the whole file, but the rest is just repetition.  There are 71 total lines of code for that little flash animation.  Is that a lot or a little?  Seems pretty small to me anyway.  Basically, with swftools you define an object (image, or text); you put it; then you change it.  You can change its fade, size, location, and more.  The swfc program will implement the change from the object&#8217;s last known state.  Check out <a href="http://www.swftools.org/" target="_blank">swftools</a> for more examples (that&#8217;s where I got all the reference I needed to make my little flash thingie).<br /></p>

  <p>So there you have it.  I walk through the frames, changing elements, putting, fading, growing, moving stuff around.  It&#8217;s was all described from start to finish in a procedural language, from the POV-ray scene description language, to bash and ImageMagick for command line image manipulation, and finally to swftools flash scene language for the final animation.  Pretty nifty, huh?</p>

  <p>Check out: <a href="http://www.altamente.com">http://www.altamente.com/</a> for another example.<br /></p>

  <p>The neat thing about this is that once the procedure has been developed, you can reuse it for other clients, other looks, colors, messages, etc.  In fact, you could directly render it on the server to update information on the fly via end user input.  There&#8217;s no limit to what you can do with something like this.<br /></p>

  <p>Of course if you&#8217;re on Windows, you would probably just buy Macromedia&#8217;s software&#8230; but where&#8217;s the fun in that?<br /></p>]]></content:encoded>
			<wfw:commentRss>http://og-consulting.com/2006/03/18/procedural-flash-animation-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails &#8211; Insert Multiple Child Records</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/</link>
		<comments>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comments</comments>
		<pubDate>Thu, 09 Mar 2006 06:39:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/</guid>
		<description><![CDATA[<p>I have been having a bafflingly hard
time trying to figure out the proper way to insert multiple child
records from one single webform.&#160; It is the standard fare for posting
things like invoice headers and details.&#160; Say for example, you've got
an invoice record which consists of an order number, date and whatnot.&#160;
That particular piece of tabular data is then considered the parent of
its child line items (product_id, description, quantity, price, etc).&#160;
So you've got this Order which consists of an invoice and line items. <br /></p>]]></description>
			<content:encoded><![CDATA[<p>I have been having a bafflingly hard
time trying to figure out the proper way to insert multiple child
records from one single webform.&nbsp; It is the standard fare for posting
things like invoice headers and details.&nbsp; Say for example, you&#8217;ve got
an invoice record which consists of an order number, date and whatnot.&nbsp;
That particular piece of tabular data is then considered the parent of
its child line items (product_id, description, quantity, price, etc).&nbsp;
So you&#8217;ve got this Order which consists of an invoice and line items.&nbsp; </p>
  <p>It&#8217;s
pretty basic, but I&#8217;ve had the hardest time figuring out how to do this
is Ruby on Rails.&nbsp; I know it&#8217;s not hard in theory, but with Rails,
since there is only One Right Way(TM) to do things, &#8217;cause you&#8217;re on
Rails, it takes a bit of doing to figure out this Right Way(TM).&nbsp; I
personally don&#8217;t have a problem doing it Rails&#8217; way, but please dear
God, just tell me what it is.&nbsp; I bought the book and everything.</p>
  <p>So
here&#8217;s the dope, folks.&nbsp; Please correct me if there&#8217;s a better way of
doing this, &#8217;cause I&#8217;m a Rails n00b.&nbsp; For reference sake, I am using
Ruby on Rails 1.0 with Postgres 8.0.4 and Ruby 1.8.4<br /></p><span id="more-29"></span>
  <p>First the webform:</p>
  <p> <code>&lt;ul id=items&gt;<br />&nbsp;&nbsp; &lt;% for item in @items %&gt;<br />&nbsp;&nbsp;
&lt;li&gt;&lt;%= check_box_tag 'line_item', item.id, checked=false,
{:name =&gt; &quot;line_item[item_id][]&quot;, :id =&gt;
&quot;line_item_id_#{item.id}&quot; }&nbsp; %&gt;&lt;label for=&quot;line_item_id_&lt;%=
item.id %&gt;&quot;&gt; &lt;%= item.title&nbsp; %&gt;&lt;/label&gt;&lt;/li&gt;<br />&nbsp;&nbsp; &lt;% end %&gt;<br />&lt;/ul&gt;</code></p>
  <p>Make sure to use check_box_tag instead of check_box.&nbsp; check_box holds a hidden text input that by default inserts a 0 into the database.&nbsp; From <a href="http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html">http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html</a><br /> </p>
  <blockquote>
    <p>The <tt>checked_value</tt> defaults to 1 while the
default <tt>unchecked_value</tt> is set to 0 which is convenient for
boolean values. Usually unchecked checkboxes don’t post anything. We
work around this problem by adding a hidden value with the same name as the
checkbox. </p>
  </blockquote>
  <p>You don&#8217;t want that.&nbsp; You want the plain vanilla check_box_tag which
does none of that nonsense, because you in fact, don&#8217;t want your
line_item table being filled with up with all kinds of line_items
referring to product &quot;0&quot; or product &quot;NULL&quot;.</p>
  <p>So that&#8217;s our form.&nbsp; The line <code>&lt;% for item in @items %&gt; </code>comes
from the items.rb model and is just a little database query to get all
the items associated with a particular order for posting in our
invoice.&nbsp; Why would we use checkboxes?&nbsp; Well, maybe we&#8217;re not going to
invoice the whole order.&nbsp; Maybe we&#8217;re out of some items.&nbsp; We&#8217;ll let our
warehouse guy check off the checkboxes on his wireless pda.&nbsp; How&#8217;s that?</p>
  <p>If
you were watching closely, you&#8217;ll notice that I modified the
check_box_tag behavior with options of my own with the following:</p>
  <p><code>:name =&gt; &quot;line_item[item_id][]&quot;</code></p>
  <p>This is what gives us multiple lines (an array of items) to pass to the controller.&nbsp; [] is the important part.</p>
  <p>Now,
so far this is easy, or at least I thought so.&nbsp; I&#8217;ve done this a
hundred times in php, but that&#8217;s just the problem, I got tired of
writing and re-writing this.&nbsp; I wanted Rails to handle all the parent
child relationships for me and leave me alone.&nbsp; I&#8217;m lazy.</p>
  <p>But I
couldn&#8217;t figure out exactly how to do this.&nbsp; Frankly, I&#8217;m still trying
to fit all the method/class/object/instance/variable blah blah blah
into my head and keep all the Invoice invoice invoices straight.&nbsp; I
know, I know, it&#8217;s probably me, but I&#8217;ll wager there are a few more
slow-witted programmers out there for whom this is all so confusing.&nbsp; A
phrase that I have been becoming more familiar with while working in
Ruby on Rails is, &quot;Use the force.&quot;&nbsp; It&#8217;s funny, but most of the time
when I relax and make stuff up without trying to &quot;understand,&quot;&nbsp; things
usually Just Work(TM).&nbsp; Jedi Programming&#8230; who knew?<br /></p>
  <p>So we&#8217;ve got our form.&nbsp; Now we need to post the parent and the children in one fell swoop.</p>
  <p>Now
for the model (no, not Victoria&#8217;s Secret):&nbsp; Invoice will not reference
the children (the children will come running when they hear their
parent&#8217;s voice regardless of whether they are called by name).&nbsp; The
parent &quot;has_many&quot; children and does not bother remembering their names
or ids or anything.&nbsp; The children on the other hand &quot;belong_to &quot; (or
reference) the parent and are tattooed with the parent_id stamp of
ownership (big ears for example).&nbsp;&nbsp; When they are required, they will
all line up under the parent and file out like good little children.</p>
  <p>Got it?&nbsp; Parent -&gt; has_many :children, Child -&gt; belongs_to :parent &#8211; the model of a perfect Catholic Rails family.<br /></p>
  <p>Now we need to post the stuff.&nbsp; This is a snippet from the invoice_controller.rb:</p>
  <p><code>&nbsp;&nbsp; def create<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @invoice = Invoice.new(params[:invoice])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @invoice.order_id = @session[&quot;order_id&quot;]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for item_id in params[:invoice_item][:item_id] do<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @invoice.invoice_items &lt;&lt; InvoiceItem.new(:item_id =&gt; item_id)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if @invoice.save<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flash[:notice] = 'Invoice was successfully created.'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; redirect_to :action =&gt; 'list'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; render :action =&gt; 'new'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br />&nbsp;&nbsp; end<br /></code></p>
  <p>order_id
is stored in the session array and is used to reference the invoice.&nbsp;
The invoice in turn has items added to it for each item_id in the
params passed from our form.&nbsp; What happens on @invoice.save is the
following:</p>
  <ol>
    <li>Rails inserts the invoice header (the parent)</li>
    <li>Immediately fetches currval(invoices_id_seq) to retrieve the newly created invoice_id</li>
    <li>Uses that invoice_id number and iterates over the invoice_items inserting both the item_id and invoice_id</li>
    <li>commits the results if successful<br /></li>
  </ol>That&#8217;s
it!&nbsp; Easy, huh?&nbsp; Well it took me all day to figure it out.&nbsp; I knew it
was easy, but perhaps I don&#8217;t have mad google sklz or something,
because it left me scratching my head.&nbsp; Hopefully someone will find
this useful.&nbsp; Leave a comment and I&#8217;ll do my best to answer your
questions.&nbsp; If not, I&#8217;m sure I&#8217;ll forget it in a few months and have to
reread this *G*.<br />]]></content:encoded>
			<wfw:commentRss>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
