Sublime Text – exclude / include search folders using regex

I recently switched from Eclipse to Sublime Text 3 and am very happy I did. It is fast to load, lots of extensions, active community.

One thing that I couldnt figure out was how to exclude folders from the search within files (project). I mostly code in JS (Sencha Ext/Touch) and ColdFusion and keep my JSDuck API Docs etc in the same project folder as my source files. That means that when I search within files in my project I end up with matches from the docs folder, which is not what I want. Also, and probably more importantly, when using Sencha Cmd to build production apps there is a /build folder which I do not want to search in since that is the “compiled” output.

There is a forum post about using -/my/path/to/folderToExclude (ie prefix the path with a – ). http://sublimetext.userecho.com/topic/97052-find-in-files-exclude-directories/

For Windows (which I use) you need backslashes instead of forward slashes and the syntax becomes odd (IMJ). At the end of that post was an example of using regex in the Where input box. This was a revelation.

So, to exclude the various folders within my project that I never want to search in, my where box looks like:

-*/docs/*,-*/build/*,-*/ext/*,-*/sass/*

which means search in all folders and subfolders in the project except these ones. Brilliant!

By the same method you can be specific about which folder to include. eg:

*/app/* will find a match in all “app” folders (and sub folders of course) eg myappname/app and myappname/build/app. However I want the first one but not the second one (build). So:

*/myappname/app/*

does the trick, only searching in folder (and sub folders of) myappname/app.

And, of course you can combine exclude and include:

*/myappname/app/*,-*/controller/*

ie only search in myappname/app/ but NOT in myappname/app/controller (or any sub folder with ‘controller’ in the path)

Finally, dont forget that the Where box is cached and previous contents are available by clicking the down arrow at the end of the input box. So, you can easily switch between saved search strings.

All very nifty!

ColdDuck – beautiful documentation for ColdFusion CFCs

Background

I have been a consumer of the Sencha ExtJS documentation for a while now and wanted to be able to use JSDuck for my ColdFusion CFCs. But how? While I am a JSDuck novice I figured that trying to make JSDuck produce documentation directly from ColdFusion CFCs was likely to result in tears (mine!). So, after some thought, I came up with another strategy that users of other programming languages might want to consider.

My CF to JSDuck strategy

Mark Mandel’s ColdDoc can be extended to produce different kinds of output by utilising a “strategy” cfc. It comes with one that produces the JavaDoc style HTML format. Strategies utilise the CF ComponentMetaData. So, I made my own strategy that takes ColdFusion CFCs and makes a pseudo-app in JavaScript code that is annotated using JSDuck formatting. Of course it auto-documents functions etc and picks up the ‘hint’ attributes where it finds them and uses all that to produce the raw material for rich documentation. It also works with CF ORM CFCs (although this part could be made even richer than it is at present).

Video overview

Here is a really quick video to give an overview of what ColdDuck does: http://www.screencast.com/t/5p4JqbvNR

Documentation

The ColdDuck package includes the documentation. You can also view it here http://murrah.com.au/coldduck/docs

Sample output

Here is the sample SuperBlog app documented with ColdDoc in JavaDoc format

Here is the sample SuperBlog app documented with ColdDuck in JSDuck format

A full implementation of JSDuck style documentation is here http://docs.sencha.com/extjs/4.1.3/

Almost all of that JSDuck functionality is available for you to use for your ColdFusion projects. I say “almost” because there are a few JSDuck features that are JavaScript specific (eg view JS class source).

Installation

Get it at GitHub https://github.com/murrah/ColdDuck

I hope you find this useful and fun. Please leave your comments below.

Thanks,
Murray

Solved: The CFML compiler encountered an unexpected java.lang.StringIndexOutOfBoundsException exception.

Just a quick one. I received the following error while working a a Coldfusion entity cfc.

The CFML compiler encountered an unexpected java.lang.StringIndexOutOfBoundsException exception.

The line it pointed to as the error condition had no errors in it.

It turned out the the problem was that just before the error line I had an empty comment (an artifact of testing) like /**/ ie no space between the comments “braces”. After changing it to /* */ the error is not thrown. Just in case someone else encounters this message.

Outlook 2007 – take care when switching from Exchange Server!

Our company recently switched it’s email server from Exchange Server. Not thinking, I deleted the Exchange item: Tools / Account Settings / Email / Remove. Not a good move!

Normal Outlook data files are PST files (e.g. outlook.pst). Exchange Server files are .OST files. Microsoft intentionally do not provide a way to convert an OST file to a PST file! Oh shit! There are commercial solutions and other solutions that may or may not work to convert the file.

After the panic subsided, I realised that I still had the company’s Exchange Server setup on my old laptop’s Outlook. So, I copied the OST file across to that laptop (so I had the emails that were present at the time I stopped using Exchange), fired up Outlook which told me the server was AWOL (which didnt matter), all my email and folders were there! Phew.

I then Archived ALL the folders (File / Archive, etc which copies the data to a PST file – e.g. archive.pst). I then copied the archive.pst file back to my new laptop, started Outlook and voila, all the old email was available.

So, the moral is, if you are switching from Exchange and not migrating your old email to a new mail system, ARCHIVE all your old email BEFORE you disconnect the Exchange data file from Outlook!

 

Solved: Outlook 2007 – email stuck in Outbox after switching from Exchange Server to Gmail IMAP – error 0x80040201

This took a long time to work out. As usual, someone had walked the path before me but it took a while to find that solution amongst all the false leads (in my case).

Our company had recently switched it’s email from Exchange Server to Gmail. (Yes, they are aware of the security issues. Anyway …). Not liking the GMail interface etc I wanted to continue using Outlook for my mail client and using GMail’s IMAP to do that. After setting that up (lots of posts on the net on how to do that), I noticed the following problem.

Important note: See this post BEFORE you delete your old Outlook Exchange file. If you do it the wrong way you will lose all your email!

The problem: When I created a new email to some of my contacts, or replied to an email from one of those same contacts, the email stayed in the Outbox of my default PST file. Sometimes it threw the error 0x80040201. Nothing I did would cause Outlook to send the email. Other email addresses worked fine! Very weird. Eventually I discovered the post below that explained that the problem was due to the Outlook.nk2 file that contains the data for the auto-complete functionality of Outlook. That file remembers whether the address is an Exchange Server address or an SMTP address. And guess what? All the addresses I had problems with had Exchange settings.

So, see the LAST item on this post: http://www.pcreview.co.uk/forums/getting-error-0x80040201-t1872774.html which explains a couple of fixes.

Alternatively, download this: http://www.nirsoft.net/utils/outlook_nk2_edit.html and delete all the email items with an account type of EX (as opposed to SMTP) and follow the instructions. You will then need to type the full email address the next time you send to that person and it will then remember the correct settings. Some addresses had both EX and SMTP entries so deleting the EX entries allowed the SMTP entries to correctly auto-correct.

I hope this saves someone the hours it took for me to find the solution.

NB: there is still a problem with Outlook that appears to be a bug. To get the email to actually send, you must click Send/Receive / Send ALL. I haven’t found a way for it to send automatically but at least I can send email with a couple of extra button clicks!

Now, I wonder how well Thunderbird’s IMAP works?

Cheers,

Murray

Using AlivePDF to print from AIR Javascript via ActionScript3 – part 1

See also Part 2 of this article.

As has been blogged in many places, printing from AIR is very limited and problematic. It seemed to me that a way around the lack of printing support would be to have the ability to create PDF files client-side, as opposed to sending all the data to be printed to the server then getting a PDF back again. Knowing that it was possible to invoke ActionScript classes from HTML/Javascript AIR apps, eg this post by Ray Camden and using that post as a start, I began exploring the possibilities.

This post covers what I found along the way. In summary:

  1. It is possible to create PDF files completely client-side from Javascript AIR apps via ActionsScript. A “proof of concept” is at the end of this post.
  2. You can use the free Flex SDK to develop the SWF file you need to invoke the required ActionScript classes.
  3. You can set up Eclipse to do that (ie you dont need FlexBuilder or be restricted to command line compiling)
  4. There are lots of other AS libraries out there that can be used using the techniques discussed in this post.

Until I started this process I had never really looked at ActionScript so the following is very much from the perspective of a newbie!

Basic AS info

First, read Ray’s post as a starting point.

Download the Flex 4 SDK from here. Unzip it somewhere (in my case D:\flex_sdk_4.1).

