Software Developer. Computer Geek. INTJ.

Category Code Snippets

All posts by date in TiddlyWiki

Create a tiddler with the following content to list posts by date and time in a table (latest first)…

Back-dating Journal entries in TiddlyWiki

AKA How to override the “created” date/time.

Reload AutoHotkey with a keyboard shortcut

This is part of my AutoHotkey script to allow me to quickly reload the script after making changes.

Coloured Tags in Nirvana (GTD App)

Gives tags in Nirvana a solid background colour instead of a small coloured dot that is difficult to see.

Arduino randomly fading multi-colour LED

This is based on lessons 3 (LED), 4 (RGB LED) and 5 (Buttons) of the Elegoo UNO Project Super Starter Kit. I set up a multi-colour LED to fade through various colours, and a button to toggle it on or…

Arduino Hello World in Morse Code

This is only marginally more advanced than the blinking light example in my first Arduino post, but perhaps a little more interesting! Again it uses the built-in LED, so no connections are required.

Fix bold titles & tags in new WorkFlowy

Fix bold styles in the new (Aug 2018) version of WorkFlowy. Titles aren’t forced to be bold #tags aren’t forced to be non-bold

Don’t grey out tags in WorkFlowy

This is a user style to make #Tags and @Tags be the same colour as the other text in WorkFlowy instead of greyed out.

Using Blade Outside Laravel

Using Jens Segers’ Blade package to render Blade templates in a standalone PHP application.

Provisioning a Windows 2016 VM on Azure with Terraform

A script that creates a Standard_D2_v3 VM (2 vCPU, 8 GiB RAM, 50GB SSD temporary storage, supports nested virtualisation) in the North Europe (Ireland) region.

Loading variables from .env files in Ansible

Ansible has various ways of looking up data from outside sources, including plain text password files, CSV files and INI files. But it doesn’t seem to have a lookup for .env files, as used in Laravel projects, also available for…

Peer review scheduler in Prolog

Continuing my exploration of Prolog, I decided to write a program to generate a schedule for peer reviews.

Getting started with SWI-Prolog

Today I decided to learn a bit about Prolog. Here is how to start using it…

Docker Reference

This week I have been learning about Docker… Here is what I’ve learned so far.

PHP CLI script that can also be run in a web browser

I had a command line (CLI) script written in PHP that I wanted to be able to run via the web, to save having to open a terminal and SSH connection each time.

Laravel Blade @ifSection() tag

This adds an @ifSection() Blade tag to Laravel that can be used to determine whether a particular @section() is defined.

Fade out completed items in WorkFlowy

Fades out completed items in WorkFlowy, until you hover over it or focus them, to make it easier to see the remaining list items yet still see your progress.

Find MySQL users with no privileges

This finds MySQL users with no global or database privileges.

Find MySQL users with access to databases that don’t exist (have been deleted)

Useful for finding users who had permission to access databases that have since been deleted…

Oxford Bus Company Wi-Fi Captive Portal Automatic Login

Automatically log into the Wi-Fi network on Oxford Bus Company buses.

HipChat (Y) and (N) shortcuts for thumbs up/down using AutoHotKey

HipChat uses “(thumbsup)” and “(thumbsdown)” instead of the easier to type “(Y)” and “(N)” of MSN Messenger, so I remapped them using AutoHotKey.

Display a list of a user’s Gists in WordPress

This code creates a shortcode, [gists], which displays a list of all Gists by a user, grouped into categories then listed alphabetically.

Find newly created/modified files in Linux

Find files created today or recently modified…

Replace URLs in the WordPress database when moving between servers

Run this to replace URLs in the database when moving a WordPress blog from one URL to another.

Fire “Ask Anna” on the FedEx website

This is a user style I wrote for a friend. It removes the “Ask Anna” box that appears in the corner of the FedEx website.

WorkFlowy Title Tweak

Remove “ – WorkFlowy” from the end of the tab title on WorkFlowy. Makes it cleaner and easier to bookmark.

Display starred pages as a list in WorkFlowy

Changes the WorkFlowy starred pages popup so it looks like a regular list, instead of trying to mimic the look of pages going across the screen, to make them easier to skim-read to find the one you’re looking for.

Move starred pages list to the top in WorkFlowy

Moves the WorkFlowy starred pages list to the top of the screen, reducing the distance the mouse has to travel from the button.

Fade out notes in WorkFlowy

Fades out the notes field in WorkFlowy until you hover over it or focus it, to make it easier to see the main list items.

List the number of open HTTP connections per IP in Linux

This was useful when fighting a DDoS attack on one of our web servers.

Script to download MySQL database & files from live to development server

This is a script I use on a lot of sites to copy the database (MySQL) and any uploaded files to the development site, and modify the database as required.

Upgrade phpMyAdmin via the command line

This script makes it easy to upgrade phpMyAdmin on one or multiple servers at the same time.

Bulk (batch) rename files in Linux

rename -v s/OLD/NEW/ FILENAMES

Write to standard output/error streams in PHP CLI

How to write to STDOUT and STDERR in PHP.

Recursively copy a directory, including symlink support, in PHP

function copy_dir($src, $dst)

Recursively delete a directory, including symlink support, in PHP

function delete_dir($dir)

Split WordPress theme functions.php into multiple files and autoload them

I use this to split my theme’s functions.php into multiple smaller files on particularly complex sites, and to autoload those files (instead of having to manually require each one).

Extract images from a .ico file (e.g. favicon.ico) on Linux

icotool -x -o . favicon.ico

Using Gravity Forms with WP-Types custom date fields

This is a filter to take Gravity Forms format dates (dd/mm/yyyy) and convert them to WP-Types format dates (integer).

Sort and filter WordPress posts query by a custom field

In this example the event start & end dates are entered as timestamps using WP-Types. It could also be modified for Advanced Custom Fields which uses strings.

Keyboard shortcuts to indent/outdent and format as code in WordPress TinyMCE

This allows you to indent lists/paragraphs in the TinyMCE WYSIWYG editor using Tab, and outdent using Shift+Tab. I wrote it because I write a lot of nested lists, it’s tedious using the keyboard to indent and outdent, and I couldn’t find any…

Insert a post into WordPress from an external script

With wp_insert_post() and wp_set_post_terms()…

Get HTTP redirect destination for a URL in PHP

Makes a HTTP request and read the Location header(s) to determine the redirect destination.

Display WordPress admin area dates in UK English (en_GB) format (day-month-year)

While entering several back-dated posts into a WordPress blog, I got annoyed at the date fields being in American month-day-year format and decided to fix it.

Hide blank icons in bookmarks toolbar in Firefox

Copied from this style and modified to also hide the folder icon and show an arrow instead. /* ==UserStyle== @name Hide blank icons in bookmarks toolbar in Firefox @namespace @version 1.0.0 @author Dave James Miller ( @homepageURL @license…

Resize an image on the fly with PHP and cache it (like Drupal’s ImageCache)

This script takes an image and resizes it to the given dimensions, then saves that version on the filesystem so Apache can serve it directly in the future.

Store WordPress post password cookies for the browser session only (instead of 10 days)

WordPress saves post password cookies for 10 days, and there is no setting or filter to change that, but you can use this code to replace the form action entirely.

Fully restart Ruby on Rails app under Phusion Passenger during Capistrano (cap) deploy

Most instructions for using Capistrano tell you how to make it restart Phusion Passenger by touching the restart.txt file, but this doesn’t immediately restart the app – instead the first person to try to use the application will cause it to be…

Zip a dynamically generated file in PHP

// Generate the contents of the file somehow $content = ‘…’; // Zip the file $zipFile = tempnam(sys_get_temp_dir(), ‘zipfile’); $zip = new ZipArchive; $zip->open($zipFile, ZipArchive::OVERWRITE); $zip->addFromString(‘sample.txt’, $content); $zip->close(); // Do something with the file (e.g. attach it to an email)…

Allow access by IP address with CanCan in Ruby on Rails

This is what I used to get CanCan to allow users on the local network to access parts of our intranet without having to log in.

© 2021 Dave James Miller — Powered by WordPress

Theme by Anders NorenUp ↑