Emailing a webpage from the command line

There are many situations whey you have information on a web page that needs to be emailed to individuals on a regular basis. Often times all that is needed is some type of script that will grab a URL, put it in an email and send it to the correct person. This article is going to look at some of the tools that can be used to do this. I’m testing it on OS X, but it should work under Linux, Unix and possibly Cygwin as well.
Continue reading “Emailing a webpage from the command line”

Using Javascript to Refresh Parent

First let me say that I’m not a huge fan of Javascript. I understand the need for Javascript, but generally I prefer to program for a server environment instead of worrying about the client. However I ran into an issue this week that required Javascript, so here is what I learned about refreshing a parent window.

I had a web page that would list a bunch of items. Users needed to be able to click the “add” button and open a pop-up window that would let them choose an item to add to the list. The pop-up window displayed a hierarchy of choices so users had to click on it several times in order to make their selection.
Continue reading “Using Javascript to Refresh Parent”

Dealing with Slow XSLT Transformations

I have some XSLT stylesheets that I use to integrate information from Amazon with my reading list on my website. This weekend I decided to create another list using Amazon’s “People Who Bought this Book also Bought” feature. After a couple generations of downloading books that were related to books I read, I ended up with an XML file with about 1,500 books in it. I tried running the transform using Xerces and it took 13 hours.

Obviously this wasn’t going to work, so I refactored parts of the XSLT and was able to cut that time in half. 6 hours still seemed like it was taking far too long. I considered doing away with the stylesheets and doing the transforms manually using Java to write directly to a file. After doing some searches I discovered that apache.org has a good solutions for this problem that is part of the Xalan-J project. Basically it allows you to take an XSLT stylesheet and compile it into java byte code called a “translet”. You can then run the transform using Xalan and the compiled java translet. This makes things run much quicker. It appears that this is because the transform doesn’t need to deal with the XSLT file and because of other optimizations.
Continue reading “Dealing with Slow XSLT Transformations”

Running out of Memory with Java

The other day when doing some particularly large xslt conversions I kept running out of memory in the JVM. After doing a bit of research I found two command line arguments that help solve the problem. -mx allows you to set the maximum size of the memory allocation pool while -ms allows you to set the starting size.

For example:
java -ms50M -mx1000M ProgramThatNeedsLotsOfMemory

will execute ProgramThatNeedsLotsOfMemory with a starting memory allocation of 50M and let it grow up to 1GB. You can also use K to specify the memory size in kilobytes, but I’m not sure why that would be useful unless you are on a machine with very little memory.

After looking into the documentation a little more it appears that the new syntax for these commands is -Xms and -Xmx, so you’ll have to choose the one that works depending on your version of the JVM.

Unix/Linux Cut Command

The cut command in unix lets you specify which part of a line you want to echo. For example if
cat file.txt
produces something like:

12345678
23456789
34567890

Cut can also be used to specify particular columns in tab, space or other delimited data.

then you could pipe the file into the cut command to show only the 3rd character like this:


cat file.txt | cut -c 3
3
4
5

You can also specify ranges like this:

cat file.txt | cut -c 3-4,6-8
34678
45789
56890