<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xml:lang="en-US">
  <title type="text">ananasblau.com</title>
  <id>tag:ananasblau.com,2012:mephisto/</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  
  <link href="http://ananasblau.com/" rel="alternate" type="text/html" />
  <updated>2011-05-04T18:04:00Z</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/ananasblau-com" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="ananasblau-com" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><subtitle type="html">Thomas R. Koll bloggs about his daily life as Ruby on Rails developer and open source hacker. He's available for small and medium projects.</subtitle><geo:lat>47.641249</geo:lat><geo:long>13.01734</geo:long><entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2011-05-04:29323</id>
    <published>2011-05-04T17:48:00Z</published>
    <updated>2011-05-04T18:04:00Z</updated>
    <category term="My projects" />
    <category term="games" />
    <link href="http://ananasblau.com/2011/5/4/spring-games" rel="alternate" type="text/html" />
    <title>spring games</title>
<content type="html">
            &lt;p&gt;Bringing sirtet into the Mac App Store was harder than I thought, in the end I had to change the name to &lt;a href="http://itunes.apple.com/us/app/unstack/id434877318?mt=12"&gt;Unstack&lt;/a&gt; but it’s in the store so go and buy it!&lt;/p&gt;


	&lt;p&gt;Last weekend I spent working on a new game for ludum dare #20 and the result is called &lt;a href="http://www.ludumdare.com/compo/ludum-dare-20/?action=rate&amp;amp;uid=3562"&gt;Trollbridge Armours&lt;/a&gt; written in Javascript and using RaphaelJS for all the user interface. I couldn’t get the tech tree finished and also should have tested it in Firefox, Chrome or at least Safari (I’m using the nightly Webkit) but that’s also coming in the next days. I learned a lot about RaphaelJS and where it has it’s difficulties with the browsers, good to know. With a better set of graphics the game will be ready to be simply wrapped into a WebView and pushed into the App Store.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2011-04-02:29059</id>
    <published>2011-04-02T05:24:00Z</published>
    <updated>2011-04-02T07:32:23Z</updated>
    <category term="game" />
    <category term="macruby" />
    <category term="sirtet" />
    <link href="http://ananasblau.com/2011/4/2/sirtet-a-macruby-game" rel="alternate" type="text/html" />
    <title>Sirtet - a MacRuby game</title>
<content type="html">
            &lt;p&gt;
I’ve spent the better part of yesterday creating a new game. Mind you it’s been a mere 8 hours to create this game. The goal of the game is to remove certain blocks from a large field, basically Tetris in reverse for all those whose stack grew too big in those old days.&lt;/p&gt;


	&lt;p&gt;As the title says, the game is in MacRuby, actually my third game in this lingo after The Flying Camera in December and the failed attempt (well, only the physics are missing) of Springz last week. I’ve learned a lot about XCode (4), again. Also a lot about the inner workings of a desktop application, compared to the usual web apps.&lt;/p&gt;


	&lt;p&gt;Check out the code a the &lt;a href="http://github.com/TomK32/Sirtet"&gt;github repository&lt;/a&gt; there’s also a download for the lazy. The game requires a 64bit Snow Leopard system, sorry about that. I’m planning on putting it into the Mac App Store which is why the game is not open source, you are only allowed the pleasure of looking at it. Kim Jong Il already did and he was moved by it.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2011-03-26:28979</id>
    <published>2011-03-26T07:42:00Z</published>
    <updated>2011-03-26T08:48:56Z</updated>
    <category term="My projects" />
    <category term="Ruby" />
    <category term="application" />
    <category term="example" />
    <category term="macruby" />
    <link href="http://ananasblau.com/2011/3/26/macruby-statusmenu-example" rel="alternate" type="text/html" />
    <title>macruby-statusmenu example</title>
<content type="html">
            &lt;p&gt;
