<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>pieroxy.net</title>
    <link>http://pieroxy.net/blog/</link>
    <description />
    <language>en</language>
    <copyright>Pieroxy</copyright>
    <pubDate>Tue, 28 May 2013 19:43:00 GMT</pubDate>
    <dc:creator>Pieroxy</dc:creator>
    <dc:date>2013-05-28T19:43:00Z</dc:date>
    <dc:language>en</dc:language>
    <dc:rights>Pieroxy</dc:rights>
    <image>
      <title>pieroxy.net</title>
      <url>http://pieroxy.net/blog/</url>
    </image>
    <item>
      <title>MySQL charset hell</title>
      <link>http://pieroxy.net/blog/2013/05/28/mysql_charset_hell.html</link>
      <content:encoded>&lt;div class="blogContentDecorated"&gt;&lt;p&gt;There are not a lot of paradises on this corner of the earth, but there's one sure hell: charsets with MySQL. MySQL has the peculiar idea of defaulting everything to &lt;span class="code"&gt;latin1&lt;/span&gt;. Everything.
&lt;p&gt;Everything should be &lt;span class="code"&gt;utf-8&lt;/span&gt; of course, just because &lt;i&gt;it fucking works with every character on earth&lt;/i&gt;.
&lt;p&gt;Now, let's assume you got the following error message somewhere in some obscure logs:
&lt;div class="code"&gt;Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='&lt;/div&gt;
This means one thing: &lt;b&gt;you're in MySQL charset hell&lt;/b&gt;. Welcome in. You're deep in. It's hot.
&lt;h2&gt;The road to heaven&lt;/h2&gt;
First, you will need to edit your &lt;span class="code"&gt;my.cnf&lt;/span&gt; file, to be found on linux in &lt;span class="code"&gt;/etc/mysql/&lt;/span&gt; and add/modify the following properties in the proper section:
&lt;div class="code"&gt;[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
default-character-set = utf8    
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8&lt;/div&gt;
The goal is to see everything as UTF-8 while running the following:
&lt;div class="code"&gt;show variables like 'char%';&lt;/div&gt;
The result you want is this:

&lt;div class="code"&gt;+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+&lt;/div&gt;
Similarly for collation:

&lt;div class="code"&gt;mysql&amp;gt; show variables like 'collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+&lt;/div&gt;

&lt;h2&gt;Now what?&lt;/h2&gt;
Now, you're still in hell, but you just got the promise of not getting deeper. And you still need to get out, that is to change all your tables to store UTF-8. There you have several options, some consisting in dumping everything, recreating a new DB and reloading everything (see the second link below). I chose the path of the &lt;span class="code"&gt;ALTER&lt;/span&gt;. Here is what you can do:
&lt;p&gt;Migrate your dbs:
&lt;div class="code"&gt;ALTER DATABASE &lt;i&gt;YourDbName&lt;/i&gt; DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;&lt;/div&gt;
&lt;p&gt;Locate the faulty tables:
&lt;div class="code"&gt;SELECT table_schema,table_name, column_name, character_set_name FROM information_schema.`COLUMNS` C where character_set_name = 'latin1';&lt;/div&gt;
&lt;p&gt;Migrate column after column:
&lt;div class="code"&gt;ALTER TABLE t MODIFY col1 CHAR(50) CHARACTER SET utf8;&lt;/div&gt;
Of course, the &lt;span class="code"&gt;CHAR(50)&lt;/span&gt; piece (and eventual other options such as &lt;span class="code"&gt;NOT NULL&lt;/span&gt;) depends on the column. Good luck.
&lt;h2&gt;And remember: For every MySQL install you do from that point on, do this &lt;i&gt;first&lt;/i&gt;. Less trouble for after.&lt;/h2&gt;

Thanks:
&lt;ul&gt;&lt;li&gt;&lt;a href="http://stackoverflow.com/questions/3513773/change-mysql-default-character-set-to-utf8-in-my-cnf"&gt;StackOverflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://airbladesoftware.com/notes/fixing-mysql-illegal-mix-of-collations"&gt;airbladesoftware.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.bluebox.net/about/blog/2009/07/mysql_encoding/"&gt;bluebox.net&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;</content:encoded>
      <category domain="http://pieroxy.net/blog/categories/general-rambling/">General rambling</category>
      <pubDate>Tue, 28 May 2013 19:43:00 GMT</pubDate>
      <guid isPermaLink="false">tag:pieroxy.net,2013-05-28:pieroxy.net/1369770180000</guid>
      <dc:date>2013-05-28T19:43:00Z</dc:date>
    </item>
    <item>
      <title>lz-string: We'll try to make it faster</title>
      <link>http://pieroxy.net/blog/2013/05/21/lz_string_well_try_to_make_it_faster.html</link>
      <content:encoded>&lt;div class="blogContentDecorated"&gt;&lt;br&gt;
I've setup a &lt;a href="/blog/pages/lz-string/testing.html"&gt;small page&lt;/a&gt; where I share my findings in trying to optimize the implementation of &lt;span class="code"&gt;&lt;a href="http://pieroxy.net/blog/pages/lz-string/index.html"&gt;lz-string&lt;/a&gt;&lt;/span&gt;. This work will continue in the coming weeks. You can leave a comment in this blog entry for any feedback.
&lt;br&gt;&lt;br&gt;&lt;/div&gt;</content:encoded>
      <category domain="http://pieroxy.net/blog/categories/javascript/">JavaScript</category>
      <category domain="http://pieroxy.net/blog/tags/compression/">compression</category>
      <category domain="http://pieroxy.net/blog/tags/javascript/">javascript</category>
      <category domain="http://pieroxy.net/blog/tags/localstorage/">localstorage</category>
      <category domain="http://pieroxy.net/blog/tags/lzw/">lzw</category>
      <category domain="http://pieroxy.net/blog/tags/web/">web</category>
      <pubDate>Tue, 21 May 2013 08:19:00 GMT</pubDate>
      <guid isPermaLink="false">tag:pieroxy.net,2013-05-21:pieroxy.net/1369124340000</guid>
      <dc:date>2013-05-21T08:19:00Z</dc:date>
    </item>
    <item>
      <title>Just released: lz-string</title>
      <link>http://pieroxy.net/blog/2013/05/09/just_released_lz_string.html</link>
      <content:encoded>&lt;div class="blogContentDecorated"&gt;&lt;span class="code"&gt;lz-string&lt;/span&gt; is a compression program for JavaScript in the browser, based on LZW. It is &lt;i&gt;fast&lt;/i&gt;, meant for localStorage or any other string-based storage in JavaScript, and is particularly efficient on short strings.
&lt;p&gt;All can be read on the home page: 
&lt;a class="longLink" href="http://pieroxy.net/blog/pages/lz-string/index.html"&gt;http://pieroxy.net/blog/pages/lz-string/index.html&lt;/a&gt;
And a demo can be found below for live compression:
&lt;a class="longLink" href="http://pieroxy.net/blog/pages/lz-string/demo.html"&gt;http://pieroxy.net/blog/pages/lz-string/demo.html&lt;/a&gt;&lt;/div&gt;</content:encoded>
      <category domain="http://pieroxy.net/blog/categories/news/">News</category>
      <category domain="http://pieroxy.net/blog/categories/javascript/">JavaScript</category>
      <category domain="http://pieroxy.net/blog/tags/compression/">compression</category>
      <category domain="http://pieroxy.net/blog/tags/gzip/">gzip</category>
      <category domain="http://pieroxy.net/blog/tags/javascript/">javascript</category>
      <category domain="http://pieroxy.net/blog/tags/localstorage/">localstorage</category>
      <category domain="http://pieroxy.net/blog/tags/lzma/">lzma</category>
      <category domain="http://pieroxy.net/blog/tags/lzw/">lzw</category>
      <category domain="http://pieroxy.net/blog/tags/news/">news</category>
      <category domain="http://pieroxy.net/blog/tags/web/">web</category>
      <pubDate>Thu, 09 May 2013 09:27:00 GMT</pubDate>
      <guid isPermaLink="false">tag:pieroxy.net,2013-05-09:pieroxy.net/1368091620000</guid>
      <dc:date>2013-05-09T09:27:00Z</dc:date>
    </item>
    <item>
      <title>Tomcat, Java and https</title>
      <link>http://pieroxy.net/blog/2013/04/16/tomcat_java_and_https.html</link>
      <content:encoded>&lt;div class="blogContentDecorated"&gt;&lt;p&gt;So I recently acquired a free https certificate from StartSSL. All well and good, this was fairly easy. Now, I have 4 files at my disposal:
&lt;div class="code"&gt;ca.pem
pk.mydomain.com
ssl.crt
sub.class1.server.ca.pem&lt;/div&gt;

&lt;p&gt;At that stage I'm fine. I'm about to configure &lt;span class="code"&gt;https&lt;/span&gt; and will go on with my life. As it turned out, things aren't exactly going to turn out that way.

&lt;p&gt;Tomcat needs a &lt;span class="code"&gt;keystore&lt;/span&gt;. None of those files will make the trick of course, but none of the stupid attempts I was about to try made it any more. It's not about just throwing the three certs in a keystore. Oh no, it's a bit more than that.

&lt;p&gt;As usual, &lt;a href="http://stackoverflow.com/questions/10323447/convert-certificate-in-pkcs12-formate-for-tomcat"&gt;Stackoverflow&lt;/a&gt; bootstrapped me in the right direction.

&lt;div class="code"&gt;openssl rsa -in pk.mydomain.com -out out/ssl.key
cat sub.class1.server.ca.pem ca.pem &gt; out/intcacerts.pem
openssl pkcs12 -export -in ssl.crt -inkey out/ssl.key -certfile out/intcacerts.pem -name "mydomain" -out out/keyandcerts.p12&lt;/div&gt;

And that's it. Now, in the &lt;span class="code"&gt;server.xml&lt;/span&gt; you would find the following:
&lt;div class="code"&gt;...
      keystoreFile="/path/to/my/keystore/file/keyandcerts.p12" 
      keystoreType="PKCS12" 
...&lt;/div&gt;
And that's all. If you have several domain names running on your Tomcat instance, you need a certificate that will accommodate them all, because to this day, Tomcat cannot use a different certificate for different hosts.&lt;/div&gt;</content:encoded>
      <category domain="http://pieroxy.net/blog/categories/java/">Java</category>
      <category domain="http://pieroxy.net/blog/tags/https/">https</category>
      <category domain="http://pieroxy.net/blog/tags/java/">java</category>
      <category domain="http://pieroxy.net/blog/tags/ssl/">ssl</category>
      <category domain="http://pieroxy.net/blog/tags/tomcat/">tomcat</category>
      <pubDate>Tue, 16 Apr 2013 19:37:00 GMT</pubDate>
      <guid isPermaLink="false">tag:pieroxy.net,2013-04-16:pieroxy.net/1366141020000</guid>
      <dc:date>2013-04-16T19:37:00Z</dc:date>
    </item>
    <item>
      <title>Ruzzle - neat cheat</title>
      <link>http://pieroxy.net/blog/2013/04/08/ruzzle_neat_cheat.html</link>
      <content:encoded>&lt;div class="blogContentDecorated"&gt;&lt;p&gt;Ruzzle is a game on iPhone and Android involving small puzzles (4x4 grid of letters) and the ability of the player to find words in the grid. Of course, as soon as I saw this, I wrote a small program to cheat at it.

&lt;p&gt;&lt;a href="/blog/pages/ruzzle-cheat.html"&gt;Here is the cheat program&lt;/a&gt;.

&lt;p&gt;Of course I don't recommend to actually cheat at Ruzzle. But it can help you train.&lt;/div&gt;</content:encoded>
      <category domain="http://pieroxy.net/blog/categories/general-rambling/">General rambling</category>
      <category domain="http://pieroxy.net/blog/categories/news/">News</category>
      <category domain="http://pieroxy.net/blog/tags/cheat/">cheat</category>
      <category domain="http://pieroxy.net/blog/tags/news/">news</category>
      <category domain="http://pieroxy.net/blog/tags/ruzzle/">ruzzle</category>
      <category domain="http://pieroxy.net/blog/tags/solver/">solver</category>
      <pubDate>Mon, 08 Apr 2013 21:56:00 GMT</pubDate>
      <guid isPermaLink="false">tag:pieroxy.net,2013-04-08:pieroxy.net/1365458160000</guid>
      <dc:date>2013-04-08T21:56:00Z</dc:date>
    </item>
    <item>
      <title>HTML5 - Also offline</title>
      <link>http://pieroxy.net/blog/2013/04/04/html5_also_offline.html</link>
      <content:encoded>&lt;div class="blogContentDecorated"&gt;Apps aren't the only things you can run whenever you are offline. Websites can too be run offline, but only if they were meant to.This nice little page, while not being exhaustive by any measure, shows you how to make that work:

&lt;a class="longLink" href="http://www.html5rocks.com/en/mobile/workingoffthegrid/"&gt;http://www.html5rocks.com/en/mobile/workingoffthegrid/&lt;/a&gt;
&lt;p&gt;&lt;/div&gt;</content:encoded>
      <category domain="http://pieroxy.net/blog/categories/html/">html</category>
      <category domain="http://pieroxy.net/blog/tags/html/">html</category>
      <category domain="http://pieroxy.net/blog/tags/offline/">offline</category>
      <category domain="http://pieroxy.net/blog/tags/web/">web</category>
      <pubDate>Thu, 04 Apr 2013 11:08:00 GMT</pubDate>
      <guid isPermaLink="false">tag:pieroxy.net,2013-04-04:pieroxy.net/1365073680000</guid>
      <dc:date>2013-04-04T11:08:00Z</dc:date>
    </item>
  </channel>
</rss>