The AS library you need in your AIR app is contained in a SWF file as you can see in Ray’s post.  There are 2 ways to compile your SWF file. As Ray says, the Adobe docs suggest using the acompc command line compiler, which outputs a SWC / Zip file that you can extract the SWF from. A simpler way is to use the amxmlc command line compiler instead which outputs directly to the SWF file. Both of these compilers are in the Flex SDK /bin folder.

Ray’s example assumes you are creating an AS package from scratch. What I wanted to do was to use an existing library and extend it. Before I discuss the command line compiler settings, I need to digress into talking about the libraries I found.

AS PDF options

I found two AS libraries that create PDF files client-side – AlivePDF and purePDF. The latter interested me particularly because it is a port of iText java library which I was already familiar with. However, as discussed in my forum post here, I was unable to get purePDF to work  so I switched to AlivePDF which was more successful. It is highly likely that my problems with purePDF we of my own making. However I was unable to get any help to work out what, if anything, I was doing wrong.

Extending an AS library

The basic method is that you create a new AS package that imports the classes that you need from the library. The AS class library is in a SWC file (ie is compiled) and the Flex / AS compiler imports the classes that you need from that file.

So, the easiest way I found to do this (before I found out how to use Eclipse) is as follows. I include this info here to help explain the process.

What I did was to take the AS code from this example and converted it into the following package.

package {
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;

    import org.alivepdf.pdf.PDF;
    import org.alivepdf.saving.Method;
    import org.alivepdf.fonts. * ;
    import org.alivepdf.pages.Page;
    import org.alivepdf.display.Display;
    import org.alivepdf.layout. * ;

    import mx.utils.UIDUtil;

    import flash.filesystem.FileStream;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;

    import flash.utils.ByteArray;

    // You need to extend the Flex class Sprite for AIR to be able to run the code
    public class aliveDemo extends Sprite {
        private
        var pdf: PDF;
        private
        var file: File;

        // Removed the image to simplify the testing
        //[Embed( source="/assets/o-png24.png", mimeType="application/octet-stream" )]
        //private var pngBytes:Class;
        public function aliveDemo() {}

        public function generate(): String {
            var pdf: PDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
            pdf.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE);

            var newPage: Page = new Page(Orientation.PORTRAIT, Unit.MM, Size.A4);
            pdf.addPage(newPage);

            // The following line turned out not to work as the API had changed since the original example was posted
            // pdf.setFont(FontFamily.ARIAL , Style.NORMAL, 12);
            // The correct way to do it now is:
            var myCoreFont: IFont = new CoreFont(FontFamily.HELVETICA);
            pdf.setFont(myCoreFont, 20);

            pdf.addText("This is a sample text", 5, 15);
            pdf.drawCircle(25, 35, 15);

            pdf.addPage();
            pdf.writeText(12, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nPraesent vel lectus lorem. Phasellus convallis, tortor a venenatis mattis, erat mi euismod tellus, in fermentum sapien nibh sit amet urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent tellus libero, lacinia ac egestas eget, interdum quis purus. Donec ut nisl metus, sit amet viverra turpis. Mauris ultrices dapibus lacus non ultrices. Cras elementum luctus mauris, vitae eleifend diam accumsan ut. Aliquam erat volutpat. Suspendisse placerat nibh in libero tincidunt a elementum mi vehicula. Donec lobortis magna vel nibh mollis tempor. Maecenas et elit nunc. Nam non auctor orci. Aliquam vel velit vel mi adipiscing semper in ac orci. Vestibulum commodo sem eget tortor lobortis semper. Ut sit amet sapien non velit rutrum egestas sollicitudin in elit. Fusce laoreet leo a sem mattis iaculis");

            // Removed this image for testing
            // pdf.addImageStream( new pngBytes() as ByteArray );
            // Save to file
            var fs: FileStream = new FileStream();
            file = new File("C:/CFusionMX7/wwwroot/Sites/TestAS/aliveDemo.pdf"); // Set your own path here!

            fs.open(file, FileMode.WRITE);
            var bytes: ByteArray = pdf.save(Method.LOCAL);
            fs.writeBytes(bytes);
            fs.close();

            return "End of generate";
        }

    }
}

I saved this directly to the Flex SDK /bin folder as AliveDemo.as (remember I was in quick and dirty test mode at this stage).

