Wednesday, December 18, 2013

MySQL: Column alias on negative value selection

Whenever you select a negative value from MySQL table, "-" will become a part of the field name returned in a result set. 

For example, we have following statement:

select id from MY_TABLE;
It will return a result with field name "id".

select -id from MY_TABLE;
will return a result with field name "-id".

select from MY_TABLE custom;
will also include table alias name and return a result with field name "".
In such case you should use "as %FIELD_NAME%" to be sure that you will have same field name:
select as id from MY_TABLE custom;

Monday, July 15, 2013

Delete a file with special characters in Linux

Sometimes you can put command line parameters in wrong order, and have a file name starting with "--" as a result. If you'll try to use rm <file name> it will fail because it will assume that you are providing a flag to rm command.
In this case, use following command:
rm -- <file name>

Wednesday, June 5, 2013

Change ownership of symbolic link

To change ownership of a symbolic link, use flag -h:

NFS mount problem - permission denied

One of common problem with NFS mounts is "permission denied" error while trying to modify existing files and folders, even if your user and group names are matching content creator's user and group. 
If you're sure that you gave "rw" permission on this NFS share to the client's host, check each user ID and group ID. File access permissions are being verified based on UID and GID, not on names. 

Run these commands on both machines, and check that UID and GID are matching:
/usr/sbin/vipw -s
/usr/sbin/vigr -s

If UID or GID is different, change it on one of servers using following commands:

/usr/sbin/usermod -u {NEW_USER_ID} {USER_NAME}
/usr/sbin/groupmod -g {NEW_GROUP_ID} {GROUP_NAME}
/usr/sbin/usermod -g {NEW_GROUP_ID} {USER_NAME}

For example, you need to update UID of user "test" to 345, GID of group "testgrp" to 999:

/usr/sbin/usermod -u 345 test
/usr/sbin/groupmod -g 999 testgrp
/usr/sbin/usermod -g 999 test

First command will update UID, second will update GID, third will update GID in user record.

NOTE: all these commands should be executed as root
NOTE 2: if you have any folders owned by this user (except home folder), you'll need to change ownership to same user and group again, because it also uses UID and GID.

Tuesday, June 4, 2013

JavaScript - download a file

If you need to download a file from JavaScript, add this code:
.prop("src", $myFileURL)

Monday, May 13, 2013

javax.mail.MessagingException: Unable to load BODYSTRUCTURE

This Exception usually comes up when you are using IMAP protocol, and calling part.getDisposition() method. It's a known bug of several IMAP servers. I had this error in GMail when I tried to parse a message with attached .eml file.
If you are facing this issue, create a new MimeMessage based on the one that you're trying to parse. This will force Javamail to download and parse the Mime message locally, and in most cases, it will fix your problem.
Keep the original message, because you still need it to set flags on server (to delete it, for example).

You can do something like this:

public void processMimeMessage(MimeMessage msg) throws MessagingException
    try {
        //some processing
    catch (MessagingException messEx)
        //making sure that it's a BODYSTRUCTURE error
        if (messEx.getMessage() != null && messEx.getMessage().toLowerCase().
        contains("unable to load " +"bodystructure"))
            //creating local copy of given MimeMessage
            MimeMessage msgDownloaded = new MimeMessage((MimeMessage) msg);
            //calling same method with local copy of given MimeMessage
            throw messEx;

from here:

Thursday, April 18, 2013

mysqldump --ignore-database

To implement --ignore-database option (f.e. to exclude MySQL internal databases), use following:
mysqldump -u{USER_NAME} -p{PASSWORD} --databases `mysql -u{USER_NAME} -p{PASSWORD} --skip-column-names -e "SELECT GROUP_CONCAT(schema_name SEPARATOR ' ') FROM information_schema.schemata WHERE schema_name NOT IN ('mysql''performance_schema''information_schema');"` > dump.sql

Monday, January 7, 2013

How to turn off DEBUG logging in C3PO

To turn DEBUG logging OFF in C3PO Connection Pool, just add following lines to your file: