Show views, show triggers in MySQL 5.0

14/07/2008

Here’s what I do to be able to easily view views and triggers in the current database in MySQL command line program. It’s quicker than running select queries against the information_schema table and it only pulls the information I need. The internal MySQL “SHOW TRIGGERS” command spits out the actual trigger body making it pretty inconvenient if you just want a simple trigger names listing.

Here’s what you do:

– Universal triggers viewer using a stored procedure. Usage: CALL triggers();

DELIMITER |

CREATE PROCEDURE triggers ()
BEGIN
SELECT TRIGGER_NAME, DEFINER, EVENT_MANIPULATION,
EVENT_OBJECT_TABLE, CREATED
FROM information_schema.triggers
WHERE trigger_schema = database();
END;
|

– Universal views viewer using a procedure. Usage: CALL views();
CREATE PROCEDURE views ()
BEGIN
SELECT table_name, definer, is_updatable
FROM information_schema.views
WHERE table_schema = database();
END;
|

DELIMITER ;

MXIE VoIP phone system running on Ubuntu (8.04)

30/05/2008

We’ve just installed a new VoIP phone system called MXIE in our office. In order to make it work you need to hook your computer to a special kind of phone with a network cable and install a piece of software for configuring and managing the device. There are installation files available for Windows, Mac OS X and Linux. As I recently switched to a Dell Ubuntu laptop (at least for some time), I was interested in a .deb package. Unfortunately, the MXIE is officially available only for Red Hat and SUSE Linux operating systems, hence the only option they give Linux users is an rpm.

Below are the steps to prepare Ubuntu 8.04 for MXIE:

1. Convert the rpm file to a deb one with a tool called Alien. Alien is available in the Ubuntu Package Manager and the conversion runs smoothly with the following command:

$ alien -d [PATH_TO_MXIE_RPM]/mxie-3.2.10-0.i386.rpm

2. Launch Synaptic Package Manager and make sure libstdc++5 has been installed.

3. Open terminal and run the program:

$ mxie

I noticed the default application font was pretty large and clunky so I went to User preferences, selected “Appearance” and amended the size.

Bring up network interface and set up network connection on Fedora Linux (command line)

15/03/2008

Have you ever tried firing up a Linux VMware virtual machine configured with a static IP address on another machine? I did and I got into trouble with the local network and the Internet access.

In my case the vm was created by VMware Server on Linux and then copied onto my Mac and loaded in VMware Fusion. The appliance run in level 3 so it did not have any graphical environment (like KDE or Xfce) installed so all the configuration needed to be done on the command line.

The first symptom there was something wrong could be observed during the boot process when the following message popped up:

“Bringing up interface eth0: pcnet32 device eth0 does not seem to be present, delaying initialisation [FAILED]“.

After logging in as root I run this command just to make sure that was the case:

# /sbin/ifup eth0

… and got pretty much the same message as the one above.

I had a look at the VMware Fusion network device settings to ensure my wireless network card was bridged and connected and then run a set of commands described below.

1. Display all available network interfaces
# /sbin/ifconfig -a
eth1 Link encap:Ethernet HWaddr 00:0C:29:3E:42:B1
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:17 Base address:0x1080
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 b) TX bytes:560 (560.0 b)

2. eth1 is down, so let’s assign some IP address and the subnet mask to it (please note we do not use DHCP here)
# /sbin/ifconfig eth1 10.0.1.7 netmask 255.255.255.0

3. Check the current routing table
# /sbin/route
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 * 255.255.255.0 U 0 0 0 eth1

4. Specify default gateway
# /sbin/route add default gw 10.0.1.1

5. Last step - specify the name server address using a command line editor called vi
# vi /etc/resolv.conf
nameserver 10.0.1.1

(:wq to save the changes and quit)

6. Voila, the routing table now shows everything has been set up correctly
# /sbin/route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 * 255.255.255.0 U 0 0 0 eth1
default 10.0.1.1 0.0.0.0 UG 0 0 0 eth1

That’s it, your virtual machine is back on the network and you can now check it by pinging any domain you like. And to make these changes available after reboot you might want create/edit the /etc/sysconfig/network-scripts/ifcfg-eth1 file. My one has the following contents:

DEVICE=eth1
BOOTPROTO=static
BROADCAST=10.0.1.255
HWADDR=00:0C:29:3E:42:B1
IPADDR=10.0.1.7
NETMASK=255.255.255.0
GATEWAY=10.0.1.1
NETWORK=10.0.1.0
ONBOOT=yes

Startup script on OpenSUSE Linux cheat sheet

18/01/2008

Create a simple script invoking your commands, e.g.
case "$1" in
start)
/usr/local/NewAtlanta/BlueDragon_Server_JX_70/bin/StartBlueDragon.sh &
/usr/local/apache2/bin/apachectl start
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac

Drop it under /etc/init.d/ and make it executable.

Then run the following command:

chkconfig -a name_of_your_script

The chkconfig command copies your script to /etc/init.d/rc3.d and /etc/init.d/rc5.d prepending a couple of characters to the names so it can be executed during the boot process in runlevels 3 and 5 in a certain order. I tested my sample script that fires up Apache and BlueDragon JX on OpenSUSE 10.2.

Mail.app crashes on startup after Exchange settings update

18/12/2007

OK, this is one of those problems that come up only if you do something silly or simply something really unusual.

Basically, I experienced a terrible situation today when my Leopard Mail.app refused to work. It was crashing all the time even before the window would appear on the screen and a standard Relauch/Ignore dialog box was popping up all the time. This is one the error messages I found in Console which is a built in application and can be found under /Applications/Utilities:

18/12/2007 11:12:16 Mail[167] *** Assertion failure in -[LibraryToDo mailboxUid], /SourceCache/Message/Message-915/Library.subproj/LibraryToDo.m:205
18/12/2007 11:12:16 Mail[167] An uncaught exception was raised

18/12/2007 11:12:16 Mail[167] Mailbox UID is not set
Stack Trace: (
(
2530345579, 2474053787, 2530345035, 2462609636, 4844373, 3408319, 4829155, 2461484666, 2529720906, 2529721635, 2461473392, 13228, 4990192, 3024109, 2530368413, 2530366856, 3999207, 2461487181, 2461486068, 2472796277, 2472795954
))
18/12/2007 11:12:16 Mail[167] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Mailbox UID is not set’
18/12/2007 11:12:16 Mail[167] Stack: (
2530345579, 2474053787, 2530345035, 2462609636, 4844373, 3408319, 4829155, 2461484666, 2529720906, 2529721635, 2461473392, 13228, 4990192, 3024109, 2530368413, 2530366856, 3999207, 2461487181, 2461486068, 2472796277, 2472795954
)

The first question is: what might have caused that? And the answer is: a recent update of my Exchange email account settings in Mail.

Last night I was VPNing to my office network and I was forced to replace the Exchange server hostnames with raw IP addresses (under Mail Preferences -> Accounts -> Incoming and Outgoing Mail Server) because for some reason my computer stopped resolving them and was not able to send and receive messages anymore. And when I got to the office today and tried to access my email, the application started crashing.

Solution
As I wasn’t able to access Mail and restore the previous Exchange settings I decided to create a new Mac OS X user account in order to temporarily replace my corrupt ~/Library/Mail settings with a fresh bunch of files. I backed this directory up and after sorting out the permissions I grabbed the files from /Users/NEWLY_CREATED_ACCOUNT/Library/Mail and dropped them under ~/Library/Mail. Then I tried firing Mail up and this time it did not crash. I fixed the the Exchange settings, restored the original, backed-up copy of ~/Library/Mail, restarted the Application and could see everything up and running again.

The moral of the story is “don’t give up when Mail doesn’t want to start” :-) Just create a new user account, replace the Library settings and start the process from there. I don’t know if there is any other way (other than the one with the updated Exchange settings) of making Mail crash but if there was one, going this route might be a good way of restoring your email without even thinking about reinstalling the system or anything as severe as that.

Missing cfdump styles on pages with certain types of DOCTYPE

11/12/2007