I pushed a little example application written in MacRuby that shows you how to write an 
application for your system’s status menu. It also displays a custom view that you can style with images and stuff
in this status menu. The app is set to run as agent meaning it won’t show in the Dock Menu when running.&lt;/p&gt;


	&lt;p&gt;Clone it from my &lt;a href="https://github.com/TomK32/macruby-statusmenu"&gt;github repository&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2011-02-19:28645</id>
    <published>2011-02-19T10:20:00Z</published>
    <updated>2011-02-19T10:25:23Z</updated>
    <category term="Ruby on Rails" />
    <category term="naiku" />
    <category term="references" />
    <category term="user tests" />
    <link href="http://ananasblau.com/2011/2/19/naiku-in-practice" rel="alternate" type="text/html" />
    <title>Naiku in practice</title>
<content type="html">
            &lt;p&gt;It’s fantastic to see the applications that I create in practice. &lt;a href="http://naiku.net"&gt;Naiku&lt;/a&gt; is a startup I work for since August and the company has made a &lt;a href="http://vimeo.com/20120477"&gt;video of students using the app&lt;/a&gt; (both the web and mobile interface). Kudos to John and Peter who joined my developing efforts in the last months.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2011-02-05:28512</id>
    <published>2011-02-05T07:43:00Z</published>
    <updated>2011-02-05T07:49:37Z</updated>
    <category term="Ruby on Rails" />
    <category term="rails" />
    <category term="validations" />
    <link href="http://ananasblau.com/2011/2/5/run-validations-early-on" rel="alternate" type="text/html" />
    <title>Run validations early on</title>
<content type="html">
            &lt;p&gt;I just had the case in a Rails app where the user’s email doesn’t have to be valid. The validations in this case are done by Devise. If the email isn’t valid I want to remove it. The way to do this is to run all validators on email before the actual validation and then decide wether to set email to nil.&lt;/p&gt;


