Skip to content

Instantly share code, notes, and snippets.

@mmrwoods
mmrwoods / formtastic_cancel_action.rb
Last active December 19, 2015 00:09
Make formtastic's cancel action return the user to the original referrer
# Make formtastic's cancel action return the user to the original referrer
#
# By default, the cancel action in formtastic always goes to the previous
# page, so hitting cancel after validation failures returns the user to
# the form, not the original referring page. The code below modifies the
# cancel action such that it by default returns to the original referrer.
# It does so by simply keeping track of the referrer in a hidden field.
#
# See also https://github.com/justinfrench/formtastic/issues/780
@mmrwoods
mmrwoods / pg_search_document_metadata.rb
Last active December 18, 2015 17:49
Adds metadata to pgsearch documents, allowing search results to be rendered with just the document data.
module PgSearch
module ClassMethods
def rebuild_pg_search_documents
self.find_each {|record| record.update_pg_search_document}
end
end
class Document
before_validation do
self.meta = generate_meta
@mmrwoods
mmrwoods / bootstrap_centos.sh
Last active September 2, 2021 20:19
Bootstrap configuration for a new RHEL or CentOS VM (set hostname, basic firewall rules, etc.)
#!/bin/bash
# Boostrap a new CentOS VM (also works with RHEL!)
# Has been used on CentOS 5.10, 6.2, 6.3, 6.4 and 6.5
# Based on https://gist.github.com/thickpaddy/1759284
# TODO: set ssh port
if test $(whoami) != "root" ; then
echo "Error: $0 must be run as root, exiting..."
@mmrwoods
mmrwoods / new_linode_centos6.markdown
Created February 7, 2012 11:39
Make me a new CentOS linode

Make me a new CentOS linode

Notes:

  • Instructions written for CentOS 6.3
  • Change, me, myhost, myip etc. to your username, hostname, ip address and so on.
  • Run all commands as root unless otherwise directed.
  • You might want to look at mounting /var and /home on separate partitions.
  • I've just allowed all members of the wheel group to operate as root. This is the height of laziness and highlights the fact that I'm just a developer that's stolen a sysadmin's
@mmrwoods
mmrwoods / MySQL_maintenance.pl
Created January 30, 2012 11:54
Dan Buettner's MySQL maintenance script, modified
#!/usr/bin/perl -w
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# MySQL_maintenance.pl
#
# By Dan Buettner - drbuettner-at-gmail.com
# 12 Nov 2005
#
@mmrwoods
mmrwoods / mysql
Created January 20, 2012 13:49
MySQL maintenance crontab file
# note: MySQL_maintenance.pl can be obtained from http://danbuettner.net/mysql-tools/
# check, optimise and repair MySQL databases (extended check on Sunday, quick every other day)
15 3 * * 0 root nice -n 19 /usr/local/sbin/MySQL_maintenance.pl --check-type=extended --optimize --repair --exclude-dbs=information_schema
15 3 * * 1-6 root nice -n 19 /usr/local/sbin/MySQL_maintenance.pl --check-type=quick --optimize --repair --exclude-dbs=information_schema > /dev/null
# dump all mysql databases once every 24 hours
15 4 * * * root nice -n 19 mysqldump --opt --all-databases --allow-keywords | gzip -9 > /var/local/backup/mysql/mysql_all.sql.gz
@mmrwoods
mmrwoods / postgres
Created January 20, 2012 13:47
Postgres maintenance crontab file
# dump all databases once every 24 hours
45 4 * * * root nice -n 19 su - postgres -c "pg_dumpall --clean" | gzip -9 > /var/local/backup/postgres/postgres_all.sql.gz
# vacuum all databases every night (full vacuum on Sunday night, lazy vacuum every other night)
45 3 * * 0 root nice -n 19 su - postgres -c "vacuumdb --all --full --analyze"
45 3 * * 1-6 root nice -n 19 su - postgres -c "vacuumdb --all --analyze --quiet"
# re-index all databases once a week
0 3 * * 0 root nice -n 19 su - postgres -c 'psql -t -c "select datname from pg_database order by datname;" | xargs -n 1 -I"{}" -- psql -U postgres {} -c "reindex database {};"'
@mmrwoods
mmrwoods / generate version number from git
Created January 9, 2012 12:57
Generate semantic versioning compatible number from git tags
git describe --tags --match "v*" 2> /dev/null | sed s/-/+build./ | sed s/-/./
@mmrwoods
mmrwoods / delete git tag from remote repo
Created January 9, 2012 12:43
Delete git tag from remote repo
git tag -d 12345
git push origin :refs/tags/12345
@mmrwoods
mmrwoods / BritishWithHash.keylayout
Created September 7, 2011 13:28
British OSX keyboard layout, with § (section sign) key remapped to output hash
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--
* save to ~/Library/Keyboard Layouts/BritishWithHash.keylayout
* enable as input source within keyboard preferences
* select as input source in menu bar
NOTE: although this works in Lion, it messes up the press and hold for alternative characters feature.
-->
<!-- Fri, 24 Feb 2006 Generated from KCHR: "British" -->
<!--Last edited by Ukelele version 2.1.7 on 2011-09-07 at 14:20 (BST)-->