Then, to compile it:

  1. Create a folder in the /bin folder called alivepdflib
  2. Download the AlivePDF package (AlivePDF 0.1.5 RC.zip) and extract it
  3. Copy the AlivePDF.swc file from \AlivePDF 0.1.5 RC\Sources\bin into the alivepdflib folder created in step 1
  4. From the command line in the Flex SDK /bin folder, execute amxmlc -library-path+=alivepdflib aliveDemo.as

What that does is to create a file called aliveDemo.swf in the \bin folder by linking whatever SWC files are found in the alivepdflib folder and importing those classes into my aliveDemo.as class.

Then, I created an AIR app in Ecplise and set the HTML as follows:

<html>
    
    <head>
        <title>
            Test alivePDF
        </title>
        <script type="text/javascript" src="lib/air/AIRAliases.js"></script>
        <!--- Drop the created SWF file in the /lib folder --->
        <script src="lib/aliveDemo.swf" type="application/x-shockwave-flash"></script>
        <script>
            // Instantiate the class
            var ASlib = new window.runtime.aliveDemo();
            // Call the generate method
            var result = ASlib.generate();
            // Display the message to show we completed OK
            air.trace(result)
            // The aliveDemo.pdf will be located where ever you saved it to in aliveDemo.as
        </script>
    </head>
    
    <body>
    </body>

</html>

I copied the aliveDemo.swf file into the /bin folder in my AIR app, then ran the app and hey presto! a pdf file!!

The next step was to make a javascript wrapper so I could actually create the PDF on demand. Before that though, I set up the Flex SDK in Eclipse.

Setting up Flex 4 SDK in Eclipse

Using this very useful post as a basis, I made the following adjustments for the AIR environment:

  1. I did not bother creating the application.mxml file because the amxmlc command line compiler is actually a batch file that appends the correct xml data for compiling for AIR.
  2. In the Eclipse builder configuration section, I used the following settings instead of the ones in the post:
    1. Location= D:\flex_sdk_4.1\bin\amxmlc.bat (ie use YOUR path to the Flex SDK)
    2. Working directory=${workspace_loc:/JSPDF} (browse to YOUR project folder, mine was called JSPDF)
    3. Arguments= -library-path+=libs src/alivePDFWrapper.as -output C:/CFusionMX7/wwwroot/Sites/TestAS/lib/alivePDFWrapper.swf (set the path of the -output parameter to YOUR AIR project so that the SWF file is saved there for you)
    4. I didnt set the suggested Build Options check boxes since I didnt want the compiler to run automatically. To build, you highlight the .as file you need to compile and use CTRL+B (in windows)
  3. Copy the AlivePDF.swc file into the /libs folder in your project
  4. Copy the alivePDFWrapper.as file from Part 2 of this post to the /src folder of your project

The javascript wrapper

While it is possible to call the ActionScript methods directly, class instatiation gets tricky because the AS classes are “data types” that Javascript cant know about. My solution is to create an AS class that acts as a wrapper exposing the required methods but using data types that Javascript can handle. Since this wrapper and it’s associated JS class is the “solution” (well, so far anyway) to my problem of creating PDF files from Javascript, I have posted this section separately for those who dont care about all the above background. See Part 2

Using AlivePDF to print from AIR Javascript via ActionScript3 – part 2

For the background to this post, and how to use the following code, see Part 1

In this section I will describe the “solution” I found to the problem of the lack of adequate printing capability in AIR apps. My solution is to use ActionScript to create a PDF on the fly on the client-side. In this case, I am creating it from Javascript since I develop HTML/Javascript apps (using the EXTJS library). This solution does NOT require EXTJS or any other JS library.

I found two AS libraries that create PDF files client-side – AlivePDF and purePDF. The latter interested me particularly becuase it is a port of iText java library which I was already familiar with. However, as discussed in my forum post here, I was unable to get purePDF to work  so I switched to AlivePDF which was more successful. It is highly likely that my problems with purePDF we of my own making. However I was unable to get any help to work out what, if anything, I was doing wrong.

Now, this is really the start of the solution and very much a work in progress. I would value feedback about the overall approach and architecture I am proposing. Since I really wanted to use purePDF instead of AlivePDF, I elected to make the JS class as a layer so that it would be easier to create a version for purePDF if I ever get it to work!

So, here is the “proof of concept” source code.

First, the ActionScript class that exposes Javascript-friendly methods. Compile this as per Part 1 of this article.

