<?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>Floorplanner Tech Blog &#187; Gert-Jan</title>
	<atom:link href="http://techblog.floorplanner.com/author/gert-jan-van-der-wel/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 19 Nov 2009 04:00:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Database replication in 5 easy steps</title>
		<link>http://techblog.floorplanner.com/2009/11/09/database-replication-in-5-easy-steps/</link>
		<comments>http://techblog.floorplanner.com/2009/11/09/database-replication-in-5-easy-steps/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 13:34:00 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[database replication mysql]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=753</guid>
		<description><![CDATA[Running an online service like Floorplanner is not without risks. There are a lot of things that can go wrong. One of them is downtime of your service due to a crashing system. It doesn&#8217;t have to happen of course, but when it does, it can have some nasty consequences. A good way to reduce [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F11%2F09%2Fdatabase-replication-in-5-easy-steps%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F11%2F09%2Fdatabase-replication-in-5-easy-steps%2F" height="61" width="51" /></a></div><p>Running an online service like <a href="http://floorplanner.com">Floorplanner</a> is not without risks. There are a lot of things that can go wrong. One of them is downtime of your service due to a crashing system. It doesn&#8217;t have to happen of course, but when it does, it can have some nasty consequences. A good way to reduce the risk of a crashing system is to set up a redundant system.</p>
<p>In short, a redundant system is an exact copy of your main system. When your main system goes down (for whatever reason), the redundant system can take over. One of the most important parts of any online service is the database. A way to maintain an exact copy of your database is setting up database replication. This post gives you the basics on how to set up database replication using a MySQL database.</p>
<p>Database replication isn&#8217;t probably something you&#8217;d setup right from the start. This means that you have to work with a running system when you decide to do so. From past experience we know that it&#8217;s not a good idea to replicate your database to the same machine, let alone to the same disk. To make this work, you need a separate machine with MySQL installed. This is your slave machine and database.</p>
<p>Let&#8217;s get down to business. These are the steps for setting up database replication:</p>
<ol>
<li>Enable binary logging on master database</li>
<li>Create a backup of master database</li>
<li>Transfer backup to slave machine</li>
<li>Import backup to slave database</li>
<li>Start slave database</li>
</ol>
<h3>1. Enable binary logging on master database</h3>
<blockquote><p><em>The binary log contains all statements that update data [..]. Statements are stored in the form of “events” that describe the modifications. The binary log also contains information about how long each statement took that updated data.</em></p></blockquote>
<p>Every write action that&#8217;s performed on your database, like an insert or an update, is stored in these binary logs (bin logs). The master dumps all actions in these logs and the slave database can read them  and perform the same actions. This way your master and slave databases will always have the same data.</p>
<p>To enable binary logging you have to create a config file, for example master.cnf. An important thing here is the server-id, which is needed for replication to work. Then there is log-bin which specifies base name of binary logs, and finally binlog-do-db, which specifies which databases should be bin logged.</p>

<div class="wp_syntax"><div class="code"><pre class="cnf" style="font-family: Monaco,monospace;">[mysqld]
datadir=/home/yourname/mysql/myisam/data
basedir=/usr/local/mysql
port=3306
server-id=1
log-bin=mysql-bin
binlog-do-db=my_fat_db1
binlog-do-db=ma_other_fat_db</pre></div></div>

<p>Then start (or restart) the master database using the config file:</p>

<div class="wp_syntax"><div class="code"><pre class="cnf" style="font-family: Monaco,monospace;">~ $ mysqld --defaults-file=master.cnf&amp;amp;</pre></div></div>

<p>The slave database needs a userid/password in order to access the master machine. It&#8217;s best practice create a dedicated user with just the required privileges. This can be done with the following SQL statement.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> replication slave <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">*.*</span> <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">'repl'</span>@<span style="color: #ff0000;">'slave-ip-here'</span></pre></div></div>

<h3>2. Create a backup of master database</h3>
<p>The next step it to create a backup of your master database. The type of your database is very important for this action. If you use MyISAM, you need to schedule some downtime to dump your database. Otherwise the dumped data isn&#8217;t consistent and therefor useless. <span style="background-color:#FFE789">With InnoDB it&#8217;s possible to dump a consistent backup of your database while keeping it up and running</span>. We stumbled on this feature by accident, but we haven&#8217;t been able to in the official documentation.</p>
<p>MyISAM</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">~ $ mysqldump --lock-all-tables</pre></div></div>

<p>InnoDB</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">~ $ mysqldump --single-transaction</pre></div></div>

<h3>3. Transfer backup to slave machine</h3>
<p>Now that the backup is created on the master machine, it needs to be transferred to the slave machine.</p>
<h3>4. Import backup to slave database</h3>
<p>Once the backup is present on the slave machine, it can be imported into the slave database:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family: Monaco,monospace;">~ $ mysql &amp;lt; filename</pre></div></div>

<h3>5. Start slave database</h3>
<p>The last step is to tell the database that it&#8217;s a slave database. First we have to give it an server id. We use a config file for this, slave.cnf:</p>

<div class="wp_syntax"><div class="code"><pre class="cnf" style="font-family: Monaco,monospace;">[mysqld]
datadir=/home/yourname/mysql/myisam/data
basedir=/usr/local/mysql
port=3306
server-id=2
replicate-do-db=my_fat_db1
replicate-do-db=my_other_fat_db</pre></div></div>

<p>Then we start the database with this config file:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family: Monaco,monospace;">~ $ mysqld --defaults-file=slave.cnf&amp;amp;</pre></div></div>

<p>and we issue the following SQL statement:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">CHANGE</span> MASTER <span style="color: #993333; font-weight: bold;">TO</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_HOST<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'master-ip-here'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_PORT<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">3306</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_USER<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_PASSWORD<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'repl'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_LOG_FILE<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'bin-log-filename-here'</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">-</span>&amp;gt; MASTER_LOG_POS<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">4</span>;</pre></div></div>

<p>It&#8217;s hard to predict the MASTER_LOG_POS. You can find this number by issuing the following SQL statement on the <strong>master</strong> database:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">SHOW</span> MASTER <span style="color: #993333; font-weight: bold;">STATUS</span>\G;</pre></div></div>

<p>Once the slave is configured correctly it will get the bin logs from the master machine, parse them and execute each action. It takes some time to have an exact copy of the master database, depending on the size and number of bin logs. To get an idea about the delay, issue the following query:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family: Monaco,monospace;"><span style="color: #993333; font-weight: bold;">SHOW</span> SLAVE <span style="color: #993333; font-weight: bold;">STATUS</span>\G;</pre></div></div>

<p>With this post we hope to contribute to a less riskier world and more peaceful state of mind for the sys admins out there <img src='http://techblog.floorplanner.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/11/09/database-replication-in-5-easy-steps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Build ActionScript3 projects with TextMate in 5 easy steps</title>
		<link>http://techblog.floorplanner.com/2009/09/05/build-actionscript3-projects-with-textmate-in-5-easy-steps/</link>
		<comments>http://techblog.floorplanner.com/2009/09/05/build-actionscript3-projects-with-textmate-in-5-easy-steps/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 11:51:34 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[textmate actionscript flex sdk]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=704</guid>
		<description><![CDATA[The text editor of choice of our Rails team is TextMate. Our Flash team is a bit divided between Eclipse+FDT and FlexBuilder. I wanted to see if TextMate is a good alternative for building Flash/ActionScript projects.
There are a couple of good sources on using TexMate for ActionScript projects, but it&#8217;s a little fragmented and sometimes [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F09%2F05%2Fbuild-actionscript3-projects-with-textmate-in-5-easy-steps%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F09%2F05%2Fbuild-actionscript3-projects-with-textmate-in-5-easy-steps%2F" height="61" width="51" /></a></div><p>The text editor of choice of our Rails team is TextMate. Our Flash team is a bit divided between Eclipse+FDT and FlexBuilder. I wanted to see if TextMate is a good alternative for building Flash/ActionScript projects.</p>
<p>There are a couple of good sources on using TexMate for ActionScript projects, but it&#8217;s a little fragmented and sometimes outdated. I found <a href="http://www.pixelate.de/blog/setting-up-a-as3-project-in-textmate">pixelate&#8217;s blog post</a> and <a href="http://blog.simongregory.com/">Simon&#8217;s blog</a> very useful.</p>
<h3>1. TextMate</h3>
<p>First of all, you need have MacroMates&#8217; <a href="http://macromates.com/">TexMate</a> of course. If you don&#8217;t already own a copy, you can download a <a href="http://download-b.macromates.com/TextMate_1.5.9.dmg">30-day-trial</a>.</p>
<h3>2. ActionScript3 bundle</h3>
<p><a href="http://blog.simongregory.com/">Simon Gregory</a> did some fine work by creating a TextMate bundle for ActionScript3. The most important things that the bundle handles are <a href="http://blog.simongregory.com/09/as3-autocompletion-in-textmate/">auto-completion</a> and <a href="http://blog.simongregory.com/02/improved-auto-import-for-actionscript-3-in-textmate/">auto-import</a>.  You can <a href="http://blog.simongregory.com/wp-content/assets/bundles/ActionScript%203.tmbundle.zip">download it</a> directly from his blog, or fetch it with Git or SVN.</p>
<p>To install via Subversion:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">export LC_CTYPE=en_US.UTF-8
cd ~/&quot;Library/Application Support/TextMate/Bundles/&quot;
svn co http://svn.textmate.org/trunk/Review/Bundles/ActionScript\ 3.tmbundle
osascript -e 'tell app &quot;TextMate&quot; to reload bundles'</pre></div></div>

<p>To install via Git:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">cd ~/&quot;Library/Application Support/TextMate/Bundles/&quot;
git clone git://github.com/simongregory/actionscript3-tmbundle.git &quot;ActionScript 3.tmbundle&quot;
osascript -e 'tell app &quot;TextMate&quot; to reload bundles'</pre></div></div>

<h3>3. Flex SDK</h3>
<p>The actual building of your project is done by the free <a href="http://www.adobe.com/cfusion/entitlement/index.cfm?e=flexbuilder3&#038;promoid=DJGYF">Flex 3 SDK</a>. Download it and move the extracted folder into your /Developer/SDKs/ folder. The SDK has to be accessible throughout your whole system. You can do this by adding it to the PATH variable in the /etc/profile file. Open terminal and type:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">sudo mate /etc/profile</pre></div></div>

<p>Then add the folder &#8220;/Developers/SDKs/flex_sdk_3/bin&#8221; to the file and save it. It should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">PATH=&quot;/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin:/Developer/SDKs/flex_sdk_3/bin&quot;</pre></div></div>

<h3>4. TextMate settings</h3>
<p>Before we can start the ActionScript fun we have to setup a few things in TextMate. Open TextMate and select File→New Project. Click on the info button located in the bottom of the Project Drawer. Add two shell variables so that the ActionScript Bundle knows where to look for your files:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">TM_FLEX_FILE_SPECS    src/Main.as
TM_FLEX_OUTPUT        bin/Main.swf</pre></div></div>

<p>We also need to let TextMate know where the Flex SDK is located. Go to TextMate→Preferences→Advanced→Shell Variables and add a new global variable:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family: Monaco,monospace;">TM_FLEX_PATH    Developer/SDKs/flex_sdk_3</pre></div></div>

<h3>5. Hello World</h3>
<p>With all that out of the way, we can finally start working on a ActionScript project: Hello World. Create a folder on your system that will hold this project. Drag this folder to TextMate&#8217;s Project Drawer. Create two new folders named bin and src in your project folder. Then create a new file in the src folder and name it Main.as. It should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;">package <span style="color: #66cc66;">&#123;</span>        
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
&nbsp;
    <span style="color: #66cc66;">&#91;</span>SWF<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">'0xFFFFFF'</span>, frameRate=<span style="color: #ff0000;">'30'</span>, <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">'200'</span>, <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">'200'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">textField</span>: <span style="color: #0066CC;">TextField</span>;
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">textField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">textField</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Hello World.&quot;</span>;
&nbsp;
            addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textField</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>        
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Choose Bundles→ActionScript 3→Build to build your project. A terminal window pops up which runs the Flex SDK to build your project. You can find the resulting Main.swf file in your bin folder. Yay!</p>
<h3>Notes</h3>
<p>If you want to build Flash Player 10 specific stuff (like me) you have to let the Flex SDK know. Open /Developer/SDKs/flex_sdk_3/frameworks/flex-config.xml and set the target-player tag to 10.0.0</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family: Monaco,monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target-player<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target-player<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The easiest way to work with libraries, the so called SWC files, in this setup is to drop them directly into /Developer/SDKs/flex_sdk_3/frameworks/libs folder. That way the Flex SDK has no problem finding them.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/09/05/build-actionscript3-projects-with-textmate-in-5-easy-steps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Debug your web service with HTTP Client</title>
		<link>http://techblog.floorplanner.com/2009/05/26/debug-your-web-service-with-http-client/</link>
		<comments>http://techblog.floorplanner.com/2009/05/26/debug-your-web-service-with-http-client/#comments</comments>
		<pubDate>Tue, 26 May 2009 09:51:42 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[http client]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=642</guid>
		<description><![CDATA[The last couple of weeks we&#8217;ve been working on a big integration project. The largest real estate portal of The Netherlands, Funda, uses Floorplanner to deliver interactive floor plans to their clients. They use our API&#8217;s to seamlessly integrate the Floorplanner into their back end system and front end website.
One of our API&#8217;s is our [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F05%2F26%2Fdebug-your-web-service-with-http-client%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F05%2F26%2Fdebug-your-web-service-with-http-client%2F" height="61" width="51" /></a></div><p>The last couple of weeks we&#8217;ve been working on a big integration project. The largest real estate portal of The Netherlands, <a href="http://www.funda.nl">Funda</a>, uses Floorplanner to deliver <a href="http://www.funda.nl/koop/dronten/huis-4217508-de-morinel-43-45/plattegrond/">interactive floor plans </a>to their clients. They use our API&#8217;s to seamlessly integrate the Floorplanner into their back end system and front end website.</p>
<p>One of our API&#8217;s is our RESTful web service. With it one can manage users, project, floors, designs etc. We set up a whole testing suite around it, but every now and then I wanted to test a single method by hand. For this I used the command line tool <a href="http://curl.haxx.se/">cURL</a> which looks something like this (getting all users):</p>

<div class="wp_syntax"><div class="code"><pre class="curl" style="font-family: Monaco,monospace;">curl -H &quot;Content-Type: application/xml&quot; 
-u &quot;username:password&quot; 
-X GET https://floorplanner.com/users.xml</pre></div></div>

<p>It works, but it&#8217;s kind of a hassle. One day <a href="https://twitter.com/whenyouneedmi">Michel</a> showed me <a href="http://ditchnet.org/httpclient/">HTTP Client</a>: </p>
<blockquote><p><i>A Mac OS X Leopard developer tool for debugging HTTP services by graphically creating &#038; inspecting complex HTTP messages.</i></p></blockquote>
<p>HTTP Client makes testing a web service by hand much easier. You can select any REST method you need from a pull down menu. Setting up your header is done by a few mouse clicks and the result is nicely formatted. </p>
<p><img src="http://techblog.floorplanner.com/wp-content/uploads/2009/05/afbeelding-1-600x421.png" alt="HTTP Client sample" title="HTTP Client sample" width="600" height="421" class="alignnone size-large wp-image-652" /></p>
<p>The only thing that didn&#8217;t seem to work out of the box was Basic HTTP Authentication. I found a workaround for this: add the authorization to the header myself. To do this use &#8220;Authorization&#8221; as header name. For the header value you have to encode the username and password with <a href="http://en.wikipedia.org/wiki/Base64">Base64</a> with a &#8220;:&#8221; as separator. For example in PHP: base64_encode(username:password). There are also a couple of websites around where you can encode a string to Base64. When you have the encoded string, you can add &#8220;Basic <i>encoded string here</i>&#8221; as a header value and you&#8217;re ready to roll.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/05/26/debug-your-web-service-with-http-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Load, modify and save local images with Flash Player 10</title>
		<link>http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-player-10/</link>
		<comments>http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-player-10/#comments</comments>
		<pubDate>Mon, 04 May 2009 11:53:10 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flash player 10]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[local file system]]></category>
		<category><![CDATA[pixel bender]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=609</guid>
		<description><![CDATA[ // 



One of the cool new things about Flash Player 10 is that you now have access to the local file system. This means that you can load, modify and save files directly on the client side without any server interaction. Mike Chambers wrote a post about reading and writing text files and I [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F05%2F04%2Fload-modify-and-save-local-images-with-flash-player-10%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F05%2F04%2Fload-modify-and-save-local-images-with-flash-player-10%2F" height="61" width="51" /></a></div><p><script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js" type="text/javascript"></script> <script type="text/javascript">// <![CDATA[
 window.onload = function() { swfobject.embedSWF("http://techblog.floorplanner.com/wp-content/uploads/2009/05/main.swf", 'thumbr', '280', '265', '10.0.0'); }
// ]]&gt;</script></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top">One of the cool new things about Flash Player 10 is that you now have access to the local file system. This means that you can load, modify and save files directly on the client side without any server interaction. <a href="http://twitter.com/mesh">Mike Chambers</a> wrote a post about <a href="http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/">reading and writing text files</a> and I was wondering if it was possible to do this with image files too.</td>
<td>
<div id="thumbr">thumbr here</div>
</td>
<td valign="top"></td>
</tr>
</tbody>
</table>
<h3>Publish Flash Player 10 content</h3>
<p>To test this, I first needed a way to make my Flex Builder compile Flash Player 10 content. I found a rather old post by <a href="http://www.flexer.info/author/webdevandrei/">Andrei Ionescu</a> about<a href="http://www.flexer.info/2008/05/21/how-to-build-flash-player-10-applications-using-flex-sdk/"> building Flash Player 10 applications</a> that told me exactly what I was looking for. I downloaded the latest Flex SDK (3.3) from <a href="http://www.adobe.com/products/flex/flexdownloads/">Adobe&#8217;s Flex Download page</a>, followed the tutorial and I was ready to go.</p>
<h3>Load image from local file system</h3>
<p>Reading a local file was no biggie, just copied and pasted the code from Mike&#8217;s sample. What I needed now was a way to convert the loaded data into an image. As usual <a href="http://twitter.com/timknip">Tim</a> helped me out by sending me a snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:ByteArray = fileRef<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'data'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span>loader<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h3>Modify image</h3>
<p>Now that I could load the image, I wanted to modify it before having it rendered. I extended the snippet to use BitmapData and a Matrix to resize the image to a thumb image (240&#215;180px).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onDataLoadComplete<span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span>loadFileRef.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDataLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
  <span style="color: #000000; font-weight: bold;">var</span> matrix:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  matrix.<span style="color: #006600;">scale</span><span style="color: #66cc66;">&#40;</span>THUMB_WIDTH<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">width</span>, THUMB_HEIGHT<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">beginBitmapFill</span><span style="color: #66cc66;">&#40;</span>bitmapData, matrix, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, THUMB_WIDTH, THUMB_HEIGHT<span style="color: #66cc66;">&#41;</span>;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Save image to local file system</h3>
<p>Now that it&#8217;s possible to load and modify an image, saving it is the last step. To save an image, it has to be encoded to a ByteArray. I used the open source <a href="http://code.google.com/p/as3corelib/">as3corelib</a> to help me out. Saving the ByteArray to a file is rather straight forward.</p>
<p><strong>Update 1:</strong> You don&#8217;t need to use the as3corelib anymore, Flex 3.3 has it own <a href="http://livedocs.adobe.com/flex/3/langref/mx/graphics/codec/JPEGEncoder.html">JPEGEncoder</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">var</span> encoder:JPEGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPEGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rawBytes:ByteArray = encoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bitmapData<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> saveFileRef:FileReference = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
saveFileRef.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>rawBytes<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><strong>Update 2:</strong> <a href="http://www.bytearray.org/">Thibault Imbert</a> figured out a way to <a href="http://www.bytearray.org/?p=775">speed up JPEG encoding</a> using the new FP10 Vector class. Good stuff!</p>
<p><strong>Update 3</strong>: You can now also use Alchemy for the encoding. It&#8217;s much, much faster then the other options! See this post from <a href="http://www.websector.de/blog/">Jens Krause</a>: <a href="http://www.websector.de/blog/2009/06/21/speed-up-jpeg-encoding-using-alchemy/">Speed up JPEG encoding using Alchemy</a></p>
<p>This sample shows that it&#8217;s not only possible to load, modify and save images directly from the local file system, but that it&#8217;s actually very simple to do so. Add some <a href="http://labs.adobe.com/technologies/pixelbender/">PixelBender</a> image processing power to the game and you almost have a Photoshop killer running completly client side!</p>
<h3>Code sample</h3>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> backgroundGradientColors=<span style="color: #ff0000;">&quot;[0xFFFFFF,0xFFFFFF]&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;0xFFFFFF&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">codec</span>.<span style="color: #006600;">JPEGEncoder</span>;
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">binding</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">BindingUtils</span>;
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">UIComponent</span>;
&nbsp;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">FileReference</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">FileFilter</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">IOErrorEvent</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loadFileRef:FileReference;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const FILE_TYPES:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #000000; font-weight: bold;">new</span> FileFilter<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Image Files&quot;</span>, <span style="color: #ff0000;">&quot;*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
			<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const THUMB_WIDTH:uint = <span style="color: #cc66cc;">240</span>;
			<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const THUMB_HEIGHT:uint = <span style="color: #cc66cc;">180</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				loadFileRef = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				loadFileRef.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SELECT</span>, onFileSelect<span style="color: #66cc66;">&#41;</span>;
				loadFileRef.<span style="color: #006600;">browse</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> saveFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>		
				<span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>THUMB_WIDTH, THUMB_HEIGHT<span style="color: #66cc66;">&#41;</span>;
				bitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>imageView<span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> encoder:JPEGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPEGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> rawBytes:ByteArray = encoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bitmapData<span style="color: #66cc66;">&#41;</span>;
&nbsp;
 				<span style="color: #000000; font-weight: bold;">var</span> saveFileRef:FileReference = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				saveFileRef.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>rawBytes<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFileSelect<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				loadFileRef.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onFileLoadComplete<span style="color: #66cc66;">&#41;</span>;
				loadFileRef.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFileLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			   	<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			   	loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onDataLoadComplete<span style="color: #66cc66;">&#41;</span>;
			   	loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span>loadFileRef.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				loadFileRef = <span style="color: #000000; font-weight: bold;">null</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDataLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
&nbsp;
                <span style="color: #000000; font-weight: bold;">var</span> matrix:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                matrix.<span style="color: #006600;">scale</span><span style="color: #66cc66;">&#40;</span>THUMB_WIDTH<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">width</span>, THUMB_HEIGHT<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">beginBitmapFill</span><span style="color: #66cc66;">&#40;</span>bitmapData, matrix, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>; 
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, THUMB_WIDTH, THUMB_HEIGHT<span style="color: #66cc66;">&#41;</span>;
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
				saveButton.<span style="color: #0066CC;">enabled</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:Panel title=<span style="color: #ff0000;">&quot;Create thumb image&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;5&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:VBox<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:Canvas id=<span style="color: #ff0000;">&quot;imageView&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;240&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;180&quot;</span> borderThickness=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #0066CC;">borderColor</span>=<span style="color: #ff0000;">&quot;#CCCCCC&quot;</span> borderStyle=<span style="color: #ff0000;">&quot;solid&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:HBox paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span> borderThickness=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Load image&quot;</span> click=<span style="color: #ff0000;">&quot;loadFile()&quot;</span><span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Save image&quot;</span> click=<span style="color: #ff0000;">&quot;saveFile()&quot;</span> id=<span style="color: #ff0000;">&quot;saveButton&quot;</span> <span style="color: #0066CC;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:VBox<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-player-10/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Umair on Constructive Capitalism</title>
		<link>http://techblog.floorplanner.com/2009/02/21/umair-on-constructive-capitalism/</link>
		<comments>http://techblog.floorplanner.com/2009/02/21/umair-on-constructive-capitalism/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 22:16:09 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Off topic]]></category>
		<category><![CDATA[capitalism]]></category>
		<category><![CDATA[daytona]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[umair]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=479</guid>
		<description><![CDATA[This might be a little off topic, but I found it interesting enough to share it with you all. It&#8217;s about the future of capitalism: Constructive Capitalism through the principles of Renewal, Peace, Equity, Meaning and Democracy. 
It&#8217;s a presentation Umair Haque gave at Daytona Sessions last month. Umair Haque is Director of the Havas Media Lab, a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F21%2Fumair-on-constructive-capitalism%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F21%2Fumair-on-constructive-capitalism%2F" height="61" width="51" /></a></div><p>This might be a little off topic, but I found it interesting enough to share it with you all. It&#8217;s about the future of capitalism: Constructive Capitalism through the principles of Renewal, Peace, Equity, Meaning and Democracy. </p>
<p>It&#8217;s a presentation Umair Haque gave at <a href="http://www.daytona.se/sessions">Daytona Sessions</a> last month. Umair Haque is Director of the <a class="external" href="http://www.havasmedialab.com/">Havas Media Lab</a>, a new kind of strategic advisor that helps investors, entrepreneurs, and firms experiment with, craft, and drive radical management, business model, and strategic innovation. Daytona Sessions is a recurring conference about the future of business and Internet held in Stockholm, Sweden. </p>
<p>Enjoy!</p>
<p><object width="580" height="325" data="http://vimeo.com/moogaloop.swf?clip_id=3204792&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=1&amp;color=ff9daa&amp;fullscreen=1" type="application/x-shockwave-flash"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=3204792&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=1&amp;color=ff9daa&amp;fullscreen=1" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/02/21/umair-on-constructive-capitalism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write JAVA, publish SWF</title>
		<link>http://techblog.floorplanner.com/2009/02/15/write-java-publish-swf/</link>
		<comments>http://techblog.floorplanner.com/2009/02/15/write-java-publish-swf/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 20:27:16 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=474</guid>
		<description><![CDATA[Ted Patrick (Senior Manager Developer Communities at Adobe Systems) has posted an interesting article about the first milestone of the Eclipse E4 project.
It seems that the SWT project has added compilation support for SWF from JAVA. Write your app in JAVA and publish as SWF to Flash Player. The cool part is that you get full [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F15%2Fwrite-java-publish-swf%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F15%2Fwrite-java-publish-swf%2F" height="61" width="51" /></a></div><p>Ted Patrick (Senior Manager Developer Communities at Adobe Systems) has posted <a title="Write JAVA, publish SWF" href="http://onflash.org/ted/2009/02/publish-swt-to-flash-player.php" target="_blank">an interesting article</a> about the first milestone of the <a title="Ecilpse E4 project" href="http://download.eclipse.org/e4/downloads/drops/S-0.9M1-200902061045/e4-news-M1.html" target="_blank">Eclipse E4 project</a>.</p>
<blockquote><p><em>It seems that the SWT project has added compilation support for SWF from JAVA. Write your app in JAVA and publish as SWF to Flash Player. The cool part is that you get full JAVA development in Eclipse with all debugging and tooling but you get a SWF file on publish. </em></p></blockquote>
<p>We&#8217;re using Flex Builder for our Flex/AS3 stuff, but this could become a very interesting option since the JAVA development in Eclipse is a lot more sophisticated than Flex Builder at the moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/02/15/write-java-publish-swf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wii Boxing</title>
		<link>http://techblog.floorplanner.com/2009/02/08/wii-boxing/</link>
		<comments>http://techblog.floorplanner.com/2009/02/08/wii-boxing/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 20:20:39 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Off topic]]></category>
		<category><![CDATA[boxing]]></category>
		<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[movie]]></category>
		<category><![CDATA[sports]]></category>
		<category><![CDATA[wii]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=469</guid>
		<description><![CDATA[Gert-Jan is on the left side and Jaap on the right.

Nico is on the left side and Willem on the right.

]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F08%2Fwii-boxing%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F08%2Fwii-boxing%2F" height="61" width="51" /></a></div><p>Gert-Jan is on the left side and Jaap on the right.<br />
<object width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=67090" type="application/x-shockwave-flash"><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=2f291901e4&amp;photo_id=3258214049" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" /><param name="src" value="http://www.flickr.com/apps/video/stewart.swf?v=67090" /><param name="allowfullscreen" value="true" /></object></p>
<p>Nico is on the left side and Willem on the right.<br />
<object width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=67090" type="application/x-shockwave-flash"><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=8646dc1cba&amp;photo_id=3259024322" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" /><param name="src" value="http://www.flickr.com/apps/video/stewart.swf?v=67090" /><param name="allowfullscreen" value="true" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/02/08/wii-boxing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Floorplanning in the Cloud, EC2</title>
		<link>http://techblog.floorplanner.com/2009/02/05/floorplanning-in-the-cloud-ec2/</link>
		<comments>http://techblog.floorplanner.com/2009/02/05/floorplanning-in-the-cloud-ec2/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 20:25:33 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=436</guid>
		<description><![CDATA[There is a lot of hype these day about being in &#8220;the cloud&#8221;. However, &#8220;the cloud&#8221; seems to mean a lot of different things. Tim O&#8217;Reilly sees three types of cloud computing.  His first type, utility computing, is the type I&#8217;m talking about here. 
Utility computing. Amazon&#8217;s success in providing virtual machine instances, storage, and computation at pay-as-you-go utility [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F05%2Ffloorplanning-in-the-cloud-ec2%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F05%2Ffloorplanning-in-the-cloud-ec2%2F" height="61" width="51" /></a></div><p>There is a lot of hype these day about being in &#8220;the cloud&#8221;. However, &#8220;the cloud&#8221; seems to mean a lot of different things. Tim O&#8217;Reilly sees <a href="http://radar.oreilly.com/2008/10/web-20-and-cloud-computing.html">three types of cloud computing</a>.  His first type, utility computing, is the type I&#8217;m talking about here. </p>
<blockquote><p><strong><em>Utility computing.</em></strong><em> Amazon&#8217;s success in providing virtual machine instances, storage, and computation at pay-as-you-go utility pricing was the breakthrough in this category, and now everyone wants to play. Developers, not end-users, are the target of this kind of cloud computing.</em></p></blockquote>
<p>Launched in July 2002, <a title="Amazon Web Services" href="http://aws.amazon.com" target="_blank">Amazon Web Services</a> provide online services for other web sites or client-side applications.<span style="text-decoration: underline;"> </span>Each individual product is interesting by itself, but all the services together made it just the solution we were looking for. In this and coming posts I will talk about our experiences with Amazon&#8217;s version of &#8220;the cloud&#8221;. The first service we started to use was <a href="http://aws.amazon.com/ec2/">Elastic Cloud Computing</a> (EC2).</p>
<p>Each day more than 2000 users from all over the world register at Floorplanner.com. At this moment we have over 800.000 registered users in our database. A lot of these users visit the site on a regular basis, which generates a lot of traffic. To meet this demand, we had a couple of dedicated servers running. When the demand rised above a certain level, we&#8217;d add a new one to spread the load. As logical as it might sound, it is far from ideal.</p>
<p>It takes a lot of time to install, configure and maintain a server. Precious time you can&#8217;t spend on the development of your product. It doesn&#8217;t scale fast. For example: when you are featured on a big site that generates a lot of additional traffic, your servers will probably have a very hard time (or crash) and there is nothing you can do about it. Buying additional servers takes too much time. Another thing about buying servers is that it&#8217;s an investment you have to finance up front. You have to pay the full price for it, but in the beginning you&#8217;ll only use a small part of it&#8217;s capacities. Once you&#8217;ve spend the money on a server, you can&#8217;t spend it on anything else. And maybe the biggest issue we had with dedicated servers was that it is hardware, and hardware gets old very fast. After a while you&#8217;re stuck with an outdated server, that you (a) won&#8217;t replace because &#8220;it&#8217;s still doing something&#8221; or (b) costs time (= money) to migrate to another server. This means a higher risk for failure, or just more work.   </p>
<p>Now with the EC2 service life has gotten better. Sure, we still had to install everything on the virtual instance, but only the first time. Once you&#8217;ve done this, you can add additional instances with a click of a button (based on an image of the first instance). When traffic spikes you can add instances within minutes instead of days. The pay-as-you-go model keeps us from financing every server up front. And because it&#8217;s a virtual server, we don&#8217;t have to think about the hardware anymore. Just deploy it and get on with the fun stuff!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/02/05/floorplanning-in-the-cloud-ec2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FITC Amsterdam 2009</title>
		<link>http://techblog.floorplanner.com/2009/01/24/fitc-amsterdam-2009/</link>
		<comments>http://techblog.floorplanner.com/2009/01/24/fitc-amsterdam-2009/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 10:52:57 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[amsterdam]]></category>
		<category><![CDATA[fitc]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=419</guid>
		<description><![CDATA[
On February 22-24th the Flash In The Can event is back in town! Design, Technology. Cool shit. I will be just a visitor, but Tim is going to help Ralph with his workshop Papervision3D from the Core. If you want to meet up, give us a ping.
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F01%2F24%2Ffitc-amsterdam-2009%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F01%2F24%2Ffitc-amsterdam-2009%2F" height="61" width="51" /></a></div><p><a href="http://fitc.ca"><img class="alignnone size-full wp-image-421" title="FITC Amsterdam 2009" src="http://techblog.floorplanner.com/wp-content/uploads/2009/01/afbeelding-1.png" alt="FITC Amsterdam 2009" width="598" height="150" /></a></p>
<p>On February 22-24th the Flash In The Can event is back in town! Design, Technology. Cool shit. I will be just a visitor, but Tim is going to help <a title="Ralph Hauwert" href="http://www.unitzeroone.com/blog/" target="_blank">Ralph</a> with his workshop <a title="Papervision3D from the Core" href="http://www.fitc.ca/presentation_detail.cfm?festival_id=80&amp;presentation_id=749" target="_blank">Papervision3D from the Core</a>. If you want to meet up, give us a ping.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/01/24/fitc-amsterdam-2009/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to remove hidden tab characters</title>
		<link>http://techblog.floorplanner.com/2008/12/17/how-to-remove-hidden-tab-characters/</link>
		<comments>http://techblog.floorplanner.com/2008/12/17/how-to-remove-hidden-tab-characters/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 13:31:37 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tab character]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=367</guid>
		<description><![CDATA[At this moment, all the language translations of the Floorplanner 2D app are stored in a database table. Today we discovered that a couple of these translations didn&#8217;t align properly in the interface. After some investigation we discovered that they all contained a hidden tab character at the end of  each string. This was probably [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F12%2F17%2Fhow-to-remove-hidden-tab-characters%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F12%2F17%2Fhow-to-remove-hidden-tab-characters%2F" height="61" width="51" /></a></div><p>At this moment, all the language translations of the Floorplanner 2D app are stored in a database table. Today we discovered that a couple of these translations didn&#8217;t align properly in the interface. After some investigation we discovered that they all contained a hidden tab character at the end of  each string. This was probably caused by importing a malformed CSV file.</p>
<p>I thought a simple <strong>REPLACE</strong> query would fix this problem, but (as usual) it was a little more complicated than that. First I had to find the fields with the tab character&#8230; <a href="http://twitter.com/wvanbergen/status/1060635881" target="_blank">Willem</a> pointed me to the right direction with his favorite weapon of choice <strong>REGEXP</strong>. According to the <a href="http://dev.mysql.com/doc/refman/5.1/en/regexp.html" target="_blank">MySQL docs</a> I could find tab characters with something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family: Monaco,monospace;">SELECT <span style="color: #339933;">*</span> FROM table WHERE field REGEXP <span style="color: #0000ff;">'[[.LF.]]'</span></pre></div></div>

<p>The next step was to remove the tab characters. My first thought was to do this by replacing them with an empty string. It turns out you can&#8217;t combine a <strong>REPLACE</strong> with a <strong>REGEXP</strong> in a query. So I used good ol&#8217; PHP for the job. A nice advantage was that I didn&#8217;t have to do any replacing, I could just use the <em>trim()</em> function.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family: Monaco,monospace;"><span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT id, field FROM table WHERE field REGEXP '[[.LF.]]'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$field</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE table SET field = '<span style="color: #006699; font-weight: bold;">$field</span>' WHERE id = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Rather simple, when you know what to do&#8230; Another bug bites the dust!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/12/17/how-to-remove-hidden-tab-characters/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
