Autowiring of Non-Shared Services

With the Symfony framework, most objects are supposed to live in the Service Container. This facilitates an “autowire” of all the class constructors, plus a great deal of magic from the debug tools.

Most objects are supposed to be “shared” as well. This is Symfony’s substitute for the singleton pattern. It helps prevent duplication of “services”. However, services don’t always fit this pattern.

One of the Symfony configuration tutorials divides object classes into only two types. In that limited example, objects would have to be “services that do work” or “models that hold data”. Again, services don’t always fit into this pattern.

Continue reading Autowiring of Non-Shared Services

Smart Host Config for Haraka v3.0

This is the 4th post in a series about setting up an outbound SMTP server with DKIM signing and smart host forwarding. Here you will learn how to configure an existing Haraka server to forward all outgoing mail to another SMTP server. In this update, I will explain a simplified built-in method that is available thanks to bug fixes published after I wrote the old post for v2.8.

Continue reading Smart Host Config for Haraka v3.0

RDP Certificate Error

Here’s a vague error message from the Windows 10 Remote Desktop Connection client:

The connection has been terminated because an unexpected server authentication certificate was received from the remote computer.

This was popping up in a message box on a specific client during every connection attempt. The message box can be closed and there are no other options. The server’s certificate chain was correct. Rebooting the server did not help.

In this case, the Certification Authority had been renewed but not yet imported to this client’s Trusted Root store.

The solution was to type “Manage computer certificates” at the client’s Start menu and then import the missing CA certificate. After that, the client connected normally.

MS Access Crashes on “SELECT ?” Query

I found another way to force MS Access to crash to desktop, and it’s shockingly simple.

Sub SQLTest()
    Dim Query As ADODB.Command
    Set Query = New ADODB.Command
    With Query
        .ActiveConnection = CurrentProject.Connection
        .CommandText = "SELECT ?"
        .Parameters.Append .CreateParameter(, adChar, , 1, "a")
        .Execute
    End With
End Sub
Continue reading MS Access Crashes on “SELECT ?” Query

Smart Host Config for Haraka

Update: This post was written for Haraka v2.8. Please see also Smart Host Config for Haraka v3.0

This is the 2nd post in a series about setting up an outbound SMTP server with DKIM signing and smart host forwarding. Here you will learn how to configure an existing Haraka server to forward all outgoing mail to another SMTP server.

Part of the credit for this solution goes to Matt’s Hacking Blog which got me pointed in the right direction after a morning of futile config file editing. It just needed some updates, tweaks, and longer explanations of how to make it work.

The core trick here is a custom plugin. I already had an SMTP service account with DNS Made Easy, so I used that as an example for my forward smart host. I created a file named /etc/haraka/plugins/dnsmadeeasy.js

Continue reading Smart Host Config for Haraka

Installing Haraka in Ubuntu 20.04

This is the first post in a series about setting up an in-house outbound SMTP server with DKIM signing and smart host forwarding. Here you will find the steps to install the Haraka SMTP server, configure it to accept outbound mail, and run it as a system service.

Requirement: Node.js

You will need the npm command to install Haraka, and I found it was not available by default. To read the official instructions for this step, reference this page:

Node.js Binary Distributions

This is how I did it:

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -

apt install nodejs

The Haraka Application

With the prerequisites met, it’s as simple as this:

npm install -g Haraka
Continue reading Installing Haraka in Ubuntu 20.04

MS Access Crashes on TreeView.Nodes.Clear

I found a specific situation where MS Access always crashes to desktop.  Here are the ingredients:

  1. A bound Form with a Microsoft TreeView Control, version 6.0.
  2. Form’s “Allow Additions” property set to “No”
  3. TreeView populated using the Form_Current() event.
  4. Prior to populating the TreeView, calling .Nodes.Clear on the TreeView object.
  5. To set up the crash, filter the form to an empty recordset.
  6. Click on the Home ribbon and the Toggle Filter button.

Download Testcase File: treeview-testcase.accdb

Workaround

In the Form_Current() event, add a DoEvents command immediately before Nodes.Clear.

Set MyTree = Me.TreeView0.Object
DoEvents
MyTree.Nodes.Clear

InStr Performance for VBA

I solved a mysterious bottleneck last night while working with large string values in MS Access. My VBA code was reading a file to a string variable, checking several values near the beginning of the string, and then manipulating and saving the string to the database.

Oddly, one of the slowest parts of my code was the several InStr calls that were only checking the first few hundred bytes of the string. I could alleviate part of the problem by copying the beginning of my file to a shorter string value, but in so doing I also noticed unexpected results from the InStr return value.

Continue reading InStr Performance for VBA

Forcing PHP to Sort Like MySQL

If you ever have to do a case-insensitive array sort in PHP, you will eventually notice that the results don’t match the MySQL latin1_swedish_ci collation. They just aren’t the same. The difference comes from a set of six characters that fall between the upper-case and lower-case alpha characters of ISO-8859-1.

Specifically, [ \ ] ^ _ ` are the troublemakers. A simple example would involve sorting the phrases “Hello” and “[Hello]”. In MySQL, “Hello” comes first. In PHP, “Hello” comes last.

If this is driving you crazy, all you will need to do is trick PHP into using an upper-case sort instead of a lower-case sort.

$strings = ['hello', '[Hello]', 'Hello'];
usort( $strings, 'mysql_simulator' );
var_dump( $strings );

function mysql_simulator( $a, $b ) {
return strcmp( strtoupper( $a ), strtoupper( $b ) );
}

I hope this will save you some of the research in solving that pesky little difference.

Cannot Use Dynamic Class Name

It seems I’ve discovered a new kind of PHP error that isn’t documented anywhere on the web yet. Here is a simple example and explanation to help correct your code.

class MyClass {}
$obj = new MyClass;
$test1 = MyClass::class;    // Right
$test2 = get_class( $obj ); // Right
$test3 = $obj::class;       // Wrong

That last line in my code sample produces the following error in PHP 7.4.

Fatal error: Cannot use ::class with dynamic class name in […][…] on line 5

This is the PHP way of saying that you have to switch to the get_class() function when retrieving the fully qualified class name of an object.

Note: An existing RFC proposes to change this behavior in PHP 8, so this particular error message might not exist in some future versions.