package {

    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;

    import org.alivepdf.pdf.PDF;
    import org.alivepdf.saving.Method;
    import org.alivepdf.fonts.* ;
    import org.alivepdf.pages.Page;
    import org.alivepdf.display.Display;
    import org.alivepdf.layout.* ;
    import org.alivepdf.links.* ;

    import mx.utils.UIDUtil;

    import flash.filesystem.FileStream;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;

    import flash.utils.ByteArray;

    public class alivePDFWrapper extends Sprite {
        private
        var pdf: PDF;
        private
        var file: File;

        public function alivePDFWrapper() {}

        // The translate methods convert the integers passed from the javascript to
        // whatever correct data types AlivePDF uses
        private function translateSize(size: int): Size {
            var s: Size = Size.A4;
            switch (size) {
            case 0:
                s = Size.A3;
                break;
            case 1:
                s = Size.A4;
                break;
            case 2:
                s = Size.A5;
                break;
            case 3:
                s = Size.LEGAL;
                break;
            case 4:
                s = Size.LETTER;
                break;
            case 5:
                s = Size.TABLOID;
                break;
            }
            return s;
        }

        private function translateOrientation(orientation: int): String {
            var o: String = Orientation.PORTRAIT;
            switch (orientation) {
            case 0:
                o = Orientation.PORTRAIT;
                break;
            case 1:
                o = Orientation.LANDSCAPE;
                break;
            }
            return o;
        }

        private function translateUnit(unit: int): String {
            var u: String = Unit.MM;
            switch (unit) {
            case 0:
                u = Unit.MM;
                break;
            case 1:
                u = Unit.CM;
                break;
            case 2:
                u = Unit.INCHES;
                break;
            case 3:
                u = Unit.POINT;
                break;
            }
            return u;
        }

        private function translateDisplayZoom(dzoom: int): String {
            var dz: String = Display.FULL_PAGE;
            switch (dzoom) {
            case 0:
                dz = Display.DEFAULT;
                break;
            case 1:
                dz = Display.FULL_PAGE;
                break;
            case 2:
                dz = Display.FULL_WIDTH;
                break;
            case 3:
                dz = Display.REAL;
                break;
            }
            return dz;
        }

        private function translateDisplayLayout(dlayout: int): String {
            var dl: String = Layout.SINGLE_PAGE;
            switch (dlayout) {
            case 0:
                dl = Layout.SINGLE_PAGE;
                break;
            case 1:
                dl = Layout.ONE_COLUMN;
                break;
            case 2:
                dl = Layout.TWO_COLUMN_LEFT;
                break;
            case 3:
                dl = Layout.TWO_COLUMN_RIGHT;
                break;
            }
            return dl;
        }

        public function newPDF(size: int, orientation: int, unit: int): void {
            var s: Size = translateSize(size);
            var o: String = translateOrientation(orientation);
            var u: String = translateUnit(unit);

            pdf = new PDF(o, u, s);

            //var myCoreFont:IFont = new CoreFont ( FontFamily.HELVETICA_BOLD );
            var myCoreFont: IFont = new CoreFont(FontFamily.HELVETICA);
            pdf.setFont(myCoreFont, 12);

        }

        public function setDisplayMode(displayZoom: int, displayLayout: int): void {
            var dz: String = translateDisplayZoom(displayZoom);
            var dl: String = translateDisplayLayout(displayLayout);

            pdf.setDisplayMode(dz, dl);
        }

        public function newPage(size: int, orientation: int,unit: int): void {
            var s: Size = translateSize(size);
            var o: String = translateOrientation(orientation);
            var u: String = translateUnit(unit);
            var newPage: Page = new Page(o, u, s);
            pdf.addPage(newPage);
        }

        public function addPage(): void {
            pdf.addPage();
        }

        public function writeText(lineHeight: Number, text: String, link: ILink = null): void {
            pdf.writeText(lineHeight, text, link);
        }

        public function saveToFileAIR(fname: String): void {
            // Save to file for AIR
            var fs: FileStream = new FileStream();
            file = new File(fname);
            fs.open(file, FileMode.WRITE);
            var bytes: ByteArray = pdf.save(Method.LOCAL);
            fs.writeBytes(bytes);
            fs.close();
        }

    }
}

The Javascript interface (so far). Save this to /js folder in your AIR app.

