Mozilla, javascript and xml parsing.

So I did an ajax application, which used ajax to pass around potentially large amounts of xml (something i may choose not to repeat). Some very strange errors were appearing, which i traced to some nodes being truncated.

After much testing, i saw that the xml was intact, the node was intact, but when I used my GetNode function, it was truncated. Turns out that for very long (larger than 4096 characters) , the engine creates multiple text nodes, so the trusty node.firstChild.nodeValue only returned the first 4096 characters of the text!

The fix appears to be to iterate through the childnodes, building a string as you go, as done here.

———-

getNodeValueDebug = function(node,key,debug){

if (!node || node.getElementsByTagName(key).length == 0||  node.getElementsByTagName(key) == null){
return null;
}
if (node.getElementsByTagName(key)[0].firstChild){

var val=”";
var obtext = node.getElementsByTagName(key)[0];

//have to build it up to avoid truncation
for(var cnt=0; cnt < obtext.childNodes.length; cnt++)
{

if (debug){
alert(val.length +”:”+obtext.childNodes[cnt].nodeValue.length);
}
val += obtext.childNodes[cnt].nodeValue;
}

return val;

}else{
return null;
}
}

.net mysql , and the unreliable connection state.

I posted this as a bug on mysql… here it is again

Well, it seems to me that Connection.State is not reliably correct. If I stop
and start the mysql server, the state still reads as open, and throws
'connection reset' exceptions if i act on it.

So, I made a wrapper class, because the MysqlConnection class is sealed and I
couldn't extend. Here it is for your benefit.
---------
/*
* User: bill@bigmojo.net
* Date: 9/12/2005
* Time: 11:16 AM
*
*/

using System;
using System.Data;

using MySql.Data.MySqlClient;

namespace My.MySqlConnection
{

///
/// Description of MySqlConnection.
///
public class xmmsMySqlConnection:IDbConnection
{
private MySqlConnection _mysql = null;

public xmmsMySqlConnection()
{
_mysql = new MySqlConnection();
}

#region IDbConnection Members

public void ChangeDatabase(string databaseName)

{

_mysql.ChangeDatabase(Database);

}

public IDbTransaction BeginTransaction(System.Data.IsolationLevel il)

{

return _mysql.BeginTransaction(il);

}

IDbTransaction System.Data.IDbConnection.BeginTransaction()

{

return _mysql.BeginTransaction();

}

///
/// This is why we have this class, return results of ping, more reliable.
///
public System.Data.ConnectionState State

{

get

{

if ( _mysql != null && _mysql.State != ConnectionState.Closed &&
_mysql.Ping()){
return _mysql.State;
}else{
return ConnectionState.Closed;
}

}

}

public string ConnectionString

{

get

{

return _mysql.ConnectionString;

}

set

{

_mysql.ConnectionString = value;

}

}

public IDbCommand CreateCommand()

{

return _mysql.CreateCommand();

}

public void Open()

{

_mysql.Open();

}

public void Close()

{

_mysql.Close();

}

public string Database

{

get

{

return _mysql.Database;

}

}

public int ConnectionTimeout

{

get

{

return _mysql.ConnectionTimeout;

}

}

#endregion

#region IDisposable Members

public void Dispose()

{

_mysql.Dispose();

}

#endregion
}
}
----------------

Installing Image Magick, Magick Wand, PHP, FreeType

This is largely by another fellow from

here , I added some updated version #’s, as well as freetype support.

——————-

I did the build in tmp,

Get your ImageMagick
wget ftp://ftp.imagemagick.net/pub/ImageMagick/ImageMagick-6.2.9-8.tar.gz

Get your delegates

wget wget ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/jpegsrc.v6b.tar.gz
wget wget ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/jasper-1.701.0.zip
wget ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/libpng-1.2.12.tar.gz
wget http://www.peregrinehw.com/downloads/gd/ghostscript-8.15.tar.bz2
wget http://www.peregrinehw.com/downloads/gd/ghostscript-fonts-std-8.11.tar.gz

extract them all.

copy the ghostscript fonts to the default dir.
mkdir /usr/local/share/ghostscript/fonts

