Disable foreign key checks in MySQL

November 24, 2008 – 22:47

Disabling foreign key checks in MySQL is usefull when you are dealing with tables that use foreign keys (InnoDB engine).

MySQL logo

MySQL logo

You can not delete (drop) multiple tables, a parent table or a child table until you disable foreign key checks four your current database.

The sql command to disable foreign key checks is:

SET FOREIGN_KEY_CHECKS = 0;

To enable the foreign key checks use the opposite command:

SET FOREIGN_KEY_CHECKS = 1;

Tags: , ,

Shell script to extract the exchange rates from BNR (Romania)

August 13, 2008 – 19:59

Here is a simple script to get the exchange rates from www.bnro.ro/nbrfxrates.xml

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
# clear the screen
clear
# display an info message
echo "+------------------------------+"
echo "|        BNR exchange          |"
echo "+------------------------------+"
# check for parameters
if [ $# -ne 1 ]
  then
    echo "Usage: $0 eur  or  $0 usd"
  else
    # convert parameter to upper case
    CURRENCY=$(echo $1 | tr '[:lower:]' '[:upper:]')
    # execute the extraction
    RON=$(lynx -source http://www.bnro.ro/nbrfxrates.xml | grep $CURRENCY | cut -c25-30)
   echo "1 $CURRNECY = $RON RON"
fi

More details about running a shell script on How to create a simple shell script and Understanding file permissions and ownership on Linux .

Tags: , ,

Internet Explorer bug – duplicate characters

March 2, 2008 – 04:12

One of Internet Explorer versions 6 and 7 bugs, consists in repeating (duplicating) some characters from the end of some elements with the CSS atribute – float.

What’s triggering this bug:

  • Using HTML comments inserted between the elemens with the float attribute.
  • Hidden elements using display: none

Solutions to prevent the duplication of the characters:

Using conditional comments:

<!--[if !IE]> comments here <![endif]-->

Another solution – you can set for the last element with float: left, the right margin at -3px (margin-right: -3px), and -3px for the left margin of the elements with float: right. Also you can set the width of the first div with 3px larger than the width of the last element with float.

Tags: , , , ,

How to activate sounds in Pidgin

January 18, 2008 – 19:06

In case the sound events are not working in Pidgin you can use this solution:

  • From the main menu select Tools -> Preferences (or just press the keyboard shortcut CTRL+p).
  • From Preferences window select the Sounds tab.
  • At the Sound method section, for Method select the Command option.
  • In the Sound command field type:
    aplay %s
Pidgin Preferences window

Pidgin Preferences window

Tags: , ,

Understanding file permissions and ownership on Linux

December 12, 2007 – 14:03

The files on a Linux system can have reading permissions, writing permissions, executing (running) permissions or no permissions for the user that owns that files, groups of users or the rest – users who does not own that files and they are not members of any group.

The usual file types are:

  • Directory – associated symbol d
  • Normal file – associated symbol - (minus, dash)
  • Symbolic link (symlink) (like a shortcut on Windows) – associated symbol l

Permission types:

  • Reading – associated symbol r, or number 4
  • Writing – associated symbol w, or number 2
  • Executing (running) – associated symbol x, or number 1
  • No permission – associated symbol -, or number 0

If a file has the reading permission you can open the file and read it, but you can not change the content. If a directory has the reading permission you can read the files in that directory, but you are not allowed to change their content.

If a file has the writing permission you can open the file for reading and also for writing (you can change the content of the file and save it with the new content). You can not delete or rename a file unless the directory has the writing permission.

The execution permission allows the user to execute (run) the file (like a shell script).

User types:

  • User – the user name of the owner of the file or directory; if an user creates a file or directory it becomes the owner of that file of directory.
  • Group – a group of users (ftp, mysql), all group members have the same rights for the file or directory.
  • Other – all users that do not own the file or direcotry and they do not belong to any group that has right for the file or directory.

Setting permissions:

You can set the permissions using the chmod command. There two methods for changing file permissions:

  • Symbolic mode
  • Numeric mode

Symbolic mode

Setting the permissions is done using the associated symbols – rwx.

Actions are defined using mathematical symbols: the + (plus) symbol is used to add a permission, the - (minus) symbol is used to remove a permission, and the = (equal) symbol is used to remove the old permission and set a new one.

For the owners, associated symbols are u for user, g for group, o for others (the rest) and a for all.

To make a file executable type in a console:

chmod +x myfile

To remove the write permissions of the group:

chmod g-w myfile

Numeric mode

Instead of symbols, the associated number are used for setting permissions. The number for each owner will be the sum of the permissions for that owner.

To set the reading, writing and execution rights for the user you use the number 7 (4+2+1); to set the reading and writing rights for group will you use the number 6 (4+2); the reading permission for the rest (others) will be set using number 4.

The command for setting the permissions in numeric mode:

chmod 764 myfile

Here is the association between numbers and letters:

0  |  ---
1  |  --x
2  |  -w-
3  |  -wx
4  |  r--
5  |  r-x
6  |  rw-
7  |  rwx

Changing the owner:

It is done using the command chown.

To change the owner:

chown myusername myfile

To change the group and the owner:

chown mygroup:myowner myfile

To change only the group you use the command chgrp:

chgrp group myfile

References:
TLDP.org
TUXfiles.org

Tags: , ,