WWW posts

web development, my site, server, and the world wide web in general

MySQL: DELETE with sub-query on same table

I had an issue with a MySQL query containing a sub-query recently where it worked fine when done as a SELECT query, but gave an error when switching it to a DELETE query. The error given was something like ‘You can’t specify target table “items” for update in FROM clause’. The sub-query was referencing the same table as the main query, which apparently can’t be done directly in MySQL because the table will be modified during deletion. But there is a sort of a hack I found in this StackOverflow answer, among others, to force it to create a temp table and allow it to work.

Continue reading post "MySQL: DELETE with sub-query on same table"

Swap file for composer out of memory problems

PHP’s defacto package manager, composer, has long required large amounts of memory to do updates for larger projects, often more than servers or virtual machines have. The script will die with an out of memory error, or more recently, the simple message “Killed”, and do no work in these situations. The normal procedure is to develop locally, deploy local lock file (composer.lock) to the server, and run composer install instead of update. But I’ve recently moved to doing most of my development in VMs, so I have had to work around this problem to get things installed or updated. A swap file is the solution for Linux machines provided in the official docs and expanded in a StackOverflow answer.

Continue reading post "Swap file for composer out of memory problems"

Unprivileged Homebrew install, 2021 edition

On my new MacBook, I’ve been isolating responsibilities into separate user accounts. This includes an unprivileged “manager” account for installing most global third-party software, and a few development accounts for different purposes. I use Homebrew to install some dev related software, but my old Homebrew setup didn’t work with this conceptually, nor with the more locked down privileges of newer Mac OS versions. I didn’t want to give Homebrew or its packages admin or root privileges, so I have adapted Homebrew’s untar anywhere method to install a globally available Homebrew using the unprivileged manager account, only requiring a privileged account briefly. I’ve also used untar anywhere for a per-account Homebrew install to allow each dev account to have custom versions of any desired packages, with no privileged account required.

Continue reading post "Unprivileged Homebrew install, 2021 edition"

jQuery AJAX and multipart form handling

I recently had need to submit a web form with file fields via AJAX. The application uses jQuery and was already submitting forms just fine without file fields using the .serialize() method to pass data to a jQuery.ajax() call. That didn’t seem to handle the file fields, though. Searching the internet, I found a solution using the browser built in FormData object.

Continue reading post "jQuery AJAX and multipart form handling"

Firefox: Weird rendering with high contrast mode

I figured out why Firefox 91+ seemed to break some CSS rendering for me (as I blogged about a few weeks back): high contrast mode. I’ve used the accessibility setting “Increase Contrast” on Mac OS for some time to make it easier to see some interface elements. Apparently, via Firefox 91 release notes, “Firefox now automatically enables High Contrast Mode when ‘Increase Contrast’ is checked on MacOS”.

Continue reading post "Firefox: Weird rendering with high contrast mode"

Purchase: New laptop, MacBook Air

I’ve made another new laptop purchase in the past couple months: I bought a refurbished 2020 MacBook Air from Apple.com. It has a 10th gen i3 Intel processor, 8GB of RAM, and 256GB of storage. I bought it to replace my struggling 11 year old MacBook. I bought a Lenovo Yoga 7i, but was struggling to get comfortable with it for my web development work. I made the call to get the Mac so I could directly migrate both my work computer user and my personal computer users, with the plan to use it for development and use the Yoga for other stuff.

Continue reading post "Purchase: New laptop, MacBook Air"

Purchase: New laptop, Lenovo Yoga 7i

Last month, I finally bought a new laptop with plans to replace my aging 2009 Macbook as my primary computer. It is a Lenovo Yoga 7i, purchased from MicroCenter. It is a switch from Mac, which has been my primary OS for pretty much since I’ve been using computers, but it has touch screen and I hope to switch to the open world of Linux.

Continue reading post "Purchase: New laptop, Lenovo Yoga 7i"

Sorting with `FIELD()` function in Doctrine

I recently needed to sort query results to match the order of IDs passed to it for use in a WHERE … IN() clause. In MySQL, this can be done using the FIELD() function in the ORDERY BY clause. For Doctrine, which doesn’t have the FIELD() function and doesn’t allow functions in the ORDER BY clause, there’s a little more work needed to make use of it.

Continue reading post "Sorting with `FIELD()` function in Doctrine"