Restore the missing DataTables search reset button in Bootstrap

If you are using DataTables with Bootstrap, you may be missing the reset button in the search control in your table. The Bootstrap styling is to blame for it.

You can bring the reset button back by  adding this to your CSS:

input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: searchfield-cancel-button;
}

Client IP in SSH session

If you are writing a bash script and you want to know the remote public IP address of the client logged into the session via SSH, a simple way to do this is:

  • my_ip=`echo $SSH_CLIENT | awk '{ print $1}'`; echo $my_ip

Connecting to MySQL without a password

There may be situations when you need to log into MySQL without providing a password. Well, not exactly without providing it at all, but without doing it in an interactive way or writing it in the command line in plain text. A real life example is doing database dump for backup purposes.

Luckily MySQL provides a mechanism to do just that. What you do is you create a file accessible only to you and MySQL and save your password within.

The procedure is very simple:

  • Go to your home directory
  • Create a hidden file named .my.cnf
  • Open it in a text editor
  • Create a section called “[client]” and provide your MySQL password, like this:
[client]
password=mypassword
  • Update access rights for better security:
chmod 600 .my.cnf

Find and replace text in all files in subdirectories

To search for and replace a text in all files in all subdirectories of the current directory:

  • find ./ -type f -exec sed -i -e 's/old-text/new-text/g' {} \;

Run a process in VirtualBox from outside

You can launch a program within an Oracle VirtualBox virtual machine from the host system’s command prompt.

Example 1:  Run notepad in MS Windows 7 virtual machine named “7” as user “user” with password “1” from Ubuntu:

  • VBoxManage guestcontrol "7" run --exe "C:\\Windows\\notepad.exe" --username user --password 1

Example 2: Output guest network info:

  • VBoxManage --nologo guestcontrol "7" run --exe "c:\\windows\\system32\\ipconfig.exe" --username user --password 1 --wait-stdout

Notes:

  • You must have Guest Additions installed
  • The user account must have a password

Input line is too long

So you create a .bat file with a long list of arguments and it fails with a message:

“the input line is too long”

To avoid this, split your long single line into multitude of shorter lines separated by the caret character to mark the line break. Like this:

echo 1^
 2^
 3

 


Missing php-mbstring

After (re-)installing PHP and attempting to run a script, you may see an error message saying “PHP Fatal error: Uncaught Error: Call to undefined function mb_strtoupper()”.

Well, you may be missing the php-mbstring extension to PHP. Simply install it by:

  • sudo apt-get install php-mbstring

Set auto-increment field value in MySQL

You have a table. The table has a primary key auto-increment numeric ID field. You want to fast-forward the ID to a certain value (which is larger than or equal to the last value the field has).

Example, let the ID of the next entered record be 1000:

  • ALTER TABLE `mytable` AUTO_INCREMENT = 1000;

Generate QR code

  • This simple command will give you an SVG file with QR code vector image in it:
echo "Hello world!" | qrencode --level=H --dpi=300 --type=SVG -o qr.svg
  • If a bitmap is enough, just type:
echo "Hello world!" | qrencode --level=H --dpi=300  -o qr.png

  • Even this simple command will work:
qrencode -o qr.png "Hi!"

  • Change the color from standard black to any if you like:
echo "Hello world!" | qrencode --foreground=808080ff --level=H --dpi=300 --type=SVG -o qr.svg
  • Alpha supported too:
echo "Hello world!" | qrencode --foreground=FFFF00FF --background=0000FF55 --level=H --dpi=300 -o qr.png
echo "Hello world!" | qrencode --foreground=FFFF00FF --background=0000FF55 --level=H --dpi=300 --type=SVG -o qr.svg

		

UTF-8 from MySQL does not show correctly in PHP

The data you have in MySQL is all in UTF-8, you have UTF-8 specified in your HTML, PHP is set up to use UTF-8, but you still get gibberish as output, with question marks showing up on screen instead of correct symbols.

The problem may be that the communication between MySQL and PHP is not happening in UTF-8.

Try telling “SET NAMES ‘utf8′” to MySQL when you initiate the connection, before you run any other queries.

For example, as soon as you establish the connection to database, run this in your script:

mysqli_query( $conection, “SET NAMES ‘utf8′” );