Installing PHPUnit On Windows With Out PEAR

This is a quick description of how I got PHPUnit working on Windows without installing PEAR

The PHPUnit documentation is a cryptic and sparse when describing how to install PHPUnit on windows.

I am assuming that PHP is already installed and working.

Steps:

  1. Download the latest version of PHPUnit (currently 3.4.9) from here http://pear.phpunit.de/get/
  2. Extract to somewhere (I put it in my PHP directory)
  3. Edit the phpunit.bat file. At the bottom of the file there are two lines:
    set PHPBIN="@php_bin@"
    %PHPBIN% "@bin_dir@\phpunit" %*
  4. Change them to something like this:
    set PHPBIN="C:\Program Files (x86)\PHP\php.exe"
    %PHPBIN% "C:\Program Files (x86)\PHP\phpunit.php" %*
  5. To test if PHPUnit is working run “phpunit --help” from a command  prompt (PHP directory needs to be set in the path environment variable).
Advertisements

Setting Return-Path in PHP

We have a system that needs to send automated emails. But we were having a problems where we were not getting bounce emails from invalid email addresses.

After half a day of digging it turns out the problem was that the Return-Path header was being set to the user that the web server runs as. Which was a non-existent email address.

To set the Return-Path in PHP on a unix environment use:
mail('nobody@example.com', 'the subject', 'the message', null, '-fwebmaster@example.com');

In windows envioronment use:
ini_set('sendmail_from', 'webmaster@example.com);

For more information see: http://www.php.net/manual/en/function.mail.php

Move Music Into Artist Folders

I like my music in artist folders so I created this little VB Script to move music albums into single folders.
It takes a folder full of albums in the format “Artist – Album” and creates a folder for each artist, then moves the Albums into that folder.

For example if you have a folder C:\Music and sub folders in the format “Artist – Album” like below:

C:\Music\Artist1 – Album1
C:\Music\Artist1 – Album2
C:\Music\Artist2 – Album1

It will turn it into:

C:\Music\Artist1\Artits1 – Album1
C:\Music\Artist1\Artist1 – Album2
C:\Music\Artits2\Artits2 – Album1

Just copy the below code into a text file, rename it something like “music mover.vbs” put it in your root music directory (C:\Music\ in my example) and run it. Your music should now be in folders by artist.

Script is:

Dim fso, folderObj, folders, outputFile, currentDir, newFolder, dashPos, folderName

Set fso = CreateObject("Scripting.FileSystemObject")
currentDir = fso.GetAbsolutePathName(".") + "\"

Set outputFile = fso.CreateTextFile(currentDir&"\FileList.txt", True) 'file for loging things
Set folderObj = fso.GetFolder(currentDir)

Set folders = folderObj.SubFolders

For each folderIdx In folders
	newFolder = ""
	dashPos = InStr(folderIdx.Name, "-")
	folderName = currentDir + folderIdx.Name

	if dashPos <> 0 then 'we found a dash in the folder name (asuming that there are no artists or albums with dashes in their names the format is Artist - Album)

		newFolder = currentDir + Trim(Left(folderIdx.Name, dashPos-1))

		if not fso.FolderExists(newFolder) then
			fso.CreateFolder(newFolder)
			outputFile.WriteLine("Created new folder (" + Trim(Left(folderIdx.Name, dashPos-1)) + ")")
		else
			outputFile.WriteLine("Folder already exists (" + Trim(Left(folderIdx.Name, dashPos-1)) + ")")
		End If		

		outputFile.WriteLine(" - Added (" + folderIdx.Name + ")")
		Call fso.MoveFolder(folderName, newFolder + "\\")

	End If
Next

outputFile.Close

If I feel like it I might write a script that does the opposite, takes Music\Artist\Artist – Album and moves them to Music\Artist – Album.

More Lotus Notes table problems

Sort of an addition to my previous post, Notes doesn’t like large tables being created with AppendTable().

You get this error “Illegal column width – check Left and Right margins”. The work around is to create the table with only one row and the desired columns and then use AddRow() to add up to 255 rows.

See the IBM technote for more infomation.

Hard limit on Lotus Notes rich text table rows

Some times Lotus Notes frustrates the hell out of me. Someone decided that it would be a good idea to put a hard limit (or at least a tiny limit) on the number of rows that a table can have

I’m not using composite applications introduced in Lotus Notes 8, I assume it handles this kind of thing a lot better. But the java client is to heavy weight and all our database (Applications) and they use the standard design elements anyway.

If you try and create a table with more than 255 rows you will get the error:

“Table can have only 255 rows”

List of Domino limits

Solution:
The solution is to basically keep creating new tables when you hit the row limit. The only problem is that it creates a gap between the tables which may mess up the layout a little.

Here is a simple function I wrote to break up an array into multiple tables if there are to many rows and add it to rich text field

rtField – the field you want to add the tables to
tableData – a 2D array that gets converted into a table (this holds the table data)
rows – the number of rows in the tableData array
cols – the number of columns in the tableData array

Sub CreateTable(rtField As NotesRichTextItem, tableData As Variant, rows As Integer, cols As Integer)
    numFullTablesToAdd% = 0
    numFullTablesToAdd% = Fix(rows/255)
    ‘add tables first
    For i%=1 To numFullTablesToAdd%
        Call rtField.AppendTable(255, cols) ‘ max row tables
    Next   
    Call rtField.AppendTable(rows Mod 255, cols) ‘ whats left
    Dim rtnav As NotesRichTextNavigator
    Set rtnav = rtField.CreateNavigator
    ‘Dim rtTable As NotesRichTextTable
    Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
    For r%=0 To rows-1
        For c%=0 To cols-1
            Call rtField.BeginInsert(rtnav)
            Call rtField.AppendText(tableData(r%, c%))
            Call rtField.EndInsert
            Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
        Next
    Next
End Sub

There maybe a way to instead create a table with HTML but I haven’t worked out out yet. Will update if I find a better solution