&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;before_validation &lt;span class="r"&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="co"&gt;User&lt;/span&gt;.validators_on(&lt;span class="sy"&gt;:email&lt;/span&gt;).map{|v| v.validate(&lt;span class="pc"&gt;self&lt;/span&gt;) }&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="pc"&gt;self&lt;/span&gt;.email = &lt;span class="pc"&gt;nil&lt;/span&gt; &lt;span class="r"&gt;if&lt;/span&gt; errors[&lt;span class="sy"&gt;:email&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2011-01-14:27385</id>
    <published>2011-01-14T17:16:00Z</published>
    <updated>2011-01-14T18:23:10Z</updated>
    <category term="My projects" />
    <category term="game" />
    <category term="macruby" />
    <category term="opengl" />
    <link href="http://ananasblau.com/2011/1/14/super-gamedev-weekend-2010" rel="alternate" type="text/html" />
    <title>Super Gamedev Weekend 2010</title>
<content type="html">
            &lt;p&gt;I’m a bit late with writing this post but I’m happy to announce that with the help of my friend “Ben:”https://abwesend.com/ I have won the last game programming competition held at the metalab in Vienna. The game is called &lt;a href="https://github.com/Metalab/The-Flying-Camera"&gt;The Flying Camera&lt;/a&gt; and is written using MacRuby and OpenGL. It is released as open source.&lt;/p&gt;


	&lt;p&gt;This is very fantastic news as it was in fact the first time I ever wrote a game and it sure will be the base for more games to come.&lt;/p&gt;


	&lt;p&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-12-09:25506</id>
    <published>2010-12-09T10:19:00Z</published>
    <updated>2010-12-09T11:18:06Z</updated>
    <category term="Javascript" />
    <category term="events" />
    <category term="jquery" />
    <category term="rails.js" />
    <category term="ujs" />
    <link href="http://ananasblau.com/2010/12/9/prevent-double-clicks-on-ajax-links" rel="alternate" type="text/html" />
    <title>Prevent double clicks on ajax links (rails.js)</title>
<content type="html">
            &lt;p&gt;A simple problem: In the new &lt;a href="http://www.schoolcamp.at"&gt;Schoolcamp app&lt;/a&gt; I’m working on this month I have some inline editing functionality using jQuery and &lt;span class="caps"&gt;UJS&lt;/span&gt;. In cases where the user clicked twice on the “edit” link he’d get two forms, not quite what a good UI would do. My solution was as simple and unobstrusive as can be and I’d like to share the code with you. 
I’m using the &lt;a href="http://github.com/rails/jquery-ujs/blob/master/src/rails.js"&gt;rails.js&lt;/a&gt; for jQuery and the only thing you have to add to your html links (or forms) is &lt;code&gt;data-once="true"&lt;/code&gt;&lt;/p&gt;


	&lt;h3&gt;The &lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/h3&gt;


&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;   &lt;span class="ta"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="an"&gt;href&lt;/span&gt;=&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;/tasks/1/edit.js&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class="an"&gt;data-method&lt;/span&gt;=&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class="an"&gt;data-once&lt;/span&gt;=&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class="an"&gt;data-remote&lt;/span&gt;=&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class="ta"&gt;&amp;gt;&lt;/span&gt;Edit&lt;span class="ta"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;


	&lt;h3&gt;The javascript event listeners&lt;/h3&gt;


&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;&lt;span class="c"&gt;// To prevent double clicks on a remote link or form you can&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="c"&gt;// simple add data-once=true to your html tag and we&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="c"&gt;// stop the ajax request here.&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;[data-once=true]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).live(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;ajax:before&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="kw"&gt;function&lt;/span&gt;(request, e) {&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="kw"&gt;var&lt;/span&gt; el = request.target;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="kw"&gt;if&lt;/span&gt;(&lt;span class="pd"&gt;$&lt;/span&gt;(el).attr(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;data-clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;)) {&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="kw"&gt;return&lt;/span&gt; &lt;span class="kw"&gt;false&lt;/span&gt;;&lt;tt&gt;
&lt;/tt&gt;  } &lt;span class="kw"&gt;else&lt;/span&gt; {&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="pd"&gt;$&lt;/span&gt;(el).attr(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;data-clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="kw"&gt;true&lt;/span&gt;);&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="kw"&gt;return&lt;/span&gt; &lt;span class="kw"&gt;true&lt;/span&gt;;&lt;tt&gt;
&lt;/tt&gt;  }&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="kw"&gt;return&lt;/span&gt; &lt;span class="kw"&gt;true&lt;/span&gt;;&lt;tt&gt;
&lt;/tt&gt;});&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="c"&gt;// after failure we want to click again, hoping for succes on a second try&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;[data-once=true]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).live(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;ajax:failure&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="kw"&gt;function&lt;/span&gt;(request,e) {&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="pd"&gt;$&lt;/span&gt;(request.target).removeAttr(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;data-clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;);&lt;tt&gt;
&lt;/tt&gt;});&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-10-13:21380</id>
    <published>2010-10-13T18:34:00Z</published>
    <updated>2010-10-13T19:49:17Z</updated>
    <link href="http://ananasblau.com/2010/10/13/rails-3-upgrade-sessions-store" rel="alternate" type="text/html" />
    <title>Rails 3 upgrade: two tips</title>
<content type="html">
            &lt;p&gt;I think I’ve started porting &lt;a href="http://photostre.am"&gt;photostre.am&lt;/a&gt; to Rails3 sometime in January, before the betas I think. Sometimes I had to stick to a certain commit of Rails as later ones were broken for me but the whole thing went quite well and over the last ten months I barely had to change anything. It’s a different story for those among you who excessively used rails’ javascript helpers, but I’ve been on &lt;span class="caps"&gt;UJS&lt;/span&gt; for long time now.&lt;/p&gt;


	&lt;p&gt;But today I did another upgrade, this from rails commit 9e081caee7 to 3.0.0. Finally. I ran into two problems and would like to share the solution with you.&lt;/p&gt;


