<?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>DIXIS</title>
	<atom:link href="http://www.dixis.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.dixis.com</link>
	<description>Design &#38; Implementation of compleX Information Systems, software-bedrijf uit Antwerpen</description>
	<lastBuildDate>Fri, 31 May 2013 07:23:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>upgrading rails 2.3.5 to rails 3.2.13</title>
		<link>http://www.dixis.com/?p=679</link>
		<comments>http://www.dixis.com/?p=679#comments</comments>
		<pubDate>Fri, 31 May 2013 07:23:40 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=679</guid>
		<description><![CDATA[Yowza. Due to some devine intervention I am now responsible to upgrade three rails sites. I started developing them in 2009, but haven&#8217;t touched then since mid 2010. The persons who took over have not kept it up to date, nor (from their code) were they really good ruby programmers :) So I have the [...]]]></description>
				<content:encoded><![CDATA[<p>Yowza. Due to some devine intervention I am now responsible to upgrade three rails sites. I started developing them in 2009, but haven&#8217;t touched then since mid 2010. The persons who took over have not kept it up to date, nor (from their code) were they really good ruby programmers :)</p>

<p>So I have the daunting task to bring those projects into the present :)</p>

<p>Remember, 2010, rails 2.3.5? That seems like ages ago :) There was</p>

<ul>
<li>no bundler</li>
<li>no rvm (actually, still isn&#8217;t since they deploy on windows &#8211;aaaaarggh since then I develop on ubuntu and mac)</li>
<li><code>vendor/plugins</code> instead of gems</li>
<li>no asset pipeline</li>
<li>old routes</li>
</ul>

<p>At first I couldn&#8217;t even get the correct set of gems together to get the rails site running correctly.</p>

<p>So the steps I took to get it running (on my mac first) :</p>

<ul>
<li>create a new branch </li>
<li>use rvm to switch to start using 1.8.7 and a new empty gemset</li>
<li><code>gem install rails</code> (which apparently installs the correct 2.3.5 version by itself &#8211;impressed :)</li>
<li>install <code>rails_update</code> plugin (script/plugin) </li>
<li>my current rake version is not compatible, luckily if you type <code>rake _0.8.7_</code> instead of the normal <code>rake</code> it will work. Hehe.</li>
<li>to get to use <code>rails_upgrade</code> you have to have a working rails site, so I had to collect all gems in the correct versions</li>
<li>using <code>rails_upgrade</code> plugin to check/and upgrade routes/gems/&#8230;

<ul>
<li>the routes generated where correct</li>
<li>the gemfile I had to edit manually (the used gems were not specified in the <code>environment.rb</code> using <code>config.gem</code>)</li>
<li>also the generated <code>application.rb</code> needed to be edited (we added a lot of initializer code there &#8211;> should move to an initializer!)</li>
</ul></li>
</ul>

<p>Then I switched (with rvm) to ruby 1.9.3 and ran <code>bundle install</code>.
Then I created a fresh 3.2.13 project and copied:</p>

<ul>
<li>the <code>scripts</code> folder verbatim</li>
<li>the <code>config/boot.rb</code>, <code>config/environment.rb</code> and <code>config/environments/*.rb</code> (make sure to check and keep any changes you made)</li>
<li>the <code>Rakefile</code> (idem)</li>
</ul>

<p>Then I was good to go!!
We still have a lot of <code>vendor/plugins</code> I need to convert, one in particular I need to convert to an engine (gem).</p>

<p>Things I still need to do:</p>

<ul>
<li>convert <code>vendor/plugins</code>:

<ul>
<li>convert engine to gem</li>
<li>convert others to <code>lib/plugins</code></li>
</ul></li>
<li>move assets to asset pipeline</li>
</ul>

<p>And then I should have a running webapplication again. Wow.</p>

<p>Of course: the sites have no tests at all (my bad as well: when I started rails I did not know about testing), so will have to still add those. Starting with cucumber first, and add rspec later, when I touch the code (working from the outside in).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=679</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>simulating HTML5 history on IE8+</title>
		<link>http://www.dixis.com/?p=682</link>
		<comments>http://www.dixis.com/?p=682#comments</comments>
		<pubDate>Tue, 28 May 2013 14:29:10 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=682</guid>
		<description><![CDATA[For my current employer I help in building a heavy javascript based website/application. Using a javascript-based site, with a lot of ajax, you have to make sure the user can still use the back button without breaking the experience. So we used the HTML5 history, and tested that on Firefox and chrome and it worked [...]]]></description>
				<content:encoded><![CDATA[<p>For my <a href="http://ontoforce.com">current employer</a> I help in building a heavy javascript based website/application. Using a javascript-based site, with a lot  of ajax, you have to make sure the user can still use the back button without breaking the experience.</p>
<p>So we used the HTML5 history, and tested that on Firefox and chrome and it worked just fine.</p>
<p>Of course, our first client is using IE9, and it breaks completely.</p>
<p>The most famous library to port HTML5 history behaviour to all browsers is <a href="https://github.com/browserstate/history.js">history.js</a>. Unfortunately I encountered a few very specific issues with it:</p>
<ul>
<li>it uses <code>statechange</code> event, so it is triggered when pushing or popping a new state, and I can&#8217;t tell which change it is. I am only interested in the pop state. This is akward, but fixable.</li>
<li>we are building a SPARQL browser, so the url&#8217;s we build contain RDF identifiers, which are URI&#8217;s. History.js just can&#8217;t handle that. It will unescape the uri&#8217;s, and thus break the built url and stored state as well. This was not simply fixable at all. It was supposedly fixed in the dev-branch, but even that did not work</li>
</ul>
<p>So I had to go looking for an alternative, with the following characteristics:</p>
<ul>
<li>support the same API as the HTML5 history, or as close as possible</li>
<li>allow to build urls containing escaped uri&#8217;s</li>
<li>and of course: work on IE9 and up</li>
</ul>
<p>And luckily, I found that library: <a href="https://github.com/devote/HTML5-History-API">HTML5-History-API</a>, which is an exact implementation of the history API.</p>
<p>The only change was my <code>popstate</code> event (and include the javascript library, of course).</p>
<p>Before it was implemented as follows (coffeescript) :</p>
<pre class="brush: jscript; title: ; notranslate">
   window.addEventListener &quot;popstate&quot;, (e) -&gt;
     state = window.history.state
     state = event.state
     if state
       if state.query != undefined
         update(state.query)
</pre>
<p>and now it looks like:</p>
<pre class="brush: jscript; title: ; notranslate">
   window.addEventListener &quot;popstate&quot;, (event) -&gt;
     event = event || window.event
     state = event.state
     if state
       if state.query != undefined
         update(state.query)
</pre>
<p>And then my code just worked on IE9! Awesome :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=682</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>automatically handle StaleObjectError in rails 3.x</title>
		<link>http://www.dixis.com/?p=671</link>
		<comments>http://www.dixis.com/?p=671#comments</comments>
		<pubDate>Fri, 09 Nov 2012 18:38:26 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[staleobjecterror]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=671</guid>
		<description><![CDATA[There are different reasons why a ActiveRecord::StaleObjectError would occur. Sometimes it is caused because rails does not have a stable identity map yet. This means that if the same object would be retrieved via different associations, your rails process would not know they point to the same object, would keep different copies of the same [...]]]></description>
				<content:encoded><![CDATA[<p>There are different reasons why a <code>ActiveRecord::StaleObjectError</code> would occur. Sometimes it is caused because rails does not have a stable <a href="http://api.rubyonrails.org/classes/ActiveRecord/IdentityMap.html">identity map</a> yet. This means that if the same object would be retrieved via different associations, your rails process would not know they point to the same object, would keep different copies of the same object and that could easily cause a <code>StaleObjectError</code> if you attempt to change both.</p>
<p>Such an occurrence needs to be fixed structurally in your code. </p>
<p>But sometimes you can get <code>StaleObjectError</code> because things happen at the same time. There are two ways to handle this:</p>
<ul>
<li>make sure that controller actions which affect the same object, are always executed sequentially. One way to achieve this is to lock the object you want to update in the database. Then all other processes wanting to update the same object will have to wait until the lock is released (and the lock can be acquired). This is a valid approach but costly, intrusive (you need to explicitly add code), and possibly dangerous. It is normally easy to avoid, but you have to be careful for deadlocks and locks that are never released.</li>
<li>when a <code>StaleObjectError</code> occurs, just retry the request</li>
</ul>
<p>Now that second option seems valid, if only it would be easy to handle. Luckily there is a very easy and unobtrusive way to automatically retry all requests when a <code>StaleObjectError</code> occurs. Let&#8217;s just create a middleware that catches the exception and retries the complete request a few times.</p>
<p>Create a new file <code>lib/middleware/handle_stale_object_error.rb</code> containing the following:</p>
<pre class="brush: ruby; title: ; notranslate">
module Middleware

  class HandleStaleObjectError
    RETRY_LIMIT = 3

    def initialize(app)
      @app = app
    end

    def call(env)
      retries = 0

      begin
        @app.call(env)
      rescue ActiveRecord::StaleObjectError
        raise if retries &gt;= RETRY_LIMIT

        retries += 1
        Rails.logger.warn(&quot;HandleStaleObjectError::automatically retrying after StaleObjectError (attempt = #{retries})&quot;)

        retry
      end
    end
  end

end
</pre>
<p>Then in your <code>config/application.rb</code> you need to add the following lines at the bottom to activate the middleware (this requires a restart of your rails server):</p>
<pre class="brush: ruby; title: ; notranslate">
    #
    # Middleware configuration
    #
    require 'middleware/handle_stale_object_error'

    config.middleware.insert_after ActiveRecord::SessionStore, Middleware::HandleStaleObjectError
</pre>
<p><b>Warning</b>: this code will retry <em>all</em> occurences of <code>StaleObjectError</code>. For some occurrences this will not help at all, so you have to use your own judgement if this middleware is something you want in your codebase. I like this approach because it is an &#8220;optimistic&#8221; approach: it only adds extra processing when a <code>StaleObjectError</code> occurs, and when a not-fixable <code>StaleObjectError</code> it still fails as it should.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=671</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Short and clean ruby (or an exercise in group-think)</title>
		<link>http://www.dixis.com/?p=664</link>
		<comments>http://www.dixis.com/?p=664#comments</comments>
		<pubDate>Tue, 16 Oct 2012 13:12:16 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=664</guid>
		<description><![CDATA[In some part of my code I ended writing the following: where self is some ActiveRecord model, and count_processed is an attribute of that model (and stored in the database). What am i trying to achieve (if it is not blatantly obvious): if count_processed is not initialised, make it zero increment count_processed Imho this code [...]]]></description>
				<content:encoded><![CDATA[<p>In some part of my code I ended writing the following:</p>
<pre class="brush: ruby; title: ; notranslate">
  self.count_processed ||= 0
  self.count_processed += 1
</pre>
<p>where <code>self</code> is some ActiveRecord model, and <code>count_processed</code> is an attribute of that model (and stored in the database). </p>
<p>What am i trying to achieve (if it is not blatantly obvious): </p>
<ul>
<li>if <code>count_processed</code> is not initialised, make it zero</li>
<li>increment <code>count_processed</code></li>
</ul>
<p>Imho this code is clear and readable, but I had the feeling it could be more concise/prettier. So I asked that question on our campfire, to see if we could come up with something shorter.</p>
<p>Very nice to be working in a team where you can just throw up questions like these and a very useful, educational discussion unfolds. In short we came up with the following solutions.</p>
<h3>Solution 1: <code>to_i</code></h3>
<pre class="brush: ruby; title: ; notranslate">
self.count_processed = self.count_processed.to_i + 1
</pre>
<p>Nifty! Isn&#8217;t it? Use <code>to_i</code> because it will handle the <code>nil</code> correctly.</p>
<p>But for me this looked wrong. If I would return to this code after a few weeks, months, I would wonder why I did this way, and not just wrote <code>self.count_processed += 1</code>. </p>
<p>So while the code is correct, the intent of the code is not clear.</p>
<h3>Solution 2: concise!</h3>
<pre class="brush: ruby; title: ; notranslate">
self.count_processed = (self.count_processed || 0) + 1
</pre>
<p>This is very beautiful, and the intent is also very clear. If it is not initialised, use the zero, else just use the value and add 1. Awesome.</p>
<h3>Solution 3: change the getter</h3>
<p>And alternative solution would be to overwrite the getter, like this</p>
<pre class="brush: ruby; title: ; notranslate">
def count_processed
  self[:count_processed] ||= 0
end
</pre>
<p>Note the notation we used: we use <code>self[:count_processed]</code> because this will fetch the value from the database column. If this was a normal getter, we would write <code>@count_processed</code> (but that does not work for an ActiveRecord model).</p>
<p>After redefining the getter, we can just write:</p>
<pre class="brush: ruby; title: ; notranslate">
self.count_processed += 1
</pre>
<p>While this will work always, does it express its intent more clearly or not? Actually you no longer have to worry about the initialisation, because it is handled, and we can focus on what we really want: increment the counter.</p>
<p>I opted for this solution.</p>
<h3>What about you?</h3>
<p>Which version do you prefer? Do you have any alternative suggestions?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=664</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to remove deprecation warnings for link_to_function</title>
		<link>http://www.dixis.com/?p=660</link>
		<comments>http://www.dixis.com/?p=660#comments</comments>
		<pubDate>Mon, 08 Oct 2012 13:52:30 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=660</guid>
		<description><![CDATA[Since rails 3.2.4 the link_to_function is effectively deprecated (again). Everything keeps on working, but when running my specs I got a horseload of deprecation warnings. I know the optimal/recommended way is to use unobtrusive javascript, but the quickest way to fix this is really easy. Just perform the following translation: Dead-easy :) In the next [...]]]></description>
				<content:encoded><![CDATA[<p>Since rails 3.2.4 the <code>link_to_function</code> is effectively deprecated (again). Everything keeps on working, but when running my specs I got a horseload of deprecation warnings.</p>
<p>I know the optimal/recommended way is to use unobtrusive javascript, but the quickest way to fix this is really easy.</p>
<p>Just perform the following translation:</p>
<pre class="brush: ruby; title: ; notranslate">
    # before
    link_to_function icon_tag('close.png'), '$(this).parent().hide()', :title =&gt; t('actions.close'), :class =&gt; 'close'

    # after
    link_to icon_tag('close.png'), '#', :onclick =&gt; '$(this).parent().hide()', :title =&gt; t('actions.close'), :class =&gt; 'close'
</pre>
<p>Dead-easy :)</p>
<p>In the next refactoring I will remove all <code>onclick</code> blocks and replace them with unobtrusive javascript. But for now I got rid of the deprecation warnings :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=660</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>logging the activerecord-session-store</title>
		<link>http://www.dixis.com/?p=651</link>
		<comments>http://www.dixis.com/?p=651#comments</comments>
		<pubDate>Fri, 04 May 2012 12:52:51 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=651</guid>
		<description><![CDATA[I had an issue where I was not sure the ActiveRecord::SessionStore was actually working (in hindsight: it worked). But to make sure, I needed to know what was stored in the session or retrieved. Now all logging for the session-store is silenced, using Base.silence. Now I was very interested in that logging, and did not [...]]]></description>
				<content:encoded><![CDATA[<p>I had an issue where I was not sure the ActiveRecord::SessionStore was actually working (in hindsight: it worked). But to make sure, I needed to know what was stored in the session or retrieved.</p>
<p>Now all logging for the session-store is silenced, using <code>Base.silence</code>.</p>
<p>Now I was very interested in that logging, and did not find another to unsilence the logging but to add an initializer with the following code. So in file <code>config/initializers/unsilence_logging.rb</code> write:</p>
<pre class="brush: ruby; title: ; notranslate">
class ActiveRecord::Base
  def self.silence
    yield self
  end
end
</pre>
<p>This will unsilence the SessionStore logging. Your logging will look like this:</p>
<pre class="brush: bash; title: ; notranslate">
^[[1m^[[36mAREL (0.0ms)^[[0m  ^[[1mUPDATE &quot;sessions&quot; SET &quot;data&quot; = 'BAh7DEkiFnF1aWN&lt;&lt;snipped to protect the inncocent&gt;&gt;iEi9mcC9kYXNoYm9hcmQ= ', &quot;updated_at&quot; = '2012-05-04 11:17:24.704491' WHERE &quot;sessions&quot;.&quot;id&quot; = 33635^[[0m
</pre>
<p>This at least allows us to verify that the sessions are stored and retrieved correctly. But how can we see what is stored inside the session?<br />
To be able to read or inspect what is actually stored in the session, you can use the following line:</p>
<pre class="brush: ruby; title: ; notranslate">
session_data = 'BAh7DEkiFnF1aWN&lt;&lt;snipped to protect the inncocent&gt;&gt;iEi9mcC9kYXNoYm9hcmQ= '
Marshal.load(ActiveSupport::Base64.decode64(session_data))
</pre>
<p>And this will present your session data in a readable format. </p>
<p>This way I learned that a time-drift between our two servers caused a very obscure bug. I hope it can help you too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=651</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>using jasmine without rails</title>
		<link>http://www.dixis.com/?p=646</link>
		<comments>http://www.dixis.com/?p=646#comments</comments>
		<pubDate>Sun, 08 Apr 2012 19:27:13 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[jasmine]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=646</guid>
		<description><![CDATA[Assume you have, like I did, a ruby gem that contains some javascript you want to test standalone. First you need to install the jasmine-gem. You have two options: either you use your gemspec to drive your bundler gemfile, so just add it to your developement dependencies I am still using jeweler, so I use [...]]]></description>
				<content:encoded><![CDATA[<p>Assume you have, like I did, a ruby gem that contains some javascript you want to test standalone.</p>
<p>First you need to install the jasmine-gem. You have two options:</p>
<ul>
<li>either you use your gemspec to drive your bundler gemfile, so just add it to your developement dependencies</li>
<li>I am still using jeweler, so I use a normal <code>Gemfile</code>, which jeweler parses to populate my gemspec with. Personally I find this much easier, and my workflow is much closer to any ruby development for me, this way</li>
</ul>
<p>If you have a rails-project, starting with jasmine is easy, and takes three easy steps:</p>
<pre class="brush: bash; title: ; notranslate">
# first add jasmine to Gemfile, and then
bundle install
rails g jasmine:install
rake jasmine 
</pre>
<p>Inside your gem or simple ruby-project it is equally simple, just type</p>
<pre class="brush: bash; title: ; notranslate">
jasmine init
rake jasmine
</pre>
<p>Now you can need to edit the <code>jasmine.yml</code> to make sure it is running your tests and your code, instead of the example code.<br />
In my case I had to change only one line:</p>
<pre class="brush: ruby; title: ; notranslate">
src_files:
  - app/assets/javascripts/**/*.js
</pre>
<p>Happy testing :)</p>
<p>Some interesting links to help you with jasmine:</p>
<ul>
<li>a very interesting <a href="http://www.slideshare.net/timtyrrell/testing-javascript-with-jasmine-8998985">slideshow</a></li>
<li><a href="http://pivotal.github.com/jasmine/">jasmine homepage</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=646</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>converting a processing sketch with audio and visuals to a video on ubuntu</title>
		<link>http://www.dixis.com/?p=640</link>
		<comments>http://www.dixis.com/?p=640#comments</comments>
		<pubDate>Sat, 24 Mar 2012 18:14:51 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[generative art]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=640</guid>
		<description><![CDATA[I really like generative art, so I have been playing with processing for a while. Processing is an open source language (on top of java), that gives the possibilty to create images, animations, with added interactivity. First I created a simulation of raindrops, and because I wanted it to be easily configurable I used processing.js: [...]]]></description>
				<content:encoded><![CDATA[<p>I really like generative art, so I have been playing with <a href="http://processing.org/" target="_blank">processing</a> for a while. Processing is an open source language (on top of java), that gives the possibilty to create images, animations, with added interactivity.</p>
<p>First I created a simulation of <a href="http://dixis.com/demo/bare_drops.html" title="animated raindrops" target="_blank">raindrops</a>, and because I wanted it to be easily configurable I used <a href="http://processingjs.org/" target="_blank">processing.js</a>: processing implemented on top of javascript. So that becomes native processing in the browser. Allowing to interact with HTML and javascript objects easily. Publishing the sketch is just: give people the link. </p>
<p>Next-up I wanted to create a music visualisation. Interact with the music. I had the perfect piece of music in my head: &#8220;Endless Season&#8221; by Ken Ishii. </p>
<p>Now processing.js does not interact with music. There is HTML5 audio, but it still is very experimental, and I did not find any API for processing music, reacting to and analysing music played. Processing (the java version) has an excellent library for this: Minim (actually more than one, but I ended up using that one).</p>
<p>When the sketch was finished, I wanted to share it, convert it to a video. What were the options.</p>
<h2> Use Processing itself</h2>
<p>There are two ways to convert a processing sketch to a movie, from within processing itself:</p>
<ul>
<li>use <code>MovieMaker</code>: this requires quicktime and unfortunately does not work on Ubuntu</li>
<li>when each frame is drawn, do <code>saveFrame</code> and then convert all frames to a movie afterwards. While in theory this should work, saving the images slowed down my sketch, and ultimately screwed up the sync with the audio. My frame-rate was not consistent enough. For straightforward stuff this does not matter, but I needed it to sync with the audio.</li>
<li>There is a third option: <code>GSVideo</code>, but frankly, that seemed to damn hard for me, so I skipped that.</li>
<p>So I needed an alternative approach. If it runs correctly on my screen, couldn&#8217;t I just record it on my screen?</p>
<h2>Use some sort of screenrecording/screencast software</h2>
<p>To record my desktop, on ubuntu, including the sound from processing proved to have some issues:</p>
<ul>
<li>processing (i.e. java/JDK 6) does not use ALSA to create the sound, but address the hardware devices directly</li>
<li>I do not want to record my entire desktop, but a specific part, of a specific size</li>
<li>I want to share my video on vimeo, so it has to follow certain guidelines</li>
</ul>
<p>The first proved to be the hardest.</p>
<h3>Recording the system audio out together with the video</h3>
<p>On ubuntu, I found <a href="http://askubuntu.com/questions/57448/screencast-with-both-mic-and-system-sounds-at-the-same-time" target="_blank">one approach</a> to work very well for me:</p>
<ul>
<li>use <code>gtk-recordmydesktop</code></li>
<li>use PulseAudio mixer, it will allow to take the sound output as input to record</li>
<li>and record away! :)</li>
<p>But, unfortunately, since java does not ALSA but uses the hardware devices directly, PulseAudio was unable to capture the sounds. However, by accident I found out that if you export your processing sketch to an applet, and run the applet in the browser, it <i>does</i> use ALSA and can be recorded perfectly. Awesome. </p>
<p>Part one solved. </p>
<h3>Recording a specific part of the screen</h3>
<p><code>gtk-recordmydesktop</code> allows to specify an area of the screen to record, but somewhat akwardly. Now, for exporting to vimeo, it had to follow certain fixed, optimal sizes. E.g. 640×480 for 4:3 SD video, 640×360 for 16:9 SD video, and 1280×720 or 1920×1080 for HD. And that is hard to do if you are trying to position the recording box manually.</p>
<p>But, as I found out <a href="http://ubuntuforums.org/showthread.php?t=1771136" target="_blank">here</a>, when using recordmydesktop from the commandline, you can send those options along:</p>
<pre class="brush: bash; title: ; notranslate">
recordmydesktop -x=0 -y=0 --width=320 --height=240
</pre>
<p>So, if you open the <code>Advanced->Misc</code>, and look for the <code>Extra options</code> field, there you can fill in the same options, and when you press record gtk-recordmydesktop will show the bounding box that is recorded.</p>
<h3>Preparing your video for uploading to vimeo</h3>
<p>To upload your video to vimeo, you have make sure two things are correct:</p>
<ul>
<li>the screensize, which we discussed before</li>
<li>the video format</li>
</ul>
<p><code>gtk-recordmydesktop</code> creates an Ogg Theora file, and unfortunately vimeo does not accept that format yet. Converting that to MP4 was hell, until I found Arista Transcoder.</p>
<p>Using Arista to create an MP4 is easy (but you have to know it):</p>
<ul>
<li>open Arista Transcode</li>
<li>create a new conversion</li>
<li>select your file, by default called <code>out.ogv</code>, as the source</li>
<li>select <code>Sony Playstation - PSP</code> as the device</li>
<li>press create!</li>
</ul>
<p>This will create a file called <code>out.mp4</code> which is just perfect for vimeo, including the sound.</p>
<h2><a href="http://vimeo.com/39084099" target="_blank">The result</a></h2>
<p><iframe src="http://player.vimeo.com/video/39084099" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=640</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>generating pdf on heroku</title>
		<link>http://www.dixis.com/?p=634</link>
		<comments>http://www.dixis.com/?p=634#comments</comments>
		<pubDate>Sat, 10 Mar 2012 20:55:00 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=634</guid>
		<description><![CDATA[I was investigating ways to generate pdf&#8217;s in Ruby on Rails, but I had one enormous constraint: it had to deploy on heroku. There are two very different ways to generate pdf&#8217;s in ruby: use prawn: it is pure ruby, very powerful. It has it&#8217;s own DSL, that unleaches all the power of building a [...]]]></description>
				<content:encoded><![CDATA[<p>I was investigating ways to generate pdf&#8217;s in  Ruby on Rails, but I had one enormous constraint: it had to deploy on heroku. </p>
<p>There are two very different ways to generate pdf&#8217;s in ruby:</p>
<ul>
<li>use prawn: it is pure ruby, very powerful. It has it&#8217;s own DSL, that unleaches all the power of building a PDF, but at the same time: it seems to be very hard and tedious.</li>
<li>use some sort of HTML to PDF conversion. In ruby there exists two gems: <a href="https://github.com/mileszs/wicked_pdf">wicked_pdf</a> and <a href="https://github.com/pdfkit/PDFKit">PDFKit</a>, both use <code>wkhtmltopdf</code> under the covers. I dreamed of having a view magically converted to PDF.</li>
</ul>
<p>I went for the second option. Furthermore, I choose <code>wicked_pdf</code> over <code>PDFKit</code>, because I felt the rails integration was better. It allowed my to just render a view which would automatically be downloaded as a PDF.</p>
<h3>Setting up wicked_pdf in Rails to run on heroku</h3>
<p>Luckily, getting it running on heroku proved to be incredibly easy:just including the correct gem with the binaries that work on heroku.</p>
<p>In my <code>Gemfile</code> I added the following:</p>
<pre class="brush: ruby; title: ; notranslate">
gem &quot;wicked_pdf&quot;
gem &quot;wkhtmltopdf-heroku&quot;, :git =&gt; 'git://github.com/camdez/wkhtmltopdf-heroku.git'
</pre>
<p>And, then, inside a view you want to render as pdf, write something like</p>
<pre class="brush: ruby; title: ; notranslate">
respond_to do |format|
       format.js
       format.pdf {
         render :pdf =&gt; &quot;show&quot;, :header =&gt; { :font_size =&gt; '8', :right =&gt; '[page] of [toPage]' }, :footer =&gt; {:font_size =&gt; '8', :right =&gt; 'Generated by jottinx.com' }
      }
     end
   end
</pre>
<p>Then, you will still have to create the view, <code>show.pdf.erb</code>. Just make sure your view renders HTML and it will be converted to PDF correctly. That is just awesome.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=634</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>testing drag and drop of jQuery UI sortable with cucumber and capybara</title>
		<link>http://www.dixis.com/?p=626</link>
		<comments>http://www.dixis.com/?p=626#comments</comments>
		<pubDate>Sun, 08 Jan 2012 18:31:16 +0000</pubDate>
		<dc:creator>nathanvda</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://www.dixis.com/?p=626</guid>
		<description><![CDATA[The Problem For jottinx I wrote a small piece of code that allowed to sort items using drag and drop. Of course, after writing it and making sure it works (manually), I want to make sure it keeps working. So I add a test, using cucumber. My scenario actually looks pretty straightforward: The difficult bit [...]]]></description>
				<content:encoded><![CDATA[<h3>The Problem</h3>
<p>For <a href="http://jottinx.com">jottinx</a> I wrote a small piece of code that allowed to sort items using drag and drop. Of course, after writing it and making sure it works (manually), I want to make sure it keeps working. So I add a test, using cucumber.</p>
<p>My scenario actually looks pretty straightforward:</p>
<pre class="brush: ruby; title: ; notranslate">
  @javascript
  Scenario: Dragging a book
    Given I authenticate as a &quot;default user&quot;
    And I add a new book with title &quot;a-new-book&quot;
    And I add a new book with title &quot;another-book&quot;
    And I add a new book with title &quot;one-last-book&quot;
    And I drag book &quot;one-last-book&quot; to the top
    Then book &quot;one-last-book&quot; is at the top of the list
</pre>
<p>The difficult bit was: <em>how do I implement the dragging?</em>.</p>
<p>Actually it seemed straightforward, because capybara has a method called <code>drag_to</code>. So I implemented the step like this:</p>
<pre class="brush: ruby; title: ; notranslate">
When /^I drag book &quot;([^&quot;]*)&quot; to the top$/ do |book_title|
  drop_place = page.find(:css, 'ul.sortable-books li:first')
  page.find(:xpath, &quot;//a[@href='##{book_title.parameterize}']&quot;).drag_to(drop_place)
end
</pre>
<p>But, unfortunately, this did not work. I googled around a bit and found the following two similar questions:</p>
<ul>
<li><a href="http://groups.google.com/group/ruby-capybara/browse_thread/thread/ce3bc33cce6fa747">drag_to with jquery sortable list</a></li>
<li><a href="http://groups.google.com/group/ruby-capybara/browse_thread/thread/e6b0d1deba8e236f">drag_to don&#8217;t work on sortable elements</a></li>
</ul>
<p>The short conclusion: it does not work, and it is a combination of how jquery implemented the sortable element, and the fact that the selenium driver does not support it yet. So, refraining to using the selenium driver directly does not help either.</p>
<p>After some more googling, I found a similar question on <a href="http://stackoverflow.com/questions/4044327/how-can-i-test-jquery-ui-sortable-with-cucumber">stackoverflow</a>, and there I found the solution.</p>
<h3>The solution</h3>
<p>Enter <a href="https://github.com/mattheworiordan/jquery.simulate.drag-sortable.js">jquery.simulate.drag-sortable.js</a>. It is a script that will allow you to simulate dragging in a sortable object by issuing a simple javascript command:</p>
<pre class="brush: jscript; title: ; notranslate">
// drag item down one position in the list
$('#itemToDrag').simulateDragSortable({ move: 1 });
</pre>
<p>If <code>move</code> parameter is negative, it will move up. And down if positive. If you include the <code>js</code> inside your project, you can easily test that out inside your Chrome console. It just works. Awesome piece of work.</p>
<p>To use that in a step-definition, just write:</p>
<pre class="brush: ruby; title: ; notranslate">
When /^I drag book &quot;([^&quot;]*)&quot; to the top$/ do |book_title|
  page.execute_script %Q{
    $('.sortable-books li:last').simulateDragSortable({move: -4});
  }
end
</pre>
<p>Hope this helps :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dixis.com/?feed=rss2&#038;p=626</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
