Pages

Wednesday, August 1, 2012

How to fix dual monitor mode rotation problem in Ubuntu 12.x

It often happens when you are trying to connect additional monitor to your laptop via VGA port and all you see is only clockwise or anticlockwise rotation options in your Displays settings while all you need is to rotate the picture 90 degrees only.
In such case you need to manually configure your display setting from a terminal. All you need to solve this problem is to open the terminal window and type in the command:
xrandr --output VGA1 --mode 1440x900 --rotate normal
From example above you should use proper VGA port as an --output parameter. Use xrandr command in terminal to get the list of your video output ports and modes. You may also avoid specifying resolution manually by using --auto instead of --mode 1440x900.
For --rotate parameter you may use left or right value depending on your preferences.
Use man xrandr for more information ;)

Saturday, March 31, 2012

How to find all UTF-8 files with BOM

It is often annoying when you see strange spaces on your web page even when HTML code looks perfect and you are spending hours to figure out the reason by modifying HTML/CSS files without any success. The reason may be in your application providing HTML output having some UTF files containing byte order mark (BOM) which is invisible at editor therefore very difficult to be eliminated.
Here is a simple way how to find the list of such files:
find -type f|while read file;do [ "`head -c3 -- "$file"`" == $'\xef\xbb\xbf' ] && echo "found BOM in: $file";done
You may write a shell script if you wish:
find -type f |
while read file do
    if [ "`head -c 3 -- "$file"`" == \xef\xbb\xbf' ] then
    echo "found BOM in: $file"
fi
done
If you are windows developer consider Cygwin :)

Tuesday, January 5, 2010

MySQL: migrating to UTF-8

Queries to generate the proper SQL statements for changing each table's field from 'CHAR' to 'BINARY' and then back to 'CHAR' (UTF8) field type:

USE information_schema;
SELECT CONCAT('ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ',
    REPLACE(column_type, 'char', 'binary'), ';') 
FROM columns 
WHERE table_schema = [DBNAME] 
    AND data_type LIKE '%char%';

SELECT CONCAT(
    'ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ', 
    REPLACE(column_type, 'text', 'blob'), ';') 
FROM columns 
WHERE table_schema = [DBNAME]
    AND data_type LIKE '%text%';

SELECT CONCAT('ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ', 
    REPLACE(column_type, 'binary', 'char'), ' CHARACTER SET utf8;') 
FROM columns 
WHERE table_schema = [DBNAME] 
    AND data_type LIKE '%binary%';

SELECT CONCAT('ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ', 
    REPLACE(column_type, 'blob', 'text'), ' CHARACTER SET utf8;') 
FROM columns 
WHERE table_schema = [DBNAME] 
    AND data_type LIKE '%blob%';