Archive for category Programming

“Order By” for Zend Db findDependentRowset()

This is another one of those note-to-self style posts.

Design decisions on Zend Db’s “Zend_Db_Table_Row_Abstract” class prevent the inclusion of an ‘order by’ clause directly in the (incredibly useful) “findDependentRowset” function.

But you can pass in the order by clause indirectly through a select statement as follows.

What you want would be something like:

$depRows = $row->findDependentRowset('DEP_TABLE_NAME', /*order by=*/'SORT_ORDER ASC');

and you get this by doing the following:

$depTable = new DEP_TABLE_NAME();
$depRows = $row->findDependentRowset($depTable, null, $depTable->select()->order('SORT_ORDER ASC'));

,

1 Comment

AppleScript desktop dialer for Asterisk

Asterisk Desktop Dialer

This is an incredibly simple idea – but incredibly useful: a desktop application (written in applescript) where you copy/paste the number you wish to dial, it connects to your local asterisk server via its management interface, and dials the number on your phone.

You’ll need a mac (obviously), a desktop phone (even more obviously), and an asterisk server (most obviously), preferably on your lan, which you can configure to allow network access to the AMI (Asterisk Manager Interface).
Read the rest of this entry »

, , , ,

1 Comment

Install python lxml 64 bit on OSX 10.5

This is one of those note-to-self style posts again.
I’m not really clear on why this has to be so damned complicated: every time I mess with lxml on OSX it costs me half a day!

The second-last time I had to do this, I actually stripped everything but the 32 bit executable out of apache to force it into 32 bit mode, so that I wouldn’t have to compile a 64bit lxml! (and yes, that’s just stupid, don’t do it).

Anyway, this is how I managed to get it to compile this time:

mkdir /tmp/lxml-build
cd /tmp/lxml-build
curl -O http://codespeak.net/lxml/lxml-2.3.tgz
tar -zxf lxml-2.3.tgz
cd lxml-2.3
mkdir libs
cd libs
curl -O ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz
curl -O ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz
cd ..

Here we need to modify the build code for lxml. (Yes, I know this shouldn’t be the case, but the arch is hardcoded in there for 10.5 as i386, and we simply have to change it).
Open the file buildlibxml.py, and, at around line 284, find the following lines:

            if minor_version < 6:
                env.update({
                    'CFLAGS' : "-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -O2",
                    'LDFLAGS' : "-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk",
                    'MACOSX_DEPLOYMENT_TARGET' : "10.3"
                    })
            else:

… changing them to the following …

            if minor_version < 5:
                env.update({
                    'CFLAGS' : "-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -O2",
                    'LDFLAGS' : "-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk",
                    'MACOSX_DEPLOYMENT_TARGET' : "10.3"
                    })
            elif minor_version < 6:
                env.update({
                    'CFLAGS' : "-arch x86_64 -arch i386 -O2",
                    'LDFLAGS' : "-arch x86_64 -arch i386",
                    'MACOSX_DEPLOYMENT_TARGET' : "10.5"
                    })
            else:

i.e. we change the first case to 10.4 and earlier, and add a case for 10.5 (the minor_version < 6 stuff).
We can now continue with the compilation as follows:

ARCHFLAGS='-arch x86_64' python setup.py build --static-deps --libxml2-version=2.7.3 --libxslt-version=1.1.24
ARCHFLAGS='-arch x86_64' sudo python setup.py install

And that should be it.

If something goes wrong, do a make clean before changing the build options. And note that you’ll probably need to restart apache (sudo apachectl restart) to pick up on changes.

References: here, here, and here.

, , , , ,

1 Comment

HTML vertical text (Safari, Firefox, Chrome, and Opera)

I recently had a requirement to display a large amount of tabular data in a small space – and to get it looking right, some of the text simply had to be vertical. My first solution was to use javascript on page load to replace the text with svg code, which essentially drew an svg image of the vertical text in place. While this looked fine, it resulted in quite a bit of client-side code running at page load, which resulted in a noticeable delay when the page got large.
My second solution was considerably neater however: css transforms.

HTML Vertical Text example

- – Before – -
- – After – -

Examples above. The first block is an image (screenshot of this in Safari), the second block is the real thing. If your browser supports this, the two should look broadly similar. The CSS for this is as follows:

.vText {
   -moz-transform: rotate(-90deg) translate(0, 100%);
   -moz-transform-origin: 0% 100%;
   -o-transform: rotate(-90deg) translate(0, 100%);
   -o-transform-origin: 0% 100%;
   -webkit-transform: rotate(-90deg) translate(0, 100%);
   -webkit-transform-origin: 0% 100%;
   transform: rotate(-90deg) translate(0, 100%);
   transform-origin: 0% 100%;
}

The first two lines (the -moz lines) are for current versions of firefox, the next two (the -o lines) are for recent versions of opera, the next two (the -webkit lines) are for Safari & Chrome, and the last two are for the future (assuming this gets beyond a working draft).

And no, this CSS doesn’t work with IE at present.

So how does it work?

  • transform-origin sets the, wait for it, origin, at the bottom-left corner. This will be the centre of the rotation when we rotate.
  • translate(0, 100%) moves the block vertically down by its own height (i.e. y = 100%), so that its top border is where its bottom border was.
  • rotate(-90deg) rotates the text 90° counter-clockwise.

The big caveat here is that the transforms do not change the original element dimensions (e.g. if it’s 100px wide before the transform, it will still take up 100px width after the transform), so you will generally need to put your vText element in a containing block which has the required width and height (i.e. after the transform) set.

, , , ,

6 Comments

Copy mysql table between servers/databases

This is one of those reminder-to-self style posts.

To copy mysql table tablename from database1 on server1 to database2 on server2, issue the following command (on either server)

mysqldump -h server1 -u user1 -ppassword1 database1 tablename | mysql -h server2 -u user2 -ppassword2 database2

user1, password1, user2, and password2 are the respective usernames and passwords to use on server1 and server2, respectively. Note that there is no space between the -p and password (unlike the other switches).

,

3 Comments

getmail FutureWarning with python2.3

Some python (I assume) update on an old Centos box made getmail bork:

/usr/lib/python2.3/optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will
return a signed string in Python 2.4 and up
return ("<%s at 0x%x: %r>"

It gets more than a little annoying when you get emailed those few lines several hundred times per day. However, according to the getmail FAQ, it’s not their fault – it’s the nasty evil lazy python developers’ fault.

Changing the top of the /usr/bin/getmail file to ignore the warning made it go away:

#!/usr/bin/python -Wignore::FutureWarning

,

No Comments

CSS min-width for Buttons in safari/webkit

… has stopped working in the latest webkit versions (for quite some time actually).

CSS min-width ignored for input type=”button” on webkit

(ok, you guessed it, I’m posting this just to draw uncle G’s attention. Sorry!)

, ,

No Comments

All zero dates, mysql, and jdbc

Cannot convert value '0000-00-00 00:00:00' from column N to TIMESTAMP

Familiar? This problem arises because ‘null’ dates in MySql are generally represented as ‘0000-00-00 00:00:00′, which, while valid in MySql, are completely forbidden in jdbc.

There is a wonderful workaround however, simply add the zeroDateTimeBehavior parameter to the end of your jdbc url as follows:

jdbc:mysql://hostname/dbname?zeroDateTimeBehavior=convertToNull

And that’s it, zero dates will be converted to nulls and jdbc will be happy.

,

No Comments

htmlspecialchars for mysql

Yes, it’s bad, evil, nasty, and just plain wrong.

But that doesn’t mean that there aren’t occasions when you do need to spew out html directly from mysql (or at least I’ve found one).

DELIMITER $$

DROP FUNCTION IF EXISTS `htmlspecialchars`$$
CREATE FUNCTION `htmlspecialchars` (_str text) RETURNS text
BEGIN
	set _str = replace(_str, '"', '&quot;');
	set _str = replace(_str, '&', '&amp;');
	set _str = replace(_str, '<', '&lt;');
	set _str = replace(_str, '>', '&gt;');
	return _str;
END$$

DELIMITER ;

Usual disclaimers apply.

,

No Comments

css.php