First of all, there’s a &lt;strong&gt;deprecation notice about the routes&lt;/strong&gt;. I have updated to the new &lt;span class="caps"&gt;DSL&lt;/span&gt; but the devil’s hiding in details:
&lt;div class="CodeMacro"&gt;
&lt;pre&gt;&lt;code&gt;--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,4 @@
-DasPhotowall::Application.routes.draw do |map|
+DasPhotowall::Application.routes.draw do&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


	&lt;p&gt;Second, I’ve updated my environment.rb from &lt;tt&gt;Rails::Application.initialize!&lt;/tt&gt; to &lt;tt&gt;DasPhotowall::Application.initialize!&lt;/tt&gt; and soon later ran into the nasty problem of not being able to login. &lt;strong&gt;Sessions didn’t work!&lt;/strong&gt;. I should have &lt;tt&gt;grep&lt;/tt&gt;ped over the whole repo earlier because in the &lt;tt&gt;session_store initializer&lt;/tt&gt; there was still a &lt;tt&gt;Rails::Application&lt;/tt&gt; hiding. So, update your initialisers.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-07-28:17280</id>
    <published>2010-07-28T06:07:00Z</published>
    <updated>2010-07-28T06:16:51Z</updated>
    <category term="padrino" />
    <category term="ruby" />
    <link href="http://ananasblau.com/2010/7/28/a-custom-padrino-formbuilder" rel="alternate" type="text/html" />
    <title>A custom padrino FormBuilder</title>
<content type="html">
            &lt;p&gt;More of a noobie question that came up yesterday at the #padrino irc channel:&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;What is the right place for a custom form builder?&lt;/em&gt;&lt;/p&gt;


About the location, the manual doesn’t really say it but it says that helpers should be put into app/helpers and as the FormBuilder is a helper it should go there too. From there on the noob ran into the next problem, how to get it work, because the example from the docs didn’t really work:
&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;&lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;CustomFormBuilder&lt;/span&gt; &amp;lt; &lt;span class="co"&gt;StandardFormBuilder&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;


	&lt;p&gt;It could be he didn’t load the padrino-helpers, as his error was something like &lt;tt&gt;No constant StandardFormBuilder found&lt;/tt&gt; and even &lt;tt&gt;Padrino::Helpers::FormBuilder::StandardFormBuilder&lt;/tt&gt; couldn’t be found.&lt;/p&gt;


	&lt;p&gt;I’ve helped him by looking up in the padrino-code (luckily it’s not that huge) and basically what you do in such situations is to rebuild what you find in that code. In this case we’ve placed the &lt;tt&gt;CustomFormBuilder&lt;/tt&gt; into &lt;tt&gt;Padrino::Helpers::FormBuilder&lt;/tt&gt; and it worked.&lt;/p&gt;


&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;&lt;span class="c"&gt;# put this into app/helpers/custom_form_builder.rb&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;module&lt;/span&gt; &lt;span class="cl"&gt;Padrino&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;module&lt;/span&gt; &lt;span class="cl"&gt;Helpers&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="r"&gt;module&lt;/span&gt; &lt;span class="cl"&gt;FormBuilder&lt;/span&gt; &lt;span class="c"&gt;#:nodoc:&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;CustomFormBuilder&lt;/span&gt; &amp;lt; &lt;span class="co"&gt;StandardFormBuilder&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-06-11:14930</id>
    <published>2010-06-11T06:21:00Z</published>
    <updated>2010-06-11T08:09:21Z</updated>
    <category term="My projects" />
    <category term="Ruby" />
    <category term="mongodb" />
    <category term="photostream" />
    <link href="http://ananasblau.com/2010/6/11/mongodb-in-my-photostre-am" rel="alternate" type="text/html" />
    <title>MongoDB in my photostre.am</title>
