Obtain Base URL of Current PHP Script

This might look complicated due to the SSL checks for setting protocol…

$base_url = ((isset($_SERVER['HTTPS']) && in_array(strtolower($_SERVER['HTTPS']), ['on', '1'])) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTPS']) === 'https') || (isset($_SERVER['HTTP_X_FORWARDED_SSL']) && strtolower($_SERVER['HTTP_X_FORWARDED_SSL']) === 'on') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/';

If you don’t need the protocol checks…

Continue reading

How to Stop All QuickBooks Processes Still Running in the Background After the Desktop Application Has Been Closed

QuickBooks resource management in Windows has always been atrocious. Even if you don’t need an app or service, Intuit loads it, and doesn’t close said ancillary applications and services after you close QuickBooks. The only acceptable reasons are sharing company files over the network, or so an app reopens faster after closing.

Continue reading

MySQL ALTER TABLE ADD COLUMN IF NOT EXISTS

I had been looking for a one-line solution for adding columns to tables when they do not already exist. For the longest time I settled on using a temporary stored procedure, but this still required at least four lines to execute using the 3rd party system I am sometimes constrained within…

DROP PROCEDURE IF EXISTS `AddColumnIfNotExists`;
DELIMITER $$ CREATE PROCEDURE `AddColumnIfNotExists`() BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; ALTER TABLE `t1` ADD `c1` TEXT; END $$ DELIMITER ;
CALL `AddColumnIfNotExists`();
DROP PROCEDURE `AddColumnIfNotExists`;

While that works fine, I was still displeased with having to use a stored procedure to achieve the desirable result. So, I eventually came up with this beautiful one-liner…

Continue reading

C# Ignore DropDownButtonPressed for ToolStripButton Converted to ToolStripSplitButton

When you convert a ToolStripButton to a ToolStripSplitButton, the underlying event code is not automatically converted. So you may notice clicking the split button’s down-down arrow also triggers the button’s Click event.

You can either move the Click event code to the new ButtonClick event (preferred), or adjust the Click event to ignore the drop-down arrow.

Continue reading

C# Pass Click Event to MenuStrip or ToolStrip Control Without Form Focus

More often than not, I want the click event for menus (MenuStrip) and toolbars (ToolStrip) to trigger on the first click, even when the firm does not have focus. I figure if Windows is going to show the hover effects, the user expects the click to trigger without having to first focus focus on the form.

A work around is to use your own ToolStrip and let the mouse activation give the control the focus, which in turn will then let the button fire it’s click event:

LarsTechStackOverflow Answer
Continue reading

Two ways to have your C# application run during Windows start-up

The simplest method (in my opinion) relies on the Windows registry.

using Microsoft.Win32;

namespace WindowsStartupTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            checkBoxRegistry.Checked = (registryKey().GetValue(Application.ProductName) != null);

        }
        private RegistryKey registryKey()
        {
            return Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")!;
        }
        private void checkBoxRegistry_Click(object sender, EventArgs e)
        {
            if (checkBoxRegistry.Checked)
            {
                registryKey().SetValue(Application.ProductName, Application.ExecutablePath);
            }
            else
            {
                registryKey().DeleteValue(Application.ProductName, false);
            }
        }
    }
}

Another method is to add an application shortcut to the Windows Startup folder.

Continue reading

Convert Your Mac QuickBooks Company to a QuickBooks for Windows Backup (QBB) and Vice Versa

  1. Open your QuickBooks company as the admin on the Mac.
  2. Open the File menu, select Export, then To QuickBooks for Windows.
    • If prompted to Verify before backing up, do it.
  3. Choose a location for the new QBB file, then click Save.
  4. Confirm all remaining prompts.
  5. Copy the QBB file to a Windows PC.

How to Restore a QuickBooks Backup File (QBB) on Windows

Continue reading

Caps Lock Alert for Password Input Fields

<input type="password" id="password">
<span id="warning" style="display:none;color:#c00">[Caps Lock]</span>
<script>
document.getElementById("password").addEventListener("keyup", function(event) {
  document.getElementById("warning").style.display = (event.getModifierState("CapsLock")) ? "inline" : "none";
});
</script>