Posts

Setting the onSubmit handler with JavaScript

A common issue -- setting the onSubmit event handler of a form with JavaScript. I mean, it's easy enough to set it with <form id='theForm' onsubmit="return confirm('Really submit?');"> but here is how to do it with JavaScript <script type='text/javascript'> document.getElementyById('theForm').onSubmit = function() { return confirm('Really submit?'); }; </script>

Parsing HTML with Perl and XPath

I have had to write an HTML parser a few times already and I've always used HTML::Parser . Because it's simple and because I never bothered to do it anohter way. I always wanted to ideally do some parsing with XPath because that way I can easily find what I need with one or two queries. Unfortunately, XPath only works on properly formatted XML documents, so unless the page I am parsing is XHTML, I couldn't do much. I also wanted to somehow convert the HTML to properly formatted XHTML and use XPath with that. Unfortunately, I didn't know an easy way to do that either. Well, now I do. I can use the HTML::TreeBuilder module from HTML-Tree CPAN distribution. It is easy enough to use the module itself for parsing: my $tree = HTML::TreeBuilder->new_from_file("test.html"); my @img = $tree->look_down('tag', 'img', sub { $_[0]->attribute("src") =~ m!thumbnail!; } However, as I would rather use XPath, here is how to easily convert t...

VS 2005 does not want to profile my ASP.NET project

Image
Visual Studio 2005 does not want to profile my ASP.NET project! What's up with that? This is with the Team Edition that has the quite useful "Performance Tools" included. However, when I start a new Performance Wizard I don't see my ASP.NET web site project in the list of profileable projects. To make a long story short, the solution is to not select the "No Start Page" option in the debug dialog as shown in the following figure. Checking "Current Page" does not work either. Just to be safe, go with "Specific Page" and pick something from the list.

KVM: virtualize a single partition

A nice feature in XEN that I miss in KVM is the ability to use a single partition as a disk image. In XEN you can do disk = [ 'file:/dev/vg0/img_root,sda1,r' ] and you can also safely mount /dev/vg0/img_root when the virtual machine is not powered on. With KVM you're out of luck, or at least my googling returned lots of questions and no solutions. Well, there is a not so hard way of working around the issue.

External repositories in subversion

Edit the svn:externals property for the directory where the external stuff will go into svn propedit svn:externals . Add a line for each external entry you want to have: local/path http://external/repo local/path2 -r### http://external/repo Example for me adding jokey's virtualbox ebuilds: svn pe svn:externals /var/repos/chutz/app-emulation virtualbox http://overlays.gentoo.org/svn/dev/jokey/trunk/app-emulation/virtualbox virtualbox-additions http://overlays.gentoo.org/svn/dev/jokey/trunk/app-emulation/virtualbox-additions virtualbox-bin http://overlays.gentoo.org/svn/dev/jokey/trunk/app-emulation/virtualbox-bin virtualbox-guest-additions http://overlays.gentoo.org/svn/dev/jokey/trunk/app-emulation/virtualbox-guest-additions virtualbox-modules http://overlays.gentoo.org/svn/dev/jokey/trunk/app-emulation/virtualbox-modules The original tip was here .

ImageMagick command arguments

Note to self for common commands use by ImageMagick: The manual The examples Geometry specification [width]x[height][+-x+-y] Cropping Always use "+repage" or else... When cropping do specify +0+0 or you'll get lots of tiles Checking the output on the command line -- use xpm:- for output ( -compress none pbm:- is also kind-of usable). Thumbnail gallery: montage input*.jpg -tile XxY -mode Concatenate output.jpg

SQLite, .NET, and DataTable constraints

The problem Here's a simplified snippet of what illustrates the problem I had today. SQLiteCommand cmd = cnn.CreateCommand("SELECT a.a1, b.b1 FROM a INNER JOIN b USING (b1)"); SQLiteDataReader reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); reader.Close(); The problem is that dt.Rows.Count is way lower than what running the same statement in the SQLite CLI produces. The reason The reason is that DataTable complains about an invalid constraint on the "b1" column. Why? Because "b1" has a unique index in "b" and for some reason DataTable doesn't like it when you get to entries with the same value for that column regardless that it is perfectly legal when joining tables. The workaround I have no idea if this is a problem with SQLite or the AdoNet SQLite wrapper, and I haven't tried other databases to see if this is not a problem with SQLite at all. The workaround, however, is this: SELECT a.a1, b.b1 + 0 FR...