Wednesday, October 12, 2011

Preserving a leading zero on a number in a text field in Excel

At work we're writing UPC codes to a TSV file. Often a UPC has a leading zero, which is automatically whacked when the file is opened in Excel. The trick is to write the UPC cell to the TSV file as

="027297909021"

This preserves the zero.


Friday, August 19, 2011

OMG, command line editing in mysql client

This is freaking awesome. To enable command line editing and searching in the mysql client, create ~/.inputrc and add the following lines...

set keymap vi
set editing-mode vi

Bam, vi commands in the shell. This is literally shaving hours off my work time.

Friday, March 25, 2011

Perl Module Tricks

To check the existence of a module, if the following completes with no errors, it's installed...

perl -MXML::Simple -e 1

To get the version of a module...

perl -MXML::Simple -e 'print "$XML::Simple::VERSION\n"'

Removing a CVS sticky tag

Yes, I'm sorry to say, I still have to use CVS for some tasks. We've talked about upgrading to SVN, at least, but I doubt it will happen soon. To remove a sticky tag and update a file to the latest revision (HEAD), use the following...

cvs update -A filename

Thursday, November 18, 2010

'clear' command in Cygwin/Terminator

I'm stuck on a Vista box for a desktop gateway to development servers. One of this things I miss is the clear screen command ('clear"). Other users have reported with Cygwin in a cmd window, a ctrl-L clears the screen, but this doesn't work for my environment.

I just installed the ncurses package in Cygwin and now have a working 'clear' command in Cygwin under Terminator.

Tuesday, November 10, 2009

Using mysql cli client in MAMP

I'm on a new contract and we're using OS X for development. Instead of getting the full LAMP stack for OS X, they use the MAMP (Mac, Apache, MySQL, PHP) collection for a one-click solution. http://www.mamp.info

MAMP includes the MySQL GUI tools, but I was wanting to use the command line version of the mysql client. Here's how...
/Applications/MAMP/Library/bin/mysql -uroot -p

Wednesday, June 10, 2009

(Semi) Secure Wrapper Script for mysqldump

I resurrected this script to do the backup of a client's MySQL database. I run it as a cron job once a day and keep the dump file on a separate server. The MySQL login info is kept in the mysql_access file which I have chmoded to be read-only for me. (chmod 400 mysql_access).

#!/bin/sh

#for debugging
#set -x

TODAY=$(date +"%D - %T")
HOST=$(hostname)
LOGFILE="${HOME}/TFP/logs/backup.log"
SHORTDATE=$(date +"%G%m%d")
DUMPFILE=${HOME}/TFP/dumps/tfp_${SHORTDATE}.sql

source ${HOME}/bin/mysql_access

echo "" >> $LOGFILE
echo "-------------------------------------------" >> $LOGFILE
echo "Date: $TODAY Host:$HOST" >> $LOGFILE
echo "-------------------------------------------" >> $LOGFILE
echo "" >> $LOGFILE

echo "Dumping $MYSQL_DB at $MYSQL_HOST to $DUMPFILE" >> $LOGFILE
mysqldump -h $MYSQL_HOST -u $MYSQL_USER $MYSQL_DB -p$MYSQL_PASSWORD > $DUMPFILE

echo "" >> $LOGFILE
WCSIZE=$(wc $DUMPFILE)
echo "wc for $DUMPFILE is" >> $LOGFILE
echo " $WCSIZE" >> $LOGFILE

echo "" >> $LOGFILE
FILESIZE=$(ls -lh $DUMPFILE)
echo "filesize for $DUMPFILE is" >> $LOGFILE
echo " $FILESIZE" >> $LOGFILE


The contents of the mysql_access include:

MYSQL_USER="some_username"
MYSQL_PASSWORD="password"
MYSQL_HOST="mysql.somedomain.com"
MYSQL_DB="some_database"


My hosting company sends me email with the output of the cron job. I include the size of the dump file in the output so I can just keep a running check on the output in case anything gets out of control.

Comments?