<content type="html">
            &lt;p&gt;Time to blog about the reasons why I’ve migrated my &lt;a href="http://photostre.am"&gt;photostre.am&lt;/a&gt; application from MySQL to &lt;a href="http://mongodb.org"&gt;MongoDB&lt;/a&gt;. I hope by this I can give a few people arguments to do the same.&lt;/p&gt;


	&lt;h2&gt;Document based&lt;/h2&gt;


	&lt;p&gt;photostre.am is powered by Ruby, a dynamic and fully object oriented programming language (well, except for blocks). MySQL isn’t that far off when using ruby, you can’t stack data rows into other rows but any decent database adapter will do those relations for you. But if you heart dynamic functionality as much as I do there’s no future for you in a schema database and the schema-less ones your best option.&lt;/p&gt;


	&lt;h2&gt;Arrays&lt;/h2&gt;


	&lt;p&gt;Arrays are a wonderful data structure to work with, e.g. for tags, but if you want to access single elements from an array in a mySQL database you most likely end up creating at least one more table, where you store each single element of your array, and query on that. I know, there are workarounds but MongoDB stores it’s data in &lt;span class="caps"&gt;BSON&lt;/span&gt; format which offers you exactly that in the straightmost way. I couldn’t be more happy to store my tags right inside a photo and retrieving photos that match a tag is only one query. For photostre.am it also allowed me to add new features, for example the Website model stored a domainhost and in the MySQL database I was too lazy for this second table as it wasn’t a much important feature but in MongoDB it has become very quick and easy to add with no loss in performance (and for an object that’s queried with every request that is important.&lt;/p&gt;


	&lt;h2&gt;Embedded objects&lt;/h2&gt;


	&lt;p&gt;This is one of the most amazing features and completes my object oriented programming experience. With MongoDB you can store whole objects inside a parent objects. For example the Website in photostream stores albums and pages which are of course models in my rails application and have all the functionality a regular model would have except the don’t need another collection (table in sql speak). The old database had more than 10 tables, the new one only three collections. It helped me to reduce the number of queries and it just feels natural.&lt;/p&gt;


	&lt;h2&gt;No more &lt;span class="caps"&gt;SQL&lt;/span&gt;&lt;/h2&gt;


	&lt;p&gt;I know &lt;span class="caps"&gt;SQL&lt;/span&gt; quite well. Learned it the hard way in the early 2000s and I always prefer the console over phpMyAdmin and similar. With MongoDB I have a great console, with all modern features and as a bonus it’s all javascript which is a great language and much undervalued by most people but as powerful as ruby.&lt;/p&gt;


	&lt;h2&gt;Sharding&lt;/h2&gt;


	&lt;p&gt;Not yet a feature that I need but photostre.am is close to 200 users now and they all come with around 1000 photos (respectively just the data about those photos) and the database must grow faster in the future if I want to make any money with it. MongoDB with it’s sharding will allow me to split the database horizontal over several small instances and I won’t have to upgrade a single DB server with more &lt;span class="caps"&gt;RAM&lt;/span&gt; and CPUs like you would need with a mySQL database.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-05-17:13638</id>
    <published>2010-05-17T16:55:00Z</published>
    <updated>2010-05-17T17:14:16Z</updated>
    <category term="code" />
    <category term="mongodb" />
    <category term="permalinks" />
    <category term="ruby" />
    <link href="http://ananasblau.com/2010/5/17/permalinks-on-embedded-documents" rel="alternate" type="text/html" />
    <title>Mongoid: Permalinks on embedded documents</title>
<content type="html">
            &lt;p&gt;The target is to create a &lt;tt&gt;permalink&lt;/tt&gt; from the &lt;tt&gt;title&lt;/tt&gt; of the object and append a number if the permalink is already taken by a different object. The code uses Mongoid but I think MonogMapper shouldn’t work that much different nowadays (I yet didn’t have access to the root object of an embedded object in January).&lt;/p&gt;


&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;25&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;&lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;Photo&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  include &lt;span class="co"&gt;Mongoid&lt;/span&gt;::&lt;span class="co"&gt;Document&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  embedded_in &lt;span class="sy"&gt;:parent&lt;/span&gt;, &lt;span class="sy"&gt;:polymorphic&lt;/span&gt; =&amp;gt; &lt;span class="pc"&gt;true&lt;/span&gt;, &lt;span class="sy"&gt;:inverse_of&lt;/span&gt; =&amp;gt; &lt;span class="sy"&gt;:photos&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  before_validate &lt;span class="sy"&gt;:set_permalink&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;set_permalink&lt;/span&gt;(permalink = &lt;span class="pc"&gt;nil&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    title = &lt;span class="pc"&gt;self&lt;/span&gt;.title.strip.blank? ? &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;image&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt; : &lt;span class="pc"&gt;self&lt;/span&gt;.title&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="r"&gt;if&lt;/span&gt; (title &lt;span class="r"&gt;and&lt;/span&gt; &lt;span class="pc"&gt;self&lt;/span&gt;.permalink.blank?) || permalink&lt;tt&gt;
&lt;/tt&gt;      permalink ||= title&lt;tt&gt;
&lt;/tt&gt;      permalink = permalink.to_permalink.strip&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;      permalink_index = &lt;span class="pc"&gt;nil&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class="c"&gt;# get all permalinks of the photo's siblings&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      permalinks = parent.photos.collect(&amp;amp;&lt;span class="sy"&gt;:permalink&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class="r"&gt;while&lt;/span&gt; permalinks.include?([permalink, permalink_index].compact.join(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;))&lt;tt&gt;
&lt;/tt&gt;        permalink_index ||= &lt;span class="i"&gt;0&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        permalink_index += &lt;span class="i"&gt;1&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class="pc"&gt;self&lt;/span&gt;.permalink = [permalink, permalink_index].compact.join(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="c"&gt;# Taken from has_permalink plugin by Nando Vieira released under the MIT license&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;String&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;to_permalink&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    str = &lt;span class="co"&gt;ActiveSupport&lt;/span&gt;::&lt;span class="co"&gt;Multibyte&lt;/span&gt;::&lt;span class="co"&gt;Chars&lt;/span&gt;.new(&lt;span class="pc"&gt;self&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    str = str.normalize(&lt;span class="sy"&gt;:kd&lt;/span&gt;).gsub(&lt;span class="rx"&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="k"&gt;[^&lt;/span&gt;&lt;span class="ch"&gt;\x00&lt;/span&gt;&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="ch"&gt;\x7F&lt;/span&gt;&lt;span class="k"&gt;]&lt;/span&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;/span&gt;,&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).to_s&lt;tt&gt;
&lt;/tt&gt;    str.gsub!(&lt;span class="rx"&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="k"&gt;[^-&lt;/span&gt;&lt;span class="ch"&gt;\w&lt;/span&gt;&lt;span class="ch"&gt;\d&lt;/span&gt;&lt;span class="k"&gt;]+&lt;/span&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="mod"&gt;sim&lt;/span&gt;&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    str.gsub!(&lt;span class="rx"&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="k"&gt;-+&lt;/span&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="mod"&gt;sm&lt;/span&gt;&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    str.gsub!(&lt;span class="rx"&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="k"&gt;^-?(.*?)-?$&lt;/span&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;\1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    str.downcase!&lt;tt&gt;
&lt;/tt&gt;    str&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;


	&lt;p&gt;I admit, quite a trivial issue but maybe my code examples saved someone precious time.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-05-06:13078</id>
    <published>2010-05-06T10:44:00Z</published>
    <updated>2010-05-06T10:45:36Z</updated>
    <category term="Gatherings" />
    <category term="Other" />
    <category term="mongodb" />
    <category term="presentation" />
    <link href="http://ananasblau.com/2010/5/6/mongodb-vortrag-auf-den-linuxwochen-2010" rel="alternate" type="text/html" />
    <title>MongoDB Vortrag auf den Linuxwochen 2010</title>
<content type="html">
            &lt;p&gt;Auf den Linuxwochen 2010 in Wien hab ich einen kleinen Vortrag zu MongoDB gehalten. Hier der Link zum Vortrag:&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://tomk32.github.com/mongodb-presentation-linuxwochen-2010/"&gt;http://tomk32.github.com/mongodb-presentation-linuxwochen-2010/&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-02-19:11257</id>
    <published>2010-02-19T16:30:00Z</published>
    <updated>2010-02-19T16:35:16Z</updated>
    <category term="carrierwave" />
    <category term="images" />
    <category term="ruby" />
    <link href="http://ananasblau.com/2010/2/19/reprocessing-images-in-carrierwave" rel="alternate" type="text/html" />
    <title>reprocessing images in Carrierwave</title>
<content type="html">
            &lt;p&gt;For &lt;a href="http://garmz.com"&gt;garmz&lt;/a&gt; I’m using the &lt;a href="http://github.com/jnicklas/carrierwave"&gt;CarrierWave&lt;/a&gt; plugin and when I had to implement cropping for the images that are attached to our designs I faced the problem of having to regenerate the various versions based with different cropping values.&lt;/p&gt;


	&lt;p&gt;The main principle of my solution is to create new images with new ids, path names etc to prevent any photo not being reloaded on the client side. Otherwise I’d have to invalidate the caches, not my thing.&lt;/p&gt;


	&lt;p&gt;In order to achieve this we create a new Image, assign my cropping parameters and then assign the file from the old Image. For some reasons it looks as if the images are processed once it’s assigned and not when it’s being saved.&lt;/p&gt;


In the Controller:
&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;&lt;span class="r"&gt;if&lt;/span&gt; images = params[&lt;span class="sy"&gt;:crop_images&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;  images.each &lt;span class="r"&gt;do&lt;/span&gt; |image_id, crop_data|&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="r"&gt;next&lt;/span&gt; &lt;span class="r"&gt;if&lt;/span&gt; crop_data.blank?&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;    old_file = object.images.find(image_id).asset.file&lt;tt&gt;
&lt;/tt&gt;    new_image = &lt;span class="co"&gt;Image&lt;/span&gt;.new(&lt;span class="sy"&gt;:crop&lt;/span&gt; =&amp;gt; &lt;span class="co"&gt;JSON&lt;/span&gt;.parse(crop_data).reject{|k,v| !&lt;span class="s"&gt;&lt;span class="dl"&gt;%w(&lt;/span&gt;&lt;span class="k"&gt;x y h w&lt;/span&gt;&lt;span class="dl"&gt;)&lt;/span&gt;&lt;/span&gt;.include?(k)})&lt;tt&gt;
&lt;/tt&gt;    new_image.asset = old_file&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;    new_image.write_asset_identifier&lt;tt&gt;
&lt;/tt&gt;    new_image.store_asset!&lt;tt&gt;
&lt;/tt&gt;    object.images &amp;lt;&amp;lt; new_image&lt;tt&gt;
&lt;/tt&gt;    object.images.find(image_id).destroy&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;


In the model:
&lt;div class="CodeMacro"&gt;
&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td title="click to toggle" class="line_numbers"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;15&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre&gt;&lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;ImageUploader&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  version &lt;span class="sy"&gt;:thumb&lt;/span&gt; &lt;span class="r"&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    process! &lt;span class="sy"&gt;:crop&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;crop&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="r"&gt;return&lt;/span&gt; &lt;span class="r"&gt;if&lt;/span&gt; model.crop.blank?&lt;tt&gt;
&lt;/tt&gt;    manipulate! &lt;span class="r"&gt;do&lt;/span&gt; |img|&lt;tt&gt;
&lt;/tt&gt;      img.crop &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;%ix%i+%i+%i&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; % [model.crop[&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;w&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;], model.crop[&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;h&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;], model.crop[&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;x&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;], model.crop[&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;y&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;]]&lt;tt&gt;
&lt;/tt&gt;    &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;Image&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  include &lt;span class="co"&gt;Mongoid&lt;/span&gt;::&lt;span class="co"&gt;Document&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  field &lt;span class="sy"&gt;:crop&lt;/span&gt;, &lt;span class="sy"&gt;:type&lt;/span&gt; =&amp;gt; &lt;span class="co"&gt;Hash&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  belongs_to &lt;span class="sy"&gt;:designs&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  mount_uploader &lt;span class="sy"&gt;:asset&lt;/span&gt;, &lt;span class="co"&gt;ImageUploader&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-02-01:10946</id>
    <published>2010-02-01T10:26:00Z</published>
    <updated>2010-02-01T10:30:35Z</updated>
    <category term="My projects" />
    <category term="Tools" />
    <category term="migration" />
    <category term="mongodb" />
    <category term="mongomapper" />
    <category term="mysql" />
    <link href="http://ananasblau.com/2010/2/1/mysql-to-mongodb-conversion" rel="alternate" type="text/html" />
    <title>MySQL to MongoDB conversion</title>
<content type="html">
            &lt;p&gt;For &lt;a href="http://photostre.am"&gt;photostre.am&lt;/a&gt; I wrote an migration script to migrate the MySQL database to MongoMapper.&lt;/p&gt;


	&lt;p&gt;Maybe it’s good use for someone, this is the actual script at &lt;a href="gist.github.com/gists/290175"&gt;gist.github.com&lt;/a&gt; and no abstract something which you give up to extend after a while. The migration actually uses ActiveRecord::Migration, could well be about the last one that I’ll ever write.&lt;/p&gt;


Lessons learned:
	&lt;ul&gt;
	&lt;li&gt;Keep the old id from MySQL for a while, but &lt;strong&gt;rename&lt;/strong&gt; it&lt;/li&gt;
		&lt;li&gt;Don’t do too many EmbeddedDocuments&lt;/li&gt;
	&lt;/ul&gt;



          </content>  </entry>
  <entry xml:base="http://ananasblau.com/">
    <author>
      <name>TomK32</name>
    </author>
    <id>tag:ananasblau.com,2010-01-25:10823</id>
    <published>2010-01-25T13:08:00Z</published>
    <updated>2010-01-25T13:15:12Z</updated>
    <category term="My projects" />
    <category term="photostre.am" />
    <category term="projects" />
    <link href="http://ananasblau.com/2010/1/25/photostre-am" rel="alternate" type="text/html" />
    <title>photostre.am</title>
<content type="html">
            &lt;p&gt;I totally forgot to blog about &lt;a href="http://www.photostre.am"&gt;photostre.am&lt;/a&gt; here. It’s a project which I’ve worked on since October 2008, put it aside after the first hundrets lines of code and then picked it up again in Summer. And in October it finally went online. In those three months since I saw lots of improvements but it’s still not finished or making any money.&lt;/p&gt;


	&lt;p&gt;The problem I’ve faced back then was that I have loads of photos on flickr, most shot with my favourite analogue cameras, but no proper portfolio website. Of course you can point people to your flickr website, or even the sideshow there, but it’s not the same. There are a few tool around that show your photos on black background, or javascript widgets that you put into your website, but not a single solution solved the problem from front to end. From photo import, rearranging, grouping, albums, multiple domains, static content pages, no tool does that, except for photostre.am. Just after releasing it I actually found a tool which solved the problem almost, but still my webapplication has a brighter future to come.&lt;/p&gt;


	&lt;p&gt;Checkout the &lt;a href="http://blog.photostre.am"&gt;blog&lt;/a&gt;, the &lt;a href="http://twitter.com/photostre_am"&gt;Twitter account&lt;/a&gt; and did I mention the app is white-labeled? No, then go for &lt;a href="http://www.365shots.net"&gt;365shots.net&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
</feed>

