Quick fixes – Home

  • Moving Sent items in New Outlook for Mac changes sent date to now

    Setup: I’m moving some mail from several old Google Workspace accounts to new MS365 accounts. It’s not high enough volume to automate or ‘Migrate’ with tools, so I’m doing it manually in New Outlook for Mac, with both old and new accounts setup in the App.

    Problem: When I select some mail in an old account’s ‘Sent’ folder and ‘Move to…’ the ‘Sent’ folder on the new account, every item has it’s original sent date switched to now, i.e. the time the move was done.

    Fix: This seems to be a bug or idiosyncrasy of New Outlook (Man it’s got some big holes and this is one of them). If Outlook is switched to ‘Legacy Outlook’, the move works fine and the dates are preserved.

    Did this help? [Ratings]

  • Possible cause of “Template part has been deleted or is unavailable” error

    Problem: When adding a Block Theme template part (footer.html) while building our acompletely fresh Block Theme I got this error repeatedly. Couldn’t work out what I’d done wrong. Later that evening while seeing to a matter, it hit me…

    The Fix: I’d put the template part in the wrong directory! Theme templates need to go in ‘templates’ directory. Parts i.e. things called with:

    <!-- wp:template-part {"slug":"footer"} /-->

    need to go in the ‘parts’ directory.

    Was this any use? Nope, not helpful...Yep, more useful than not! (No Ratings Yet)
    Loading…

  • Find the size of a MySQL database from CLI

    Need: To run a single command in the MySQL console / CLI to show the size of a paricular database.

    Solution: This command, when logged in with a user that has permssions to read the information_schema table, substituting “the_database” with the name of the db you want to check (include the double quotes!)

    SELECT table_schema "the_database", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MiB" FROM information_schema.TABLES GROUP BY table_schema;

    Example result: 

    mysql> SELECT table_schema "db", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MiB" FROM information_schema.TABLES GROUP BY table_schema;
    +--------------------+-----------------------+
    | db                 | Data Base Size in MiB |
    +--------------------+-----------------------+
    | db                 |            5.53125000 |
    | information_schema |            0.18750000 |
    +--------------------+-----------------------+
    2 rows in set (0.01 sec)

    Please let me know if this was useful? Nope, not helpful...Yep, more useful than not! (No Ratings Yet)
    Loading…

  • Open a Folder or File in a new VS Code window on Mac OS

    Problem: When opening a new folder in VS Code (Mac OS), I want it to open a new VSCode window, and not add the folder to the already open window. I’m used to the Atom IDE behaviour from years back.

    Fix: There are two settings that help here:
    window.openFoldersInNewWindow controls whether a folder should be opened in the same window or a new one.

    window.openFilesInNewWindow does the same for Files, i.e. when you open just a single file.

    These settings can be found in the ‘Code > Preferences > Settings’ menu item. OR easier still, with the shortcut  ⌘, (or ‘Command’ plus ‘comma’ keys, if you can’t see the shortcut to the left here)

    Once in Settings, start typing window.openF and you should see both options there. Set one or both to on for the desired behaviour. Can’t remember if you have to restart VS Code or not after changing this. Try it!

    Please let me know if this works for you Nope, not helpful...Yep, more useful than not! (No Ratings Yet)
    Loading…

  • Test a Composer package from a local version / copy

    Problem: I need to test a small change to a Composer package that’s on GitHub / Packagist, but I don’t want (yet) to request the change from the maintainer or fork my own version on Packagist or whatever… I literally just want to change one digit in a version number requirement.

    Not that it’s particularly relevant, but the Package in question is a Volume storage driver for Craft CMS that makes use of Fortrabbit’s Object Storage.

    Solution: Composer has a repositories feature which allows us to add Repositories other than the default Packagist.org one by adding a new block to the project’s composer.json. There are quite a lot of different sorts of repositories that can be setup, but I’m interested in the path one. This option will allow me to stick a package’s contents almost anywhere on my local machine, and path to it. Example: (more…)

  • Splitting many files into numbered folders with leading zeros

    Problem: I had a few thousand files in a directory and needed them to be in a series of numbered folders – specifically with leading zeros – with no more than 100 files in each. Don’t ask why… just some weird old batch program that needs files presented that way. Obviously manually creating directories and moving the files was going to take a while. Also, this needed to be done via a cron job, so I needed something scriptable.

    Solution: Thankfully all sorts of magic can be done on the *nix command line, and we have access to very useful formatting functions like printf and for loops.

    The following command achieves what I needed:

    i=0; for f in *; do d=dirname_$(printf %03d $((i/100+1))); mkdir -p $d; mv "$f" $d; let i++; done

    (more…)

  • stream_socket_client(): unable to connect to smtp.mailtrap.io:2525 (Permission denied) – CentOS 7 / Mailtrap / Laravel

    Problem:
    After rebuilding a CentOS 7 system with a Laravel app on it, every time the app attempted to mail a notification using MailTrap, the above error got fired.

    Solution:
    SELinux. Again. It’s always flipping SE LINUX! The SELinux policy can block in and outbound ports and all sorts of things. It’s a git. A clever useful git.

    Running `sudo sealert -a /var/log/audit/audit.log` showed the problem. If sealert isn’t possible, then tailing the audit log with `sudo tail -f /var/log/audit/audit.log` goes some way to finding the problem.

    In this case a solution (being Linux there are probably 74 equally effective and largely contested solutions) was to allow Apache to use port 2525 like so:

    sudo semanage port -a -t http_port_t -p tcp 2525

    Any good? If this helped please let me know: Nope, not helpful...Yep, more useful than not! (No Ratings Yet)
    Loading…

  • Fixing ReflectionException: Class scope does not exist in file when setting up Laravel Passport Scopes

    Problem: I’m retro-fitting ‘scopes’ to an existing Laravel Passport API to allow some different levels of client access. After adding the available scopes with Passport::tokensCan, and default scopes with Passport::setDefaultScope, and attempting to specify a scope on a route like so:

    Passport::setDefaultScope([
        'other-access'
    ]);
    
    Passport::tokensCan([
        'write-access' => 'Read-write access',
        'read-access' => 'Read-only access',
        'other-access' => 'Other access'
    ]);
    
    Route::get('endpoint/count', 'API\EndpointController@count')->middleware(['auth:api', 'scope:read-access']);

    And an attempt to query the route gives this error:

    ReflectionException: Class scope does not exist in file /path/to/webroot/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 790

    Solution: READ THE DOCS. Again, I didn’t read the docs FULLY. In order to use token scopes, the docs say…

    To get started, add the following middleware to the $routeMiddleware property of your app/Http/Kernel.php file:

    'scopes' => \Laravel\Passport\Http\Middleware\CheckScopes::class,
    'scope' => \Laravel\Passport\Http\Middleware\CheckForAnyScope::class,
    

    🤦🏻‍♂️ 🤦🏻‍♂️ 🤦🏻‍♂️ 🤦🏻‍♂️ 🤦🏻‍♂️ 🤦🏻‍♂️

  • 135 Film DX recoding solution

    135 Film DX recoding solution

    Problem: I own a Pentax P30t (and P30n since writing) Film SLR which only allows ISO to be set via DX encoding on the film canister. If no DX code is present, the ISO defaults to 100.

    Solution: There are all sorts of existing solutions involving tin-foil, stickers or scratching the canister but I wanted a more permanent re-usable solution and came up with this ‘shim’ idea.

    The method is as follows, with simple explanation in the captions where needed: (more…)

  • Adding sections or headings to WordPress Menus – Making use of the walker_nav_menu_start_el filter

    The WordPress menu builder makes it easy to add nested menu item links to a named menu, and display it in pre-defined theme location. However, as of writing in Jan 2019, there’s not an easy or built-in way to add menu sections or section headers. Here’s my solution:

    The Design

    Example visual to be recreated as a WordPress menu
    Example visual to be recreated as a WordPress menu

    The adjacent image shows the design that I’ve been asked to translate to a WordPress native menu. The orange items are page links. The white items are section headers and should not be active in any way. They are simply visual cues to aid navigation.

    The Challenge

    ‘Out of the box’ WordPress doesn’t provide a place for menu section headers like ‘Services’ and ‘Products’ to be entered. It is possible to add them based on a menu item’s class or ID using the CSS ‘content‘ property, or an absolutely positioned image, but this is tacky and hard-coded, so site owners and admins can’t easily change the menu section headers without a developer type person or some Additional CSS hackery.

    We need to find a way of adding section headers that uses the WordPress menu builder and remains editable. (more…)