I’d had this problem for ages: during the development of a standards compliant site that includes a Doctype statement at the top of the XHTML code, it is not possible to comfortably use the cfdump function, a very nice tool for dumping variables that all CF developers are familiar with. All the styles are missing so instead of those nifty, colourful tables you are left with some bits of raw text on a white background that look quite ugly and are hard to work with. This issue occurs on ColdFusion and BlueDragon, probably because both engines use the same bit of CSS.

I came up with a simple solution to this problem: I just slightly modified the cfdump inline code making it a little more standards compliant and put it in an external CSS file. As a result, instead of this kind of layout:
cfdump screen grab when Doctype defined
…you get this:

cfdump screen grab when Doctype defined and the cfdump.css file included

The results are not exactly the same as the original ones, probably because of some CSS conflicts on this particular page, but I think it’s still worth trying.

The CSS file that repairs the styles can be downloaded below:

A patch for the CFML cfdump function run in an XHTML Doctype environment

Report recently changed files with the directory hierarchy preserved (command line)

11/12/2007

This little command is very useful eg if you want to find out what files in your project have been modified recently. The beauty of the script is not only it outputs a list of files in your terminal but it also zips them up (or tars in this case) preserving the whole hierarchy of folders. The tar file can then be gzipped, bzip2ed or simply untarred so you can review the folders structure and your modified files.

Here’s an example of a command that displays the files modified within last two weeks on the screen, tars them and saves the tar file on your desktop. I tested this script both on the Mac and Linux.

$ tar cvf - `find /var/www/my_project -type f -mtime -14 -print` > ~/Desktop/project_recent_changes.tar

Redirecting in CFscript - CFML cflocation equivalent

5/12/2007

In CFML you go:

<cflocation url="http://google.co.uk/">

with an additional “addtoken” attribute if needed.

Cflocation can be used both for external and local redirects, so you might as well want to have something like this:

<cflocation url="/section/page.cfm">

In cfscript there is no native equivalent function so you basically have two options. Either write a little wrapper UDF (using the CFML language) for the cflocation tag or take advantage of the GetPageContext function. If you want to replicate the cflocation behaviour in exactly the same way as it is in CFML, you can pick:

GetPageContext().getResponse().sendRedirect("LOCAL PATH OR URL");

AFAIK this hits the web server twice so for local redirections the forward method is a better solution:

GetPageContext().forward("LOCAL PATH");

The examples above have been tested on BlueDragon JX 7.0 on SUSE Linux.

DVD Player “skipping over damaged area” problem on Mac OS X Leopard

2/12/2007

I bought a new Sigur Ros DVD the other day and after inserting it to the drive DVD Player would display a “skipping over damaged area” message in the top left corner of the screen and refuse to play the film. The menu would also not be clickable but I would still hear the background sound. After some googling I found out that other people also experienced similar issues on Leopard. It looks like there is no fix for it at the moment and the only thing you can do is installing other software. I picked a well known VLC player and all have been working fine since then.

Subversion freezes during a Linux working copy update process

1/12/2007

Tip: make sure you don’t have any symbolic links between files with (almost) the same names that might have been deleted during the update.

It’s probably a pretty rare situation where you have two files with the same name residing in the same directory where the only difference between their names is the case, eg File.ext and file.ext. In my situation I was forced to create a couple of symbolic links of that kind because I was developing an application on a Linux virtual machine where case matters and the main copy of the application was running on a Windows box. Some other bits of the system were written by developers who apparently did not pay much attention as to whether they refered to File.ext or file.ext, therefore the need for symbolic links.

But the problem arose during a standard svn update procedure when after running the ls -l command I noticed the following:

total 1
lrwxr-xr-x 1 user group 8 1 Dec 14:06 File.txt -> file.txt

whereas before you’d have got:

total 2
lrwxr-xr-x 1 user group 8 1 Dec 14:06 File.txt -> file.txt
-rwxr-xr-x 1 user group 8 1 Dec 13:16 file.txt

I understand what happens here is that Subversion deletes file.txt during the check out and, for some reason, the whole process freezes. I found a simple solution to this issue by simply removing the dead symbolic link (rm -f File.txt). After that’s been done, the subversion update continues its work without any problems. Unless it doesn’t delete another link target file of that kind…