SVN Clients

Mac SVN Clients

Windows SVN Clients

Recover the MySQL Root Password in Linux

Step 1 - At the linux shell, stop the current mysqld process, start the mysqld_safe process with –skip-grant-tables switch and login as root (no password).

/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root

Step 2 - At the mysql shell set the root password and flush privileges.

USE mysql;
UPDATE user SET password=PASSWORD("new-password-here") WHERE User='root';
FLUSH PRIVILEGES;
QUIT;

Step 3 - Back at the linux shell stop the mysqld_safe process and start the normal mysqld process. At this point you should be able to successfully login as root using the password from Step 2.

/etc/init.d/mysql stop
/etc/init.d/mysql start
mysql -u root -p

Set MySQL Root Password

To reset the MySQL root password, login to the mysql shell and run the following commands.

SET PASSWORD FOR root@localhost=PASSWORD('RootPasswordHere');
FLUSH PRIVILEGES;

Grant MySQL Privileges

To grant all privileges to a user from any location login to the mysql shell and run the following queries.

GRANT ALL PRIVILEGES ON *.* TO username@localhost IDENTIFIED BY 'PasswordHere' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO username@"%" IDENTIFIED BY 'PasswordHere' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Apache Cache Control using mod_expires with Expires By Type

Use Apache’s mod_expires to explicitly set the expiration of a file by it’s type. This will enable to browser to cache these static assets and greatly increase performance.

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "now"
    ExpiresByType text/html "now"
    ExpiresByType text/xml "now"
    ExpiresByType text/css "access plus 8 hours"
    ExpiresByType text/plain "access plus 8 hours"
    ExpiresByType application/x-javascript "access plus 8 hours"
    ExpiresByType application/x-shockwave-flash "access plus 8 hours"
    ExpiresByType application/pdf "access plus 8 hours"
    ExpiresByType image/gif "access plus 8 hours"
    ExpiresByType image/png "access plus 8 hours"
    ExpiresByType image/jpeg "access plus 8 hours"
    ExpiresByType image/x-icon "access plus 8 hours"
    ExpiresByType video/x-flv "access plus 8 hours"
    ExpiresByType video/quicktime "access plus 8 hours"
</IfModule>

NewsGator, FeedDemon and NetNewsWire RSS Feed Readers

There are a ton a excellent desktop and web based RSS feed readers available to choose from. My favorites by far are FeedDemon for Windows and NetNewsWire for Mac.

The last few years I’ve been using both with NewsGator Online to read and sync my news feeds daily. I’ve found this to be the perfect combo, allowing me to move from one machine to the other without seeing the same news item twice.

Earlier this week it was announced that both FeedDemon and NetNewsWire would be available for FREE (previously $30 each). If you’ve been looking for a commercial quality RSS feed reader then I highly recommend you give these a shot!

NewsGator Online

NewsGator Online Screenshot

FeedDemon

FeedDemon Screenshot

NetNewsWire

NetNewsWire Screenshot

Using the ternary operator in PHP

The ternary operator is an excellent and often underutilized way to quickly evaluate a variable in place of an if/else statement. The syntax is clean and can greatly simplify code.

( expr1 ) ? ( expr2 ) : ( expr3 )

Take the following code for example where we determine how to greet a user.

<?php
    if(isset($user)) {
        echo $user->name;
    } else {
        echo "Guest";
    }
?>

The code above is simple enough but let’s see how we can improve it by refactoring using a ternary operator.

<?php echo (isset($user)) ? $user->name : "Guest"; ?>

Update 1: There is a great collection of examples over at dzone.

Update 2: Found another nice tips and tricks post over at dzone.

Update 3: One more to check out.

Using Rsync over SSH

Prerequisites

First make sure that you are able to login to the remote host using ssh key authentication.

Basic Syntax

To sync files from a local directory to a remote directory use the following syntax:

rsync {options} -e ssh {source} {dest}

Example

Here is an example that exclude all .psd and .fla files:

rsync --exclude *.psd \
        --exclude *.fla \
        -avz -e ssh /local/dir/ user@remotehost:/remote/dir/

Using tar and gzip to Compress Files and Directories

Create and Compress and Archive

Archive a group of files:
tar -czvf archive.tar.gz file1 file2 file3
Archive an entire directory:
tar -czvf archive.tar.gz directory/

Extract a Compressed Archive

tar -xzvf archive.tar.gz

List the Contents of a Compressed Archive

tar -tzvf archive.tar.gz

Common tar Switches

  • -c create a new archive
  • -x extract files from an archive
  • -t list the contents of an archive
  • -z filter the archive through gzip
  • -v verbosely list files processed
  • -f filename of the archive (filename must always immediately follow)

SSH Login Using Public Key Authentication

Step 1: Generate Keypair on Localmachine

ssh-keygen -t dsa

When prompted for a passphrase you can leave it empty to enable logging in without a password (please note that there are potential security issues with doing this).

After confirming your passphrase at the second prompt you’ll find two new files (the keypair) in your ~/.ssh directory. The first file id_dsa is your private key, the second file id_dsa.pub your public key.

Step 2: Set Local ~/.ssh Permissions

chmod 700 ~/.ssh

Step 3: Copy Public Key to Remote Server

scp ~/.ssh/id_dsa.pub username@remoteserver:~/id_dsa.pub

Step 4: Login to Remote Server:

ssh username@remoteserver

Step 5: Update Authorized Keys on Remote Server

cat id_dsa.pub >> ~/.ssh/authorized_keys

Step 6: Set Remote ~/.ssh Permissions

chmod 600 ~/.ssh/authorized_keys

Done!

At this point you should be able to login to the remote server without using a password.

ssh username@remoteserver
 - or - 
ssh -i ~/.ssh/id_dsa username@remoteserver