function jsPDF() {
    // Define constants
    this.size = {
        A3: 0,
        A4: 1,
        A5: 2,
        LEGAL: 3,
        LETTER: 4,
        TABLOID: 5
    }
    this.unit = {
        MM: 0,
        CM: 1,
        INCHES: 2,
        POINT: 3
    }
    this.orientation = {
        PORTRAIT: 0,
        LANDSCAPE: 1
    }
    this.displayZoom = {
        DEFAULT: 0,
        FULL_PAGE: 1,
        FULL_WIDTH: 2,
        REAL: 3
    }
    this.displayLayout = {
        SINGLE_PAGE: 0,
        ONE_COLUMN: 1,
        TWO_COLUMN_LEFT: 2,
        TWO_COLUMN_RIGHT: 3
    }

    // Load the ActionScript Library (ie alivePDF + wrapper class)
    this.ASlib = new window.runtime.alivePDFWrapper();

    // Create a new PDF instance
    this.newPDF = function (size, orientation, unit) {
        this.ASlib.newPDF(size, orientation, unit);
    }
    // Set the display mode for the PDF when displayed in the reader
    this.setDisplayMode = function (displayZoom, displayLayout) {
        this.ASlib.setDisplayMode(displayZoom, displayLayout);
    }
    // Create a new page and add it to the pdf document
    this.newPage = function (size, orientation, unit) {
        this.ASlib.newPage(size, orientation, unit);
    }

    this.addPage = function () {
        this.ASlib.addPage();
    }

    this.writeText = function (lineHeight, text, link) {
        this.ASlib.writeText(lineHeight, text, link);
    }

    this.saveToFileAIR = function (fname) {
        this.ASlib.saveToFileAIR(fname);
    }
}

The AIR app:

