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
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](http://www.vim.org/) 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
davejamesmiller / sudo-relaunch.py
Last active Mar 30, 2019
Use sudo to re-launch a Python script as root
View sudo-relaunch.py
# 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
davejamesmiller / ask.sh
Last active Aug 7, 2019
Bash General-Purpose Yes/No Prompt Function ("ask")
View ask.sh
# 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() {
# https://gist.github.com/davejamesmiller/1965569
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
@davejamesmiller
davejamesmiller / wp-config.php
Last active Jul 31, 2019
Set WordPress site URL in the config file instead of the database
View wp-config.php
<?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:
// https://gist.github.com/davejamesmiller/a8733a3fbb17e0ff0fb5
@davejamesmiller
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]: http://www.autohotkey.com/
; [2]: http://www.autohotkey.com/docs/commands/FormatTime.htm
^!+d:: ; When you press Ctrl+Alt+Shift+D
Clip0 = %ClipBoardAll% ; Store current clipboard in Clip0
@davejamesmiller
davejamesmiller / paste-as-plain-text.ahk
Last active Jun 20, 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]: http://www.autohotkey.com/
; Ctrl+Alt+Shift+V
^!+v::
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to plain text
@davejamesmiller
davejamesmiller / sleep.ahk
Last active Aug 11, 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]: http://www.autohotkey.com/
@davejamesmiller
davejamesmiller / monitor-off.ahk
Last active Aug 11, 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
davejamesmiller / run-program.ahk
Last active Aug 8, 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]: http://www.autohotkey.com/docs/Hotkeys.htm
; Win+Alt+G - Open Gmail in Chrome
@davejamesmiller
davejamesmiller / README.md
Last active Jul 31, 2019
HTML to PDF conversion in PHP using wkhtmltopdf (and optionally Smarty)
View README.md

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.