Skip to content

Instantly share code, notes, and snippets.

Mark Woods mmrwoods

  • London & Oxford
Block or report user

Report or block mmrwoods

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
View keybase.md

Keybase proof

I hereby claim:

  • I am mmrwoods on github.
  • I am mmrwoods (https://keybase.io/mmrwoods) on keybase.
  • I have a public key ASCzrDxWj3rVBEYaFP5PA0_jWGNQdhiYpwcJ8_d-9NcJowo

To claim this, I am signing this object:

@mmrwoods
mmrwoods / checkhost.sh
Last active Jan 15, 2018
Quick hack to check a remote host is accepting connections on a tcp port (useful when doing dangerous things, like kernel updates!)
View checkhost.sh
#!/bin/bash
if [ "$1" == "" ] || [ "$2" == "" ]; then
echo "usage: $0 [options] <host> <port>"
echo
echo "options:"
echo " -i <interval> Number of seconds between checks [default: 5]"
exit 1
fi
@mmrwoods
mmrwoods / check_apache.sh
Last active Aug 29, 2015
Quick hack to check apache is running and responding, and start/restart if not
View check_apache.sh
#!/bin/bash
PS_NAME=apache2
CHECK_URL=http://localhost/
MAX_TRIES=5
apache_running() {
ps -eo pid,comm | fgrep $PS_NAME > /dev/null 2>&1
}
@mmrwoods
mmrwoods / postgres_migration_utils.rb
Last active Aug 29, 2015
postgres_migration_utils.rb
View postgres_migration_utils.rb
module PostgreSQLMigrationUtils
# Changes the type of a string or text column to citext and recreates
# indexes on that column that follow the rails naming convention, such
# that the index is on the result of the lower(col) function.
#
# Note: The citext type changes comparisons on citext columns to be on
# lower(col), but does nothing about ensuring that indexes created on
# citext columns are automatically created on the result of lower(col).
def change_column_to_citext(table_name, column_name)
View run_on_hosts
#!/bin/bash
# Find hosts matching pattern in ssh_config and run command on each.
# As pattern is an argument to egrep, but is also injected into a string
# which is evaluated, you can hack the input to do weird useful things,
# like pass options to egrep or pipe the output through another command.
usage() {
echo "Usage: $0 [pattern] [command]"
}
View postgresql-maintenance.cron
#!/bin/bash
# Vacuum, analyze and re-index all non-template postgres databases
# Should be run as root to avoid any permissions issues
db_list_sql="SELECT datname FROM pg_database WHERE NOT datistemplate AND datallowconn ORDER BY datname"
for db in $(su - postgres -c "psql -At -c '$db_list_sql'"); do
su - postgres -c "vacuumdb --analyze --quiet $db"
su - postgres -c "PGOPTIONS='--client-min-messages=warning' reindexdb --quiet $db"
View postgresql-backup.cron
#!/bin/bash
# Create a clean SQL dump of each non-template postgres database
# Should be run as root to avoid any permissions issues
dest_dir=/var/local/backup/postgres
db_list_sql="SELECT datname FROM pg_database WHERE NOT datistemplate AND datallowconn ORDER BY datname"
for db in $(su - postgres -c "psql -At -c '$db_list_sql'"); do
View dumb_ass_backup.rb
#!/usr/bin/env ruby
# Dumb-ass backup - better than no backup!
#
# Run nightly and enjoy daily, weekly and monthly filesystem backups
#
# - default destination directory is /var/local/backup
# - latest, daily, weekly and monthly sub-directories are created
# - latest directory should only ever contain the latest backup
# - latest backup copied to daily, weekly and monthly directories as required
View download_my_code.rb
require 'active_support'
require 'hirb'
require 'debugger'
user = 'thickpaddy' # FIXME: get from argv
def send_request(url, content=nil)
curl_opts = ["--max-time 30", "--silent"]
if content
curl_opts << "--header 'Content-Type: application/json'"
@mmrwoods
mmrwoods / show_dependencies
Last active Jun 3, 2016
Hacky script to show bundled dependencies of rails app
View show_dependencies
#!/usr/bin/env ruby
require 'bundler'
require 'hirb'
require 'csv'
lock_file = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock"))
def url_for(spec)
case spec.source
You can’t perform that action at this time.