<html>
    
    <head>
        <title>
            Test alivePDF
        </title>
        <script type="text/javascript" src="lib/air/AIRAliases.js"></script>
        <script src="lib/alivePDFWrapper.swf" type="application/x-shockwave-flash"></script>
        <script src="js/jspdf.js"></script>

        <script>

            var mypdf = new jsPDF();

            mypdf.newPDF(mypdf.size.A4, mypdf.orientation.PORTRAIT, mypdf.unit.MM);

            //mypdf.setDisplayMode(mypdf.displayZoom.FULL_PAGE,mypdf.displayLayout.SINGLE_PAGE);
            mypdf.setDisplayMode(mypdf.displayZoom.FULL_PAGE, mypdf.displayLayout.TWO_COLUMN_LEFT);

            mypdf.newPage(mypdf.size.A4, mypdf.orientation.LANDSCAPE, mypdf.unit.MM);

            mypdf.writeText(10, "Just one line on the first page!");

            mypdf.newPage(mypdf.size.A5, mypdf.orientation.PORTRAIT, mypdf.unit.MM);

            mypdf.writeText(10, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\nPraesent vel lectus lorem. Phasellus convallis, tortor a venenatis mattis, erat mi euismod tellus, in fermentum sapien nibh sit amet urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent tellus libero, lacinia ac egestas eget, interdum quis purus. Donec ut nisl metus, sit amet viverra turpis. Mauris ultrices dapibus lacus non ultrices. Cras elementum luctus mauris, vitae eleifend diam accumsan ut. Aliquam erat volutpat. Suspendisse placerat nibh in libero tincidunt a elementum mi vehicula. Donec lobortis magna vel nibh mollis tempor. Maecenas et elit nunc. Nam non auctor orci. Aliquam vel velit vel mi adipiscing semper in ac orci. Vestibulum commodo sem eget tortor lobortis semper. Ut sit amet sapien non velit rutrum egestas sollicitudin in elit. Fusce laoreet leo a sem mattis iaculis");

            mypdf.saveToFileAIR("C:/CFusionMX7/wwwroot/Sites/TestAS/test2.pdf"); // Set YOUR path here

        </script>
    </head>
    
    <body>
    </body>

</html>

I will continue to add functionality and test the AS and JS classes above. I will update the code above as I do. I am very interested to see if others find this idea has potential.

500 Null errors with POIutility – java.lang.OutOfMemoryError

I use Ben Nadel’s great POIUtility custom tags to create Excel spreadsheets in Coldfusion MX 7. I have two applications that run on a shared server. Occassionally, the spreadsheet generation stops with the dreaded 500 Null error and I can finally shed some light on the problem. I can often rerun the same generation process with the same data and sometimes it works, sometimes not. Frustratingly, I could not get it to fail on my local development machine until today – when I threw a much larger dataset at it and finally it crashed with the 500 Null error.

So, digging into my exception.log file  I found what I had suspected was probably happenning on the shared server but couldnt prove  – java.lang.OutOfMemoryError. My service provider said they couldnt see any errors in the log files which wasnt helping my debug efforts!

The final spreadsheet is 1,491 kb on the drive and is 187 columns x 380 rows = 71,060 cells.

I set up some tests on my local development machine and using the same dataset, adjusted the JVM settings and restarted CF each time to work out which setting was the problem. Here are the results:

JVM Heap size Mb MaxPermSize Mb Worked?
512 64 No
750 64 No
750 512 No
925 64 Yes
925 512 Yes
1024 64 Yes
1024 128 Yes
1024 512 Yes

So, it looks like the heap size is the critical setting.

Using CreateObject("java","java.lang.Runtime").getRuntime() and maxMemory = runtime.maxMemory() it looks like the server setting is probably 512Mb.

Interestingly, I also used the java runtime.freeMemory() in the cell.cfm custom tag (using cflog) whenever a new cell object was created to monitor the memory useage and even when the 500 Null errors occurred the memory always seemed to be at least approx 28 Mb and when the last log entry was written each time there was substantially more than that! I guess I was expecting the freeMemory to fall to something close to zero. My guess is that the garbage collection or some other process must have been grabbing some memory?

Now, I just need to convince my service provider to increase their settings. Or, find another service provider!

I hope this helps others with a similar problem.

Cheers,
Murray

A tale of two reel mowers

Yes, that’s reel not real!

Having only a small area of lawn I didn’t want to buy a power mower of any kind – petrol or electric. A reel mower is the kind that gets its energy from me pushing it. It is a great feeling to be able to get it out of the shed with one hand, push it quietly around and feel it slicing the grass (rather than bludgeoning it!). But I am getting ahead of myself here …

I went off to the hardware store and the only reel mower they had was a Talon brand. After I used it a few times, the gear inside the wheel broke – crappy casting. The store happily exchanged it. I wasnt so happy since all that metal and plastic probably ended up in landfill. Maybe they recycled it but I doubt it.

Other things that I didn’t like:

  1. It is really hard to adjust the cutters. A reel mower acts like a shear to slice the grass and for it to work properly you need to be able to adjust it so that the stationary bar and the rotating “knives” come very close together as it rotates.
  2. Small people (eg 12 year old’s) can’t use it because the handles are at their chest height so when they push it the handles just go up into the air instead of the energy going into moving the mower along.
  3. It is slow to adjust the cutting height. Normally you would have it at a set height so that wouldn’t be important. However, when I took it to cut someone else’s grass (which was very long and tough) I needed to do it in two passes. It was annoying to have to unscrew bits simply to make it cut higher.

Then, a miracle occurred!

While out for an early morning walk someone had left a Flymo brand reel mower (model H33) on the footpath with a one word sign on it – FREE! So, why not me, I thought? It looked like it was working and sure enough it did! And it is a dream after the other one!

Good points (I haven’t found any bad ones so far):

  1. Cutter adjustment is by a spring-loaded “wing nut” – done accurately in seconds.
  2. The handles go very low so small people can use it.
  3. Height adjustment is also done in seconds.
  4. The gearing is better than the Talon so the reel spins faster and easier.

Brilliant! I have just come in after a peaceful, quiet, CO2-free easy mowing session where all I could hear was the gentle whirr of the grass being sliced to size. I just love things that are designed properly!

I hope this encourages someone to try a reel mower and not to buy the Talon brand – it’s rubbish!

Time for a beer to celebrate!

CF UDF countArbitraryDaysExcluding

My countArbitraryDaysExcluding UDF has been released on CFLIB.org. You can find it here:

http://www.cflib.org/udf/countArbitraryDaysExcluding

See the comments there. But basically, count all the days in a date range (eg all Mondays) but exclude certain dates (eg for public holidays). These exclusions may be specific dates or patterns ( eg YYYY-1-1 ) – New Years Day in any year so you dont need to update your code once a pattern is defined.