cp ./ghostscript-fonts-std-8.11/* /usr/local/share/ghostscript/fonts/

make an ‘ext’ directory in ImageMagick
mkdir ./ImageMagick-6.2.9-8/ext

copy all the delegate folders there, give them nicer names like
jpeg
jasper
libpng
ghostscript

./configure and build jpeg
copy the jpeg folder into the ghostscript folder

./configure and build ghostscript

./configure and build jasper

./configure and build and install libpng

i use a text file for my configure params for ImageMagick
cd /tmp/ImageMagick-6.2.9-8/

touch myconf

this is the contents of MY configuration
./configure  –with-windows-font-dir=/usr/share/fonts/monotype/TrueType –enable-shared –with-exif=yes –enable-lzw=yes –with-gs-font-dir=/usr/local/share/ghostscript/fonts -without-x CPPFLAGS=’-I/tmp/ImageMagick-6.2.9/ext/jpeg -I/tmp/ImageMagick-6.2.9/ext/libpng -I/tmp/ImageMagick-6.2.9/ext/jasper’ LDFLAGS=’-L/tmp/ImageMagick-6.2.9/ext/jpeg -L/tmp/ImageMagick-6.2.9/ext/libpng -L/tmp/ImageMagick-6.2.9/ext/jasper -lfreetype’

you can see where you point ImageMagick at the various delegates

so, then I configure
./myconf > configure.log

after that happens, inspect the configure.log  , with any luck it’ll look like this, the only thing i didn’t get was jpeg2000 (thats jasper) , I’m not to worried about it, but possibly if you did a make build on jasper before configuring image magick it would work.

—-
Shared libraries  –enable-shared=yes        yes
Static libraries  –enable-static=yes        yes
Module support    –with-modules=yes        yes
GNU ld            –with-gnu-ld=yes        yes
Quantum depth     –with-quantum-depth=16    16

Delegate Configuration:
BZLIB             –with-bzlib=yes        yes
DPS               –with-dps=yes        no
FlashPIX          –with-fpx=no        no
FontConfig        –with-fontconfig=no        no
FreeType          –with-freetype=yes        yes
GhostPCL          None                pcl6 (unknown)
Ghostscript       None                gs (8.15)
Ghostscript fonts –with-gs-font-dir=/usr/local/share/ghostscript/fonts    /usr/local/share/ghostscript/fonts/
Ghostscript lib   –with-gslib=yes        no
Graphviz          –with-gvc=yes        no
JBIG              –with-jbig=yes        no
JPEG v1           –with-jpeg=yes        yes
JPEG-2000         –with-jp2=yes        no
LCMS              –with-lcms=yes        no
Magick++          –with-magick-plus-plus=yes    yes
PERL              –with-perl=yes        /usr/bin/perl
PNG               –with-png=yes        yes
RSVG              –with-rsvg=no        no
TIFF              –with-tiff=yes        no
Windows fonts     –with-windows-font-dir=/usr/share/fonts/monotype/TrueType    /usr/share/fonts/monotype/TrueType/
WMF               –with-wmf=yes        no
X11               –with-x=no            no
XML               –with-xml=yes        yes
ZLIB              –with-zlib=yes        yes
——–

then do make && make install , walk away, it takes about forever..

that should do it! try this out
echo “This is a test” | convert -background yellow -page 200×50 text:- mediocreimage.jpg

The Auto suggest typeahead conundrum

UPDATE AGAIN: apparently this IS working on safari, so there you go..
UPDATE : apparently this isn’t working on safari, any mac devs out there that are interested, I don’t have a mac, so testing is a problem….

So I wanted to do an autosuggest type box, along the lines of google suggest, or the flickr tags.

I found this example at codeproject , which seemed to do the right thing, but as the comments suggest, its crazy heavyweight.. To run the example you need a database, need to compile the project, etc.. etc… Seemed unnecessary. Also, the javascript was > 80k , huge.

It turned out almost all of this javascript was the Google XSLT libraries, which were being used to simply draw 1 div. Also, this example had no keyboard handling, or multi-word support.

So, I’ve created the ’skinny typeahead demo’ , this is dramatically smaller (javascript file is 7k) and runs without a database or server side script (for the demo, your implementation will need something to provide the word suggestions).

This demo supports keyboard control (up/down arrow, enter key to select) , as well as comma separated words, so if you use a comma, it will start providing suggestions based on the word after the comma.

Here is a functional demo and here is a zip of the project

Text append for GTD on windows

I follow 43 folders regularly , and am a big fan of what they do.

After reading the coverage of the quicksilver tool , which essentially allows you to easily append some text to a file, or in GTD terms add an action item to a list. This seemed very handy, and I wasn’t able to find an easy to use tool on windows to do the same, so I’ve written one, and it’s called “Monsters GTD”.

Monsters GTD allows for quick hotkey based text appending to a text file, below find a quickstart guide.

1. download the zipped exe

2. extract the zip file to a location of your choice (perhaps the desktop, or c:\gtd)
3. run MonstersGTD.exe (from the location you just extracted it to)


4. on launch it will ask you to specify where you would like to keep your lists, (c:\gtdlists for example)

5. The app will launch, with no lists, select ’settings -> add a list’

6. enter your list name and press ‘Create List’ (or hit enter)

7. Your list will be created, and the focus will be in the enter note box, type your note and press ‘Append’

8. that’s it, press close. Check your list with notepad to be sure everything worked.

I recomend you setup a hotkey to launch the app, simply create a shortcut for the app on the desktop, get the properties for that shortcut and set the hotkey in the properties dialog. With this done, the key strokes can be

hotkey (ctrl-m for example)

arrow key up/down to select list

tab to notes dialog, enter note

tab to append button, space bar to append

tab to close button, space bar to close

4 key strokes seems pretty good to me.

Enjoy