<?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>Jalada</title>
	<atom:link href="http://jalada.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://jalada.co.uk</link>
	<description>The blog of David Somers and Select Player</description>
	<lastBuildDate>Sun, 19 Feb 2012 11:00:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Stuff I Like (Week ending 19th February 2012)</title>
		<link>http://jalada.co.uk/2012/02/19/stuff-i-like-week-ending-19th-february-2012.html</link>
		<comments>http://jalada.co.uk/2012/02/19/stuff-i-like-week-ending-19th-february-2012.html#comments</comments>
		<pubDate>Sun, 19 Feb 2012 11:00:30 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Stuff I Like]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=541</guid>
		<description><![CDATA[The big surprise news this week was Apple announcing OS X Mountain Lion being launched this summer. Nothing massively ground-breaking but I&#8217;m excited about getting an integrated Notification Centre (bye Growl?). Trying to remember all these common grammar mistakes is &#8230; <a href="http://jalada.co.uk/2012/02/19/stuff-i-like-week-ending-19th-february-2012.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div id="attachment_542" class="wp-caption aligncenter" style="width: 378px"><a href="http://www.flickr.com/photos/digitalart/3281919019/"><img class=" wp-image-542  " title="Mountain Lion by digitalART2" src="http://jalada.co.uk/wp-content/uploads/2012/02/mountain_lion.jpg" alt="Mountain Lion by digitalART2" width="368" height="248" /></a><p class="wp-caption-text">Grace and Beauty by digitalART2</p></div>
<ul>
<li>The big surprise news this week was Apple announcing <a href="http://www.apple.com/macosx/mountain-lion/">OS X Mountain Lion</a> being launched this summer. Nothing massively ground-breaking but I&#8217;m excited about getting an integrated Notification Centre (<a href="http://www.theverge.com/2012/2/18/2807481/growl-creator-responds-os-x-10-8-mountain-lion-notification-center">bye Growl?</a>).</li>
<li>Trying to remember <a href="http://litreactor.com/columns/20-common-grammar-mistakes-that-almost-everyone-gets-wrong">all these common grammar mistakes</a> is difficult, but it&#8217;s worth a read any way. I&#8217;ve probably made one or two of them in this post.</li>
<li><a href="http://www.pwnee.com/">Cloudberry Kingdom</a> looks like a really interesting platformer. It algorithmically generates levels based on difficulty settings, and &#8216;insane&#8217; really does look insane. They&#8217;ve been working on it for a ridiculous amount of time, I hope it gets in to the Live Arcade store.</li>
<li>It&#8217;s a bit buggy, but <a href="http://itunes.apple.com/gb/app/caffeine-zone-2-lite/id483217205?mt=8">Caffeine Zone 2</a> is a free iPhone app for tracking your caffeine intake and telling you how much caffeine is in your system. (via <a href="http://lifehacker.com/5885306/caffeine-zone-2-tracks-your-caffeine-usage-and-tells-you-if-another-cup-will-do-any-good">Lifehacker</a>)</li>
</ul>
<p>Finally, possibly my oldest childhood friend (we were born within 1 month of each other and my parents are his godparents) got married this weekend. Congratulations Matt and Rosie! Here&#8217;s a <a href="http://cinemagr.am">cinemagr.am</a> of them being bombarded by confetti:</p>
<p style="text-align: center;"><a style="color: transparent;" href="http://cinemagr.am/show/77652"><img class="aligncenter" src="http://cinemagr.am/uploads/77652.gif" alt="" width="360" height="480" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2012/02/19/stuff-i-like-week-ending-19th-february-2012.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stuff I Like (Week ending 12th February 2012)</title>
		<link>http://jalada.co.uk/2012/02/12/stuff-i-like-week-ending-12th-february-2012.html</link>
		<comments>http://jalada.co.uk/2012/02/12/stuff-i-like-week-ending-12th-february-2012.html#comments</comments>
		<pubDate>Sun, 12 Feb 2012 11:00:17 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Stuff I Like]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=531</guid>
		<description><![CDATA[Advanced Data Structures, a Computer Science module at MIT, looks like a great course with a great lecturer. All lectures will be available online with video and synchronised lecture notes, so it&#8217;s worth a look! I cannot get enough of &#8230; <a href="http://jalada.co.uk/2012/02/12/stuff-i-like-week-ending-12th-february-2012.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://courses.csail.mit.edu/6.851/spring12/lectures/">Advanced Data Structures</a>, a Computer Science module at MIT, looks like a great course with a great lecturer. All lectures will be available online with video and synchronised lecture notes, so it&#8217;s worth a look!</li>
<li>I cannot get enough of <a href="http://soundcloud.com/bigosmusicsource-com-7/icarus-madeon">Icarus, by Madeon</a>, a brilliant piece of French disco. I look forward to being able to actually buy it (it was only recently debuted on Radio 1)! If you like that sort of thing, it&#8217;s worth a listen.</li>
<li>We started using <a href="http://trello.com">Trello</a> this week at work and I&#8217;m liking it a lot. I don&#8217;t think it&#8217;s very useful for personal organisation but it&#8217;s great for small teams working on lots of projects (like <a href="http://labs.newsint.co.uk">us</a>!).</li>
<li>So that you always know when @petermacrobert has a meeting: <a href="http://doespetehaveameeting.com">DoesPeteHaveAMeeting.com</a>. (coming soon: Google Calendar integration?)</li>
</ul>
<p><strong>And finally</strong>, I got some <a href="http://www.ikea.com/gb/en/catalog/products/00202324/">Ikea DIODER</a> lights shipped this week. I saw lots of cool examples of them being used as backlighting for TVs so thought I&#8217;d try it out. The results are pretty cool, as you can see in the photo below (it&#8217;s not so bright in real life!).</p>
<p style="text-align: center;"><a href="https://twitter.com/#!/jalada/status/168042478107238400/photo/1"><img class="aligncenter" src="https://p.twimg.com/AlUBvlcCIAAsWFg.jpg" alt="" width="420" height="562" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2012/02/12/stuff-i-like-week-ending-12th-february-2012.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stuff I like (Week ending 5th February 2012)</title>
		<link>http://jalada.co.uk/2012/02/05/stuff-i-like-week-ending-5th-february-2012.html</link>
		<comments>http://jalada.co.uk/2012/02/05/stuff-i-like-week-ending-5th-february-2012.html#comments</comments>
		<pubDate>Sun, 05 Feb 2012 11:00:48 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Stuff I Like]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=520</guid>
		<description><![CDATA[Maciej Cegłowski, creator of Pinboard, posted an article this week called The Five Stages of Hosting. In it he compares different hosting options (SaaS, cloud, your own datacentre) to different types of housing. It&#8217;s worth a read because Maciej is a &#8230; <a href="http://jalada.co.uk/2012/02/05/stuff-i-like-week-ending-5th-february-2012.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="wp-caption aligncenter" style="width: 430px"><img class=" " src="https://twitpic.com/show/large/8dczik" alt="" width="420" height="420" /><p class="wp-caption-text">via @4colorrebellion</p></div>
<p>Maciej Cegłowski, creator of <a href="http://pinboard.in">Pinboard</a>, posted an article this week called <a href="http://blog.pinboard.in/2012/01/the_five_stages_of_hosting/">The Five Stages of Hosting</a>. In it he compares different hosting options (SaaS, cloud, your own datacentre) to different types of housing. It&#8217;s worth a read because Maciej is a firm believer in bare metal hardware, something which I can relate to. In particular, on Virtual Private Servers he says:</p>
<blockquote><p>Sometimes you will REALLY notice the neighbors, and can&#8217;t do anything about it.</p></blockquote>
<p><a href="https://twitter.com/#!/atomixmag">Atomix</a>, the videogame magazine for iPad, have just launched <a href="http://itunes.apple.com/gb/app/atomix-mag/id429125775?mt=8">version 2 of their iPad application</a> with support for Newsstand. In addition, they have made their back-catalogue (and new issue) completely free. I&#8217;m not sure about this as a business move, but obviously it&#8217;s good for users! The first few issues are particularly good, as they have some great video and editorial content from <a href="http://area5.tv/">Area5</a> (where are they now?!). They purposefully made sure the content wasn&#8217;t time-specific, so it&#8217;s definitely worth checking out the back issues if you&#8217;ve never read them before.</p>
<p><a href="http://backbonejs.org/#changelog">There&#8217;s a new version of Backbone</a> &#8211; the Javascript MVC framework &#8211; out this week. They&#8217;ve made some interesting changes. If you use Backbone be sure to check out the Change Log.</p>
<p>And finally, <a href="http://www.thetimes.co.uk/tto/public/cyclesafety/">The Times have launched a cycle safety campaign</a> this week after one of their journalists, Mary Bowers, was hit by a lorry just yards from work. <a href="https://twitter.com/#!/jalada/status/132390311094784000">I heard the accident</a>, it was on the road just outside my window (5 floors up), and I witnessed the aftermath. I don&#8217;t think I&#8217;ll ever forget what I heard and saw. Please <a href="http://www.thetimes.co.uk/tto/public/cyclesafety/contact/">pledge your support</a> and <a href="https://twitter.com/#!/petermacrobert/status/165601849699860480">cycle safely</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2012/02/05/stuff-i-like-week-ending-5th-february-2012.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stuff I like (Week ending 29th January)</title>
		<link>http://jalada.co.uk/2012/01/29/stuff-i-like-week-ending-29th-january.html</link>
		<comments>http://jalada.co.uk/2012/01/29/stuff-i-like-week-ending-29th-january.html#comments</comments>
		<pubDate>Sun, 29 Jan 2012 12:03:28 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Stuff I Like]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=514</guid>
		<description><![CDATA[To try and get some more use out of this blog, I&#8217;m thinking of looking over my Pinboard/Instapaper/History each week and picking out a few things that I found really interesting over the course of the week. So here goes: &#8230; <a href="http://jalada.co.uk/2012/01/29/stuff-i-like-week-ending-29th-january.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To try and get some more use out of this blog, I&#8217;m thinking of looking over my Pinboard/Instapaper/History each week and picking out a few things that I found really interesting over the course of the week. So here goes:</p>
<ul>
<li><a href="https://chrome.google.com/webstore/detail/ggnjbdfgigejghknieofeahaknkjafim">Chrome Web Timer</a> has found a place next to my address bar in Chrome. It&#8217;ll be interesting to see how the statistics work out after a few weeks of using it. I&#8217;m probably going to suggest it to <a href="http://twitter.com/petermacrobert">Pete</a> like every other &#8216;focus&#8217; tool I find.</li>
<li>I&#8217;ve been spending a lot of time with the R&amp;D 3D printer this week, and it&#8217;s getting better and better and less temperamental (though isn&#8217;t working right now!).  Therefore I expect <a href="http://v1.tinkercad.com/">Tinkercad</a>, a tool for designing simple 3D models in your browser, will be useful in the future.</li>
<li>Twitter Bootstrap has become my default CSS toolkit, with the only disadvantage being everyone else uses it too! So I&#8217;m excited and intrigued by the news that <a href="http://www.markdotto.com/2012/01/24/bootstrap-2-ready-for-testing-and-feedback/">Bootstrap 2 is ready for testing</a>. Looks like they&#8217;ve added some really interesting stuff.</li>
</ul>
<p>And finally, I bought myself a new coffee toy this weekend, a Zassenhaus coffee mill. It&#8217;s excellent and goes really well with <a title="An AeroPress review from a coffee noob" href="http://jalada.co.uk/2011/08/25/an-aeropress-review-from-a-coffee-noob.html">my Aeropress</a>.</p>
<p style="text-align: center;"><img class="aligncenter" title="Zassenhaus coffee mill" src="https://p.twimg.com/AkUkaKpCIAAWSdQ.jpg" alt="" width="480" height="642" /></p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2012/01/29/stuff-i-like-week-ending-29th-january.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding files to config.assets.precompile in Rails 3.1+</title>
		<link>http://jalada.co.uk/2012/01/23/adding-files-to-config-assets-precompile-in-rails-3-1.html</link>
		<comments>http://jalada.co.uk/2012/01/23/adding-files-to-config-assets-precompile-in-rails-3-1.html#comments</comments>
		<pubDate>Mon, 23 Jan 2012 12:29:53 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=510</guid>
		<description><![CDATA[I came across a problem that stumped me for quite a while today, so thought it best I write it down. In Rails 3.1+ with the asset pipeline enabled any files that are not referenced by a manifest file (e.g. &#8230; <a href="http://jalada.co.uk/2012/01/23/adding-files-to-config-assets-precompile-in-rails-3-1.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I came across a problem that stumped me for quite a while today, so thought it best I write it down.</p>
<p>In Rails 3.1+ with the asset pipeline enabled any files that are not referenced by a manifest file (e.g. a require line) will not be precompiled in production. They may work fine in development / compiling on the fly but they won&#8217;t be touched by the assets:precompile rake task.</p>
<p>The solution is to add them to config.assets.precompile in your application.rb file. However there is a little gotcha. I had a file I wanted precompiled called admin.sass, so I wrote the following line:</p>
<pre class="brush: plain; title: ; notranslate">
config.assets.precompile += %w(admin.sass)
</pre>
<p>However this didn&#8217;t work. Eventually I found out it&#8217;s because the asset pipeline expects you to specify the <em>resulting</em> filename after compilation, rather than the un-compiled SASS/CSS filename. So I changed the line:</p>
<pre class="brush: plain; title: ; notranslate">
config.assets.precompile += %w(admin.css)
</pre>
<p>Everything worked fine then.</p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2012/01/23/adding-files-to-config-assets-precompile-in-rails-3-1.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Always have exact (UK) change</title>
		<link>http://jalada.co.uk/2012/01/02/always-have-the-right-amount-of-uk-change.html</link>
		<comments>http://jalada.co.uk/2012/01/02/always-have-the-right-amount-of-uk-change.html#comments</comments>
		<pubDate>Mon, 02 Jan 2012 12:24:30 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=501</guid>
		<description><![CDATA[I never thought about this, but there is a way of going out of the house with a small number of coins, and always (at least, the first time) having the right amount of change between 1p and 99p with &#8230; <a href="http://jalada.co.uk/2012/01/02/always-have-the-right-amount-of-uk-change.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I never thought about this, but there is a way of going out of the house with a small number of coins, and <em>always (at least, the first time) having the right amount of change between 1p and 99p with just 8 coins.</em></p>
<p>In fact, if you add a few extra coins, you can have the right change from 1p all the way up to £6.10.</p>
<p>The magic combination is:</p>
<ul>
<li>One penny</li>
<li>2 two pence</li>
<li>1 five pence</li>
<li>1 ten pence</li>
<li>2 twenty pence</li>
<li>1 fifty pence</li>
</ul>
<p>Then optionally you can add:</p>
<ul>
<li>1 pound coin</li>
<li>2 two pound coins</li>
</ul>
<p>To work this out, use a greedy strategy; keep picking the biggest coin less than or equal to the remaining amount. You can keep doing that up through notes as well if you want.</p>
<p>Obviously this only works the first time you need exact change, but it seems like a great way of getting rid of your change. I find I can take a handful of change with me and still have to go &#8220;sorry, I don&#8217;t have the right amount&#8221; and end up with even more change.</p>
<p>Note I didn&#8217;t work this out myself. I saw the idea on <a href="http://lifehacker.com/208742/always-have-exact-change">Lifehacker</a> and <a href="http://mathlesstraveled.com/2010/06/24/optimal-change-carrying/">others have discussed the problem</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2012/01/02/always-have-the-right-amount-of-uk-change.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop whinging about the new iPhone Twitter client</title>
		<link>http://jalada.co.uk/2011/12/09/stop-whinging-about-the-new-iphone-twitter-client.html</link>
		<comments>http://jalada.co.uk/2011/12/09/stop-whinging-about-the-new-iphone-twitter-client.html#comments</comments>
		<pubDate>Fri, 09 Dec 2011 22:06:38 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=492</guid>
		<description><![CDATA[Twitter have launched what could be considered the first version of their website that properly demonstrates the monetization direction they are trying to take, and in conjunction they have unified their website, iOS (only iPhone for now) and Android clients. &#8230; <a href="http://jalada.co.uk/2011/12/09/stop-whinging-about-the-new-iphone-twitter-client.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://fly.twitter.com/">Twitter have launched</a> what could be considered the first version of their website that properly demonstrates the monetization direction they are trying to take, and in conjunction they have unified their website, iOS (only iPhone for now) and Android clients.</p>
<p>Twitter power users seem to be unimpressed. They are unhappy with the loss of 1 tap access to Direct Messages (even though it&#8217;s just a swipe away) and feel the direction Twitter are taking is turning Twitter into less of a platform and more of a product, and a way to push advertising and branded information to them. <em>Kinda like the rest of the web</em>.</p>
<p>We all knew Twitter couldn&#8217;t be so nice to everyone forever and the signs were there when they started hanging on to private API calls and not giving access to key features to developers. Everyone has always asked the question &#8220;How will Twitter monetize?&#8221; and now the answer is starting to be evident.</p>
<p>My point is: When Facebook change their layout and millions set up groups to campaign for reversion, social media &#8216;experts&#8217; look down their noses <a href="http://theoatmeal.com/pl/state_web_winter/facebook_layout">and laugh</a>. But for some reason when Twitter redesigns <a href="http://daringfireball.net/2011/12/new_twitter">it deserves a serious critique</a>. In my opinion it doesn&#8217;t, stop whinging.</p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2011/12/09/stop-whinging-about-the-new-iphone-twitter-client.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving Latin1 and UTF8 errors for good in Ruby</title>
		<link>http://jalada.co.uk/2011/12/07/solving-latin1-and-utf8-errors-for-good-in-ruby.html</link>
		<comments>http://jalada.co.uk/2011/12/07/solving-latin1-and-utf8-errors-for-good-in-ruby.html#comments</comments>
		<pubDate>Wed, 07 Dec 2011 19:46:28 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=475</guid>
		<description><![CDATA[Update: I haven&#8217;t tested it fully, but @eevee has a shorter suggestion that seems to work: Tell the mysql driver that you&#8217;re getting BINARY back, then use .force_encoding(&#8220;UTF-8&#8243;)? In a Rails application you can do this by setting encoding: binary &#8230; <a href="http://jalada.co.uk/2011/12/07/solving-latin1-and-utf8-errors-for-good-in-ruby.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: I haven&#8217;t tested it fully, but @eevee has a shorter suggestion that seems to work:</p>
<blockquote><p>Tell the mysql driver that you&#8217;re getting BINARY back, then use .force_encoding(&#8220;UTF-8&#8243;)?</p></blockquote>
<p>In a Rails application you can do this by setting encoding: binary in your database.yml file (I&#8217;m also using the mysql2 driver, not sure if that makes a difference). It seems to work (tested in Ruby 1.9.2) and it makes more sense, but I&#8217;ll update if I come across any issues!</p>
<p>Original post follows.</p>
<p>Recently I had to deal with a MySQL database where the character encoding was set to latin1 (the default) but the bytes sent to it were UTF-8. When this happens you get horribly messy strings coming out of your database if you try and access it with anything sane. For example &#8220;ümlaut&#8221; becomes &#8220;Ã¼mlaut&#8221;. What a mess!</p>
<p>In any normal situation you would fix the data storage itself, but I had no control over the database so I had to work out another way of fixing it on my side. <strong>And I managed to do it!</strong></p>
<h2>Some background</h2>
<p><strong>Latin1</strong> is a character encoding used by MySQL. People mistakenly think it is equivalent to <a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1">ISO-8259-1</a> but it isn&#8217;t, it&#8217;s actually <a href="http://en.wikipedia.org/wiki/Windows-1252">CP-1252</a> (also known as Windows-1252). CP-1252 is a superset of ISO-8259-1 with some additional characters (recently including the € symbol).<strong></strong></p>
<p>We can simulate what happens in MySQL when you forcibly send it UTF-8 with the following Ruby snippet:</p>
<pre class="brush: plain; title: ; notranslate">
&quot;ümlaut&quot;.force_encoding(&quot;cp1252&quot;).encode(&quot;UTF-8&quot;)
# =&gt; &quot;Ã¼mlaut&quot;
</pre>
<p>Here, we start with UTF-8, then we tell Ruby that it&#8217;s actually CP-1252. It isn&#8217;t, so that just results in garbage. We then ask Ruby to give us that encoded back in to UTF-8.</p>
<p>When I realised this (thanks to Yehuda Katz for some pointers in <a href="http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/">his blog post about Ruby 1.9 Encodings</a>) I tried running the reverse process against the text I was trying to fix:</p>
<pre class="brush: plain; title: ; notranslate">
&quot;Ã¼mlaut&quot;.encode(&quot;cp1252&quot;).force_encoding(&quot;UTF-8&quot;)
# =&gt; &quot;ümlaut&quot;
</pre>
<p>Success! However when I put that code into my application and ran it across a much larger set of data, I encountered a new problem:</p>
<pre class="brush: plain; title: ; notranslate">
&quot;(â€œWhat do you think?â€\u009D)&quot;.encode(&quot;cp1252&quot;)
                                 .force_encoding(&quot;UTF-8&quot;)
# =&gt; Encoding::UndefinedConversionError: U+009D to WINDOWS-1252
     in conversion from UTF-8 to WINDOWS-1252
</pre>
<p><em>Clearly strings coming out of MySQL aren&#8217;t strictly CP-1252.</em></p>
<p><a href="http://en.wikipedia.org/wiki/Windows-1252#Codepage_layout">It turns out</a> that Windows API methods (and thus, perhaps, others) will accept certain decimal code values for characters that aren&#8217;t strictly accepted in the CP-1252 standard. Just 5 of them: 81, 8D, 8F, 90, and 9D. Looking at the error above, <strong>9D</strong> is referred to so that must be what is going on!</p>
<p>I&#8217;m not 100% sure, but what I suspect is happening is MySQL is happily storing the 9D byte it receives, which when read by Ruby as UTF-8 comes out as the Unicode byte character \u009D. But Ruby is strict about encoding CP-1252 and won&#8217;t encode that byte because it considers it invalid. However if you drop those invalid bytes the resulting text won&#8217;t come out properly, because that byte is actually part of a multibyte Unicode character, so needs to be passed across to the encoded string.</p>
<p>To do this, you can use the badly documented :fallback option in the encode method. :fallback takes a hash where the key is the invalid character and the value is the character to replace it with. We want to replace all instances of \u009D etc. with \x9D (an escaped single byte character). One final caveat is that for Ruby to accept that as a replacement character, you must use <code>force_encoding("cp1252")</code> (essentially overriding Ruby&#8217;s lack of conversion). The resulting code looks like this:</p>
<pre class="brush: plain; title: ; notranslate">
def fix_cp1252_utf8(text)
  text.encode('cp1252',
              :fallback =&gt; {
                &quot;\u0081&quot; =&gt; &quot;\x81&quot;.force_encoding(&quot;cp1252&quot;),
                &quot;\u008D&quot; =&gt; &quot;\x8D&quot;.force_encoding(&quot;cp1252&quot;),
                &quot;\u008F&quot; =&gt; &quot;\x8F&quot;.force_encoding(&quot;cp1252&quot;),
                &quot;\u0090&quot; =&gt; &quot;\x90&quot;.force_encoding(&quot;cp1252&quot;),
                &quot;\u009D&quot; =&gt; &quot;\x9D&quot;.force_encoding(&quot;cp1252&quot;)
              })
      .force_encoding(&quot;utf-8&quot;)
end
</pre>
<p>A bit messy, but it gets the job done. <em>I believe Ruby 1.9.2 will not accept a dynamic hash in the :fallback option for some weird reason, but Ruby 1.9.3 will</em>. Just bear that in mind.</p>
<p>In action:</p>
<pre class="brush: plain; title: ; notranslate">
fix_cp1252_utf8(&quot;(â€œWhat do you think?â€\u009D)&quot;)
# =&gt; &quot;(“What do you think?”)&quot;
</pre>
<p>Hurrah!</p>
<p><strong>One really important caveat</strong>: If you pass that method nice tidy UTF-8 it will screw up the text. I haven&#8217;t figured out a way of stopping that; so be careful!</p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2011/12/07/solving-latin1-and-utf8-errors-for-good-in-ruby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Compass with Rails 3.1 final and no hacks</title>
		<link>http://jalada.co.uk/2011/10/16/using-compass-with-rails-3-1-final-and-no-hacks.html</link>
		<comments>http://jalada.co.uk/2011/10/16/using-compass-with-rails-3-1-final-and-no-hacks.html#comments</comments>
		<pubDate>Sun, 16 Oct 2011 14:38:43 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=472</guid>
		<description><![CDATA[The web is full of complicated instructions about getting the Compass CSS framework to work with Rails 3.1 &#38; the asset pipeline when actually you don&#8217;t need to do anything any more. All you need to do, is add Compass &#8230; <a href="http://jalada.co.uk/2011/10/16/using-compass-with-rails-3-1-final-and-no-hacks.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The web is full of complicated instructions about getting the <a href="http://compass-style.org/">Compass CSS framework</a> to work with Rails 3.1 &amp; the asset pipeline when actually you don&#8217;t need to do anything any more.</p>
<p>All you need to do, is add Compass to your Gemfile and you should be all set. You can even group it under assets (so long as you precompile assets before deploying).</p>
<p>But you might find it still doesn&#8217;t work, that&#8217;s because the stable version of Compass (0.11) <em>doesn&#8217;t work with Rails 3.1</em>. So you need to explicitly request version 0.12:</p>
<pre>group :assets do
  gem 'sass-rails', "  ~&gt; 3.1.0"
  gem 'coffee-rails', "~&gt; 3.1.0"
  gem 'uglifier'
  gem 'compass', '~&gt; 0.12.alpha'
end</pre>
<p>Now you can carry on using the great Rails 3.1 asset pipeline with all the Compass and Blueprint mix-ins you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2011/10/16/using-compass-with-rails-3-1-final-and-no-hacks.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Prospects.ac.uk send you your password in plaintext even if you don&#8217;t want it</title>
		<link>http://jalada.co.uk/2011/09/30/prospects-ac-uk-send-you-your-password-in-plaintext-even-if-you-dont-want-it.html</link>
		<comments>http://jalada.co.uk/2011/09/30/prospects-ac-uk-send-you-your-password-in-plaintext-even-if-you-dont-want-it.html#comments</comments>
		<pubDate>Fri, 30 Sep 2011 14:42:57 +0000</pubDate>
		<dc:creator>jalada</dc:creator>
				<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://jalada.co.uk/?p=460</guid>
		<description><![CDATA[Update: I have received a few emails back from Prospects. The first was an automated message providing me with a username and password to log in to their service desk, the irony of which wasn&#8217;t lost on me. I&#8217;ve then received &#8230; <a href="http://jalada.co.uk/2011/09/30/prospects-ac-uk-send-you-your-password-in-plaintext-even-if-you-dont-want-it.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> I have received a few emails back from Prospects. The first was an automated message providing me with <em>a username and password</em> to log in to their service desk, the irony of which wasn&#8217;t lost on me.</p>
<p>I&#8217;ve then received confirmation that my account will be closed within 48 hours, and then I had a further email from David Sherwin, who is the Web Traffic and Communication Manager at Prospects:</p>
<blockquote><p>Hi David</p>
<p>Thanks for your email.</p>
<p>We are investigating the issues you have raised.</p>
<p>We have taken steps to deal with your immediate concerns.</p>
<p>Regards</p>
<p>David Sherwin</p></blockquote>
<p>The email was CC&#8217;d to 6 other people within Prospects, which suggests they are taking my issues seriously, which I am pleased about.</p>
<p>Original post follows:</p>
<p style="text-align: left;"><a href="http://jalada.co.uk/wp-content/uploads/2011/09/prospects1.png"><img class="aligncenter size-full wp-image-461" title="Prospects email" src="http://jalada.co.uk/wp-content/uploads/2011/09/prospects1.png" alt="" width="406" height="695" /></a>Today <a href="http://ww2.prospects.ac.uk/cms/ShowPage/Home_page/My_Prospects___Vacancies_by_e_mail_or_mobile/My_Prospects_R2_Signup/p!eklfebL?mode=showMpHome">Prospects</a> - &#8217;the UKs official graduate careers website&#8217; &#8211; decided to remind me by email that I still have an account with them. Just in case I had forgotten, they included my password in plaintext, which means either they are storing it in plaintext or they are encrypting it in a reversible manner (just as bad, I guess).</p>
<p style="text-align: left;">I have contacted them about this, and also emailed them asking them to delete my account as there doesn&#8217;t seem to be a way of doing it online.</p>
<p style="text-align: left;">The horrors don&#8217;t stop there though. If you visit their &#8216;Change my password&#8217; page not only is communication not over SSL but for some ridiculous reason <em>they embed your password as a value in the &#8216;Your existing password&#8217; field even though it&#8217;s hidden</em>. Someone actually made a conscious decision to do this. I would love to know why.</p>
<p style="text-align: center;"><a href="http://jalada.co.uk/wp-content/uploads/2011/09/prospects2.jpg"><img class="aligncenter size-full wp-image-462" title="prospects2" src="http://jalada.co.uk/wp-content/uploads/2011/09/prospects2.jpg" alt="" width="647" height="664" /></a></p>
<p style="text-align: left;">I don&#8217;t think I&#8217;ve ever seen something quite so stupid on the Internet.</p>
]]></content:encoded>
			<wfw:commentRss>http://jalada.co.uk/2011/09/30/prospects-ac-uk-send-you-your-password-in-plaintext-even-if-you-dont-want-it.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

