Connect WordPress to a second database

While building a wordpress site and needed to work with a separate existing database.
Added a function in wp-includes/functions.php like this:


function my_query($sql){
$db = @mysql_connect("my_DB_host", "DB_usr", "DB_pass");
mysql_select_db("my_other_database");
$result = mysql_query($sql) or die('Did not get required database result');
return $result;
mysql_close($db);
}

Then wherever I need to connect to this database I can use the function like this:


$sql = sprintf("SELECT blah FROM table");
$result = my_query($sql);

Posted in Uncategorized | Leave a comment

Reboot Windows XP via Remote Desktop

I work on remote machines fairly often. Sometimes a software install will ask for a reboot. But when you click the “Start” button, the options aren’t there!

Right click on the task bar at the bottom and go to task manager, look for the menu named ‘Shutdown’ and choose ‘Restart’

that’s it!

Posted in Uncategorized | Leave a comment

Convert MSSQL dates to MySQL

I’m moving a database from MSSQL to MySQL, I was cruising along with CSV files until I hit a table that has some date columns. They weren’t showing up right no matter what, until I found this post:

http://abbyandwin.net/blog/2007/08/14/how-to-convert-mssql-date-format-to-mysql

Here’s the query to run on MSSQL:

SELECT CONVERT(VARCHAR(40),[date_column_name],120) AS new_date_format FROM [table_name]

Thanks Abby & Win!

Posted in Uncategorized | Leave a comment

How Long does it take to copy VMs with VMWare vCenter Converter Standalone?

Still considering whether it will be worth purchasing vCenter software, for now I am getting by with the free tools supplied by VMWare. To clone a new VM from one ESXi host to another, I powered it down and used vCenter Converter to do a VM to VM copy.
The VM I’m copying was about 350GB. When I launched the Task, the Estimated time was 1 hour. After the progress achieved 1%, the estimated time jumped up to 1 day, 18 hours. It remained there as progress reached 2% about an hour later. I came back the next morning about 15 hours later, and the conversion was completed successfully. Very glad it didn’t take more than 1 day or I would’ve had to stop the process and find another way.

Posted in Uncategorized | Leave a comment

Moving Repository: cvs checkout: Codepage transformation not supported by server. Results may not be correct

We have a CVS repository on linux and Tortoise CVS users on windows. Sometimes we need to move our repository and users start seeing the subject error. Wasted time looking into it, has to do with UTF-8 stuff going from linux to windows… Apparently it can be safely ignored in the modern versions of Tortoise CVS, don’t waste your time with it!

Another issue with the CVS move is changing all the CVS Root files to reflect the new hostname; this blog post has the right answers. Created the changeroot.sh file and updated our newly located branches to know where they belong.

First off we need to change the CVS Root for the working copy. Here’s the script that will do the job:

#!/bin/bash
# Test whether we got an argument for the new CVS Root value - exit if not
# -z is a bash conditional experssion that returns true
# if the has a zero length
if [ -z "$1" ]; then
echo "

You must supply a new value for CVSRoot
usage: $0

Examples:
To change to an external repository accessed via ssh:
./changerepository.sh :ext:crb@webdevcvs:/Users/Shared/cvsrep

To change to a local repository:
./changerepository.sh /Users/Shared/cvsrep
"
exit
fi
# if we were passed a new CVS Root value on the command line, assign it to
# the newRoot variable
newRoot=$1
# walk the current directory (find . ) and if the path matches */CVS/Root,
# slap the new CVS Root into the files found
find . -path "*/CVS/Root" | while read f; do
echo $newRoot > $f
done

To run this script and change the root, copy and paste the code into your favourite text editor, save it as changeroot.sh in the root directory of your working copy and chmod it to be executable. You can then run it using

./changeroot.sh [newcvsrootvalue]
Where [newcvsrootvalue] is the name of your new CVS Root, for example:

./changeroot.sh :ext:me@newrepository.net:/usr/local/cvsrep
If its just the host name of your repository that has changed, you’re done

thank you solarorange :)

Posted in Uncategorized | Leave a comment

How To Install HandBrake Command Line Version on Ubuntu Server 10

Handbrake is a great tool for encoding video. Best of all it is open source and free. If you are running Ubuntu server, here are the steps to install it quickly and painlessly!

$ sudo su
# apt-get install python-software-properties
(hit Y to continue)
# add-apt-repository ppa:stebbins/handbrake-releases
# apt-get update
# apt-get install handbrake-cli
# HandBrakeCLI -u
HandBrake 0.9.6 (2012030100) – Linux x86_64 – http://handbrake.fr
Your version of HandBrake is up to date.

Find your encode settings then start encoding, woohoo!

Posted in Uncategorized | Leave a comment

Format USB on Ubuntu Server

I have a brand new USB drive and I want to backup some contents on my server. I hooked up the drive and type “mount -t ext3 /mnt/usb /dev/sdc1″ but the drive is not formatted so this gave me an error.

The steps to format the new USB from Ubuntu server command line are as follows:
type “dmesg” to find / make sure you have the correct drive letter (in my case, sdc)
type “fdisk /dev/sdc” (this returns a menu listing)
type “n” for new
type “1″ for partition number and use the defaults for start and end points.
Then type “w” to save the changes.
now to format the new partition, type “mkfs -t ext3 /dev/sdc1″
then the mount command works.

Posted in Uncategorized | Leave a comment

Can’t locate File/Pid.pm in @INC

Sometimes when I move a script onto a new server, i see the subject error.
File::Pid is a handy little perl toolkit for keeping track of your own pid.
Every time I see the error I scramble around trying to find the fix. So here it is:
perl -MCPAN -e shell
> install File::Pid

Posted in Uncategorized | Leave a comment

OpenSSL Signing my own certificates Error Solved

this is on CentOS:
sudo openssl ca -in /opt/openssl/testCA/server/requests/testWEB.CSR -cert /opt/openssl/testCA/CA/testCA.CRT -keyfile /opt/openssl/testCA/CA/testCA.KEY -out /opt/openssl/testCA/server/certificates/testWEB.CRT
Using configuration from /etc/openssl.cnf
I am unable to access the /etc/openssl/testCA/certs directory

I tried creating the folders and files it wanted, what a mistake.
I finally found the proper thing to do is to find the install folder, such as /usr/share/src/openssl-1.0.0z
then copy the contents of apps/demoCA into wherever openssl is looking, eg for the example above,
cp -a /usr/share/src/openssl-1.0.0z/apps/demoCA/* /etc/openssl/testCA/certs/

Posted in Uncategorized | Leave a comment

Trouble with PDF::API2 paragraph function

We have some ancient code for printing documents that relied on the PDF::API2 module. When we upgraded our systems, this module has some different behavior and our program was throwing errors.
First, I commented out the “pdf->page->text->compress” function calls and that helped. But some text was not showing up. Turns out the “text->paragraph” function totally changed. Thankfully google led me to this page where I found the proper way to update my paragraph calls:

OLD
$text->paragraph("Hello, just a test."x10, -x => 300, -y => 600, -h => 600, -w => 200);

NEW
$text->translate( 300, 600 );
$overflow = $text->paragraph( "Hello, just a test. "x10, 200, 600 );

Scary note at the bottom, but applying the change above worked for me!
DEVELOPER METHOD means:
1. This method may not do anything useful.
2. This method may erase your hard disk(s).
3. This method may erase the hard disks on any machine your machine is connected to.
4. This method is subjected to change *without* notice.

Posted in Uncategorized | Leave a comment