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 / deploy.rb
Last active Oct 10, 2017
Download data from Ruby on Rails production database to development server using Replicate
View deploy.rb
# Replicate [1] is a Gem that lets you dump and load relational objects between
# Ruby/Ruby on Rails environments, e.g. dump data from your production database
# and load it in your development database.
# The examples given in the README [2] are of shell scripts being used to do
# this. I wanted to use a Capistrano task because it keeps everything related to
# the production site in one place (particularly the config).
davejamesmiller / deploy.rb
Last active Oct 10, 2017
Fully restart Ruby on Rails app under Phusion Passenger during Capistrano (cap) deploy
View deploy.rb
# Most instructions for using Capistrano tell you how to make it restart Phusion
# Passenger by 'touch'ing 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 restarted, so they will see a delay of at least a few seconds.
# This shows how to add a post-deploy task to 'ping' the server, to cause it to
# restart immediately.
# First, (optionally) add a '/ping' route to config/routes.rb that immediately
# returns a blank page. This prevents any non-essential work being done, such as
davejamesmiller / BladeServiceProvider.php
Last active Oct 14, 2017
Laravel Blade @ifSection() tag
View BladeServiceProvider.php
namespace App\Providers;
use Blade;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
* Bootstrap the application services.
davejamesmiller / deploy.rb
Last active Mar 9, 2018
Automatically push changes to Git repository before deploying with Capistrano (cap deploy)
View deploy.rb
# I use this Capistrano task so I don't have manually run 'git push' before 'cap
# deploy'. It includes some error checking to make sure I'm on the right branch
# (master) and haven't got any uncommitted changes.
# Simply add the code below to config/deploy.rb, then run 'cap deploy:push' to
# test it, and 'cap deploy' to deploy as usual.
namespace :deploy do
desc "Push local changes to Git repository"
task :push do
davejamesmiller / auto-activate-plugins.php
Last active Jan 8, 2019
Automatically enable plugins in new WordPress Multisite blogs
View auto-activate-plugins.php
// There are three options (that I know of) for automatically enabling a plugin
// in new sites.
// 1. Move the plugin from wp-content/plugins/ to wp-content/mu-plugins/ (MU =
// Must Use). But then it cannot be deactivated for any site.
// 2. Click "Network Activate" instead of "Activate" to enable it for all sites.
// I didn't want to use this though because I didn't want to affect existing
davejamesmiller / url-to-domain.php
Last active Mar 29, 2019
Get the domain name from a URL for display purposes in PHP
View url-to-domain.php
// This is PHP function to convert a user-supplied URL to just the domain name,
// which I use as the link text.
// Remember you still need to use htmlspecialchars() or similar to escape the
// result.
function url_to_domain($url)
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 / 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 / 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 Jun 14, 2019
Detect pipe/file input in Bash / shell script
# How to detect whether input is from keyboard, a file, or another process.
# Useful for writing a script that can read from standard input, or prompt the
# user for input if there is none.
# Source:
if readlink /proc/$$/fd/0 | grep -q "^pipe:"; then
# Pipe input (echo abc | myscript)
elif file $( readlink /proc/$$/fd/0 ) | grep -q "character special"; then
# Terminal input (keyboard)
You can’t perform that action at this time.