Skip to content

Instantly share code, notes, and snippets.

Dave James Miller davejamesmiller

Block or report user

Report or block davejamesmiller

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
davejamesmiller / create-new-file.ahk
Last active Apr 29, 2019 — forked from aubricus/create-new-file.ahk
Create a new file with Ctrl+Alt+N keyboard shortcut in Windows Explorer with AutoHotKey
View create-new-file.ahk
; This is part of my AutoHotKey [1] script. When you are in Windows Explorer it
; allows you to press Ctrl+Alt+N and type a filename, and that file is created
; in the current directory and opened in the appropriate editor (usually
; [gVim]( in my case, but it will use whatever program is
; associated with the file in Windows Explorer).
; This is much easier than the alternative that I have been using until now:
; Right click > New > Text file, delete default filename and extension (which
; isn't highlighted in Windows 7), type the filename, press enter twice.
; (Particularly for creating dot files like ".htaccess".)
davejamesmiller /
Last active Mar 30, 2019
Use sudo to re-launch a Python script as root
# This is how I ensure a Python script is launched as root, and automatically
# call 'sudo' to re-launch it as root if not.
# I found it useful to check the parameters are valid *before* re-launching as
# root, so I don’t have to enter the sudo password if there is a problem with
# the parameters, or I just want the help message.
import os
import sys
davejamesmiller /
Last active Dec 4, 2019
Bash General-Purpose Yes/No Prompt Function ("ask")
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
local prompt default reply
if [ "${2:-}" = "Y" ]; then
davejamesmiller / wp-config.php
Last active Nov 10, 2019
Set WordPress site URL in the config file instead of the database
View wp-config.php
// WordPress stores the site URL in the database by default (which I have never
// understood), and it's a pain to have to type out the UPDATE SQL or search in
// phpMyAdmin to change it. This is a simple way to put the URL into
// wp-config.php instead.
// Note that you will still need to update any URLs that appear in the content,
// especially when you copy a database from a development site to production:
davejamesmiller / paste-current-date.ahk
Last active Apr 3, 2019
Paste the current date into any program using AutoHotKey
View paste-current-date.ahk
; This is part of my AutoHotkey [1] script that pastes the current date into any
; program when I press Ctrl+Alt+Shift+D.
; See the FormatTime reference [2] for other date/time formats.
; [1]:
; [2]:
^!+d:: ; When you press Ctrl+Alt+Shift+D
Clip0 = %ClipBoardAll% ; Store current clipboard in Clip0
davejamesmiller / paste-as-plain-text.ahk
Last active Nov 26, 2019
Paste clipboard contents as plain text with AutoHotKey
View paste-as-plain-text.ahk
; This is part of my AutoHotkey [1] script that pastes the contents of the
; clipboard as plain text when I press Ctrl+Alt+Shift+V.
; [1]:
; Ctrl+Alt+Shift+V
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to plain text
davejamesmiller / sleep.ahk
Last active Dec 7, 2019
Sleep/suspend/hibernate computer with a keyboard shortcut using AutoHotKey
View sleep.ahk
; This is part of my AutoHotkey [1] script that puts my computer to sleep when I
; press Win+F12.
; I chose that keyboard shortcut because it's very similar to the Fn+F12
; keyboard shortcut on my laptop.
; I don't have my PC set to require a password to resume, so I also have a
; second version (Win+Shift+F12) in case I want to lock the PC first.
; [1]:
davejamesmiller / monitor-off.ahk
Last active Nov 22, 2019
Turn monitor off with a keyboard shortcut with AutoHotKey
View monitor-off.ahk
; This is part of my AutoHotkey [1] script that turns off my monitor when I
; press Win+\.
; It also turns the screensaver on at the same time, so that Windows Live
; Messenger (and any other programs) know I am away.
; I don't have a password on my screensaver, so there is a second version
; (Win+Shift+\) that locks the PC as well.
; Note: Sometimes the monitor comes back on after a second and I have to
davejamesmiller / run-program.ahk
Last active Nov 7, 2019
Run a program with a keyboard shortcut with AutoHotKey
View run-program.ahk
; This is a simple and pretty generic example of an AutoHotkey script to run a
; program when you press a keyboard shortcut. Add as many of these as you want
; to a .ahk file, and set that to be run at startup.
; See the Hotkeys reference [1] for details of the modifiers and keys available.
; [1]:
; Win+Alt+G - Open Gmail in Chrome
davejamesmiller /
Last active Nov 6, 2019
HTML to PDF conversion in PHP using wkhtmltopdf (and optionally Smarty)

Recently I was asked to generate PDF invoices for an online shop. I looked at various PHP PDF generators, but wasn't particularly impressed with any of them.

Then I found (via Stack Overflow) a command-line HTML-to-PDF convertor called wkhtmltopdf, which uses WebKit (the same layout engine as Safari and Google Chrome) and therefore is very accurate.

There is a class for PHP integration on the Wiki, but I found it overly complicated and it uses temp files which aren't necessary. This is the code I wrote instead.

I used Smarty for generating the HTML for the PDF, but you can use any template engine, or pure PHP if you prefer.

Note: I originally tried to install wkhtmltopdf from source, but it's much easier to use the static binary instead.

You can’t perform that action at this time.