Finding/Replacing control characters in Excel.

While doing some database work, I found myself needing to replace extraneous tab characters in a couple columns in Excel. Here is how I was able to do it. This method could just as easily be applied to any other control character once you know the ASCII code.

Go into Find/Replace.

In the “Find what” field, just hold down the Alt key and enter 0009.

Release the Alt, and Find/Replace as you usually would.

This will find all the tab characters since 9 is the ASCII code for tab. You can do this for any other ASCII character as well, but I doubt that would come up very often.

MySQL ERROR 2006 – server has gone away while restoring.

I was getting the following errors when I was trying to restore a Request Tracker MySQL database in linux (Ubuntu to CentOS).

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 10
Current database: rt4

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 11
Current database: rt4

ERROR 2006 (HY000): MySQL server has gone away
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 12
Current database: rt4

These errors came later in the restore:

ERROR 1231 (42000): Variable ‘time_zone’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘sql_mode’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘foreign_key_checks’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘unique_checks’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘character_set_client’ can’t be set to the value of ‘NULL’
Query OK, 0 rows affected (0.00 sec)

ERROR 1231 (42000): Variable ‘collation_connection’ can’t be set to the value of ‘NULL’
ERROR 1231 (42000): Variable ‘sql_notes’ can’t be set to the value of ‘NULL’

To get the database restored, I had to change the maximum allowed packet setting.

The best way to do that is to add the following line to the [mysqld] section of the my.cnf (CentOS: /etc/my.cnf or Ubuntu: /etc/mysql/my.cnf):

max_allowed_packet = 16M

Then, restart your MySQL service.
Ubuntu: service mysql restart
CentOS: service mysqld restart

Now, I did this on both of my servers, then I could use my regular backup script and the setting would be picked up by the my.cnf. However, you can do the backup with option enabled if it is not in your my.cnf by using something like the following:

mysqldump $thedb –user=”myid” –password=”$SQLPWD” –max_allowed_packet=16M > $thedb.sql

Ubuntu, apache and using hostnames instead of directories for sites.

OS: Ubunutu 12.x
Web server: apache 2.x

So here is what I was trying to accomplish. I have a server with many sites in their own directories. I had one that I wanted to just use a hostname to access it. Now, I have done this many times in CentOS/Redhat, but never in Ubuntu, and it adds a little twist to the process. First the name needed to be added to the DNS. I created a CNAME, since I already had a name in for the server.

Then:

vi /etc/apache2/apache2.conf

NameVirtualHost *:80
<IfModule mod_ssl.c>
 NameVirtualHost *:443
</IfModule>

cd /etc/apache2/sites-available
</blockquote>

Created a file with a descriptive name of my site:

vi some.hostname.com

Added the following as appropriate for my site:

<VirtualHost *:80>
 ServerName some.hostname.com
 ServerAlias some
 DocumentRoot /var/www/some
</VirtualHost>

There are many other options you can add here, but this is where I started.

cd /etc/apache2/site-enabled
ln -s ../sites-avaiable/some.hostname.com
service apache2 restart

Extract Windows 8 Product Key from BIOS

I used the following procedure to extract the Windows 8 key from a Lenovo desktop.

Download RW from: http://rweverything.com/. I used the 64-bit portable version.

Copy the Win64 directory from the zip to your local drive.

Execute the RW.EXE program in the Win64\Portable directory.

Once open, click the ACPI icon or select ACPI Tables from the menu.

Then, click on the MSDM tab in the ACPI Table window.

You will find the key in the bottom of the ACPI Table window.

How to create a Mavericks bootable USB drive.

I really don’t understand why Apple makes somethings so difficult for users. Since, Apple no longer distributes their OS upgrade installation media and they have no made an ISO/DMG easily available, we have had to figure out different ways to create a bootable media. For Lion and Mountain Lion it was pretty simple once you figured out how to find the DMG buried in the installation application. For Mavericks, it is different. You can find the DMG in the package, but using the same method does not produce a bootable media. Instead, you have to use createinstallmeda which is a program buried in the installation package.

You must be root to execute the program, so you su or sudo to gain root privileges. The volume is the name of you USB drive. It takes while to to create, but does work.

# /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia –volume /Volumes/SanDisk –applicationpath /Applications/Install\ OS\ X\ Mavericks.app –nointeraction
Erasing Disk: 0%… 10%… 20%…100%…
Copying installer files to disk…
Copy complete.
Making disk bootable…
Copying boot files…
Copy complete.
Done.

Here is the help output:

Usage: createinstallmedia –volume –applicationpath [–force]

Arguments–volume, A path to a volume that can be unmounted and erased to create the install media.
–applicationpath, A path to copy of the OS installer application to create the bootable media from.
–nointeraction, Erase the disk pointed to by volume without prompting for confirmation.

Example: createinstallmedia –volume /Volumes/Untitled –applicationpath /Applications/Install OS X Mavericks.app

vSphere client in Windows 8.1

I could not get the vSphere client to install on Windows 8.1. I rebooted and it still didn’t work. It turns out that the client requires .Net Framework 2 or 3 to install. In Windows 8.1, it is a feature that just needs to be turned on. Go to Control Panel\Programs\Turn Windows features on or off. Then, check off .NET Framework 3.5 (includes .NET 2.0 and 3.0).

Once complete, you should be able to install the client.

Redirect certain subnets to a different site in Apache.

I did this from the httpd.conf where I have all my virtual directories defined. I just added the following within one of those virtual directory definitions and reloaded httpd. This will redirect anybody on the 192.168.0.0/24 subnet to http://google.com, and the others will proceed to the directory (/my/website/directory).


RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^192.168.0.*
RewriteRule .* http://google.com [R=302,L]

In an .htaccess file you would just need to add the following:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^192.168.0.*
RewriteRule .* http://google.com [R=302,L]

If you need to redirect the cgi-bin, elsewhere:


AllowOverride All
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^192.168.0.*
RewriteCond %{REMOTE_HOST} !^172.16.0.*
RewriteCond %{REMOTE_HOST} !^10.0.0.*
RewriteRule .* http://www.google.com [R=302,L]
Options ExecCGI
Options FollowSymLinks
Order allow,deny
Allow from all

Sending email from PHP using mail().

To send text email from PHP:

tomailaddress‘;
$from = ‘frommailaddress‘;
$subject = ‘Here is my subject.’;
$message = ‘Some text in the body of the message.’;

$headers .= ‘X-Priority:1 (Highest)’ . “\r\n”;
$headers .= ‘From: ‘ . $from . “\r\n”;
mail( $to, $subject, $message, $headers) or print ‘Could not send mail’;
?>

To send HTML email from PHP:

tomailaddress‘;
$from = ‘frommailaddress‘;
$subject = ‘Here is my subject.’;
$message = ‘
<HTML>
<BODY>
<B>
Some bold text
</B>
<P>
Some other HTML stuff.
</BODY>
</HTML>
‘;

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= ‘X-Priority:1 (Highest)’ . “\r\n”;
$headers .= ‘From: ‘ . $from . “\r\n”;
mail( $to, $subject, $message, $headers) or print ‘Could not send mail’;
?>

Windows and RDP key mappings

The Windows key has become much more important now that Windows 8 has been released. For someone who primarily uses Windows via RDP, it can make things a bit more difficult if you don’t know the some key combinations. I have listed a few that I commonly use below.

Windows Key: Alt-Home

Ctrl-Alt-Del: Ctrl-Alt-End

Alt-Tab: Alt+Page Up

Another interesting thing I found that has annoyed me in Windows 8 when using RDP is how to close metro applications. You can do this using a mouse. When in the metro application, move the mouse to the very top of the screen until the mouse pointer turns into a hand. Then, click and pull the window down to the bottom of the screen. This definitely beats what I was going before. I using Task Manager to kill the application.

Mutt – delete messages by date range

Finally got fed up when faced with how to delete 9,000 of 10,000+ email message using mutt in linux. The key is to get the messages tagged. To tag messages, hit “T” (capital T). Then, you will be presented a “Tag messages matching:” prompt.

Tag the messages by date:

Tag messages matching: ~d dd/mm/yyyydd/mm/yyyy

For example:

Tag messages matching: ~d 01/01/2012-31/12/2012

Tagged messages will now have an “*” (asterik).

Delete all the tagged messages:
Hit the “;” (semi-colon). You will have a “tag-” prompt. Then, just hit “d”.

Return top

INFORMATION