Instantly share code, notes, and snippets.

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).
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
View BladeServiceProvider.php
<?php
namespace App\Providers;
use Blade;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
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.
#
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
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
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)
{
View detect-input-type.sh
# 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: http://www.linuxquestions.org/questions/linux-software-2/bash-scripting-pipe-input-to-script-vs.-1-570945/
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)
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
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