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 / deploy.rb
Last active Oct 10, 2017
Download data from Ruby on Rails production database to development server using Replicate
View deploy.rb
# OVERVIEW:
# 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
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
davejamesmiller / BladeServiceProvider.php
Last active Oct 14, 2017
Laravel Blade @ifSection() tag
View BladeServiceProvider.php
<?php
namespace App\Providers;
use Blade;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
@davejamesmiller
davejamesmiller / download-live-site.sh
Last active Dec 25, 2017
Script to download MySQL database & files from live to development server
View download-live-site.sh
#!/bin/bash
#===============================================================================
# This is a template for 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.
#
# The script should be on the development server. The live site can either be on
# the same server, or a remote server connected via SSH.
#
@davejamesmiller
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
davejamesmiller / auto-activate-plugins.php
Last active Jan 8, 2019
Automatically enable plugins in new WordPress Multisite blogs
View auto-activate-plugins.php
<?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
davejamesmiller / blogs-menu.php
Last active Mar 14, 2019
List of all blogs in a WordPress Multisite network
View blogs-menu.php
<?php
// This code was used to generate a menu showing all blogs on a WordPress
// Multisite installation.
// projects_menu() was used in the template to show a dropdown menu on all the
// sites.
// The shortcode [bloglist] was used in the homepage of the main blog to link to
// all the other blogs.
@davejamesmiller
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
<?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
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 / 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
You can’t perform that action at this time.