convert

Convert a MySQL database to UTF8

This is a “script” to convert your latin1 myisam database to utf8 innodb
Dump the database

mysqldump -u root -p database_to_convert > db.latin1.sql

Make a copy of the dump

cp db.latin1.sql db.utf8.sql

Change any default table charset to be utf8

sed -i 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/g' db.utf8.sql

Now, remove all field collations for Latin1

sed -i 's/COLLATE=latin1_general_ci//g' db.utf8.sql

Change any MyISAM engines to InnoDB

sed -i 's/ENGINE=MyISAM/ENGINE=InnoDB/g' db.utf8.sql

Re-import the database

mysql -u root -p database_to_convert < db.utf8.sql

And thats it.

Convert Excel headers to numbers

Quite often I have to convert datasets from one source to another target. Sometimes I can only export them as CSV to investigate the field order/column structure

Then, once I work out the columns I can import them. But, the headings are often not in the source, so I only have Excel/OpenOffice column headers which go from A to Z and then AA to AZ, and BA to BZ, etc etc

I needed a quick way to convert these to numbers, so I could state “the 141st column is /this/ field”

So here it is:

$(document).ready(function() {
    $("#testes").on("keyup", function(event) {
        var str = $(this).val();
        if (str.length == 1) {
            $("#results").val(get_string_value(str));
        } else {
            var fstr = str.slice(0,1);
            var estr = str.slice(1,2);
            $("#results").val(get_string_value(estr) + (get_string_value(fstr) * 26));
        }
    });
});

function get_string_value(str) {
    return str.charCodeAt() - 96;
}

Or if you like, a fiddle: http://jsfiddle.net/8eAV6/