Skip to content

Instantly share code, notes, and snippets.

@robwilkerson
robwilkerson / date-time-selector.php
Created March 30, 2012 14:33
Creating a hybrid date/time selector in CakePHP
# app/views/elements/form/input_datetime.ctp
# This is a reusable bit to display the date/time inputs.
<?php $model = isset( $model ) ? $model : $this->model ?>
<div class="input datetime<?php echo isset( $required ) && $required ? ' required' : '' ?>">
<?php echo $this->Form->input( $model . '.' . $field . '.date' , array( 'type' => 'text', 'label' => $label, 'value' => !empty( $value ) ? date( DATE_FORMAT_LONG, strtotime( $value ) ) : '', 'div' => false, 'class' => 'date' ) ) ?>
<?php echo $this->Form->input( $model . '.' . $field, array( 'type' => 'time', 'label' => false, 'div' => false, 'class' => 'time', 'empty' => true ) ) ?>
</div>
# app/views/<wherever>/<whatever.ctp>
@robwilkerson
robwilkerson / externalip.sh
Created May 14, 2013 14:32
Display the external IP address of a Unix server.
curl http://ipecho.net/plain; echo
@robwilkerson
robwilkerson / install-compass.sh
Created May 22, 2013 15:11
Scripted install of Compass. Tested in a Vagrant shell provisioner for a Ubuntu 12.04 VM.
echo -n "Installing compass (http://compass-style.org)..."
apt-get update -qq -y
apt-get install ruby1.9.1 -qq -y > /dev/null
gem install rubygems-update > /dev/null
update_rubygems > /dev/null
gem install compass > /dev/null
echo "complete."
@robwilkerson
robwilkerson / install-dnsmasq.sh
Created May 22, 2013 15:12
Installs DNSMasq. Tested in a Vagrant shell provisioner for a Ubuntu 12.04 VM.
# Installing dnsmasq so that loopback communication using the site URL doesn't fail.
if [ ! -e '/etc/dnsmasq.conf' ]; then
echo -n "Installing and configuring DNSMasq..."
apt-get install dnsmasq -qq -y > /dev/null 2>&1
cat >> /etc/dnsmasq.conf << "EOF"
address=/.umassmemorial.org/127.0.0.1
listen-address=127.0.0.1
EOF
sed -i -r -e 's/^(\s*)#(\s*prepend domain-name-servers\s+.*)$/\1\2/' /etc/dhcp/dhclient.conf
service dnsmasq restart > /dev/null
@robwilkerson
robwilkerson / configure-memcached-php5.sh
Created May 22, 2013 15:15
Configures Memcached for use with PHP.
if grep -Fxq 'memcache.hash_strategy="consistent"' /etc/php5/conf.d/memcache.ini; then
echo "Memcache configuration updates have already been made."
else
echo -n "Updating the memcached config..."
echo 'memcache.hash_strategy="consistent"' >> /etc/php5/conf.d/memcache.ini
echo "complete."
fi
@robwilkerson
robwilkerson / update-nginx-conf.sh
Created May 22, 2013 15:21
Enables gzip and adjusts for a Virtualbox bug w/ sendfile.
# Tweak the Nginx conf. sendfile is broken on Virtualbox.
echo -n "Setting the Nginx configuration..."
sed -i -r -e 's/sendfile\s*on/sendfile off/g' /etc/nginx/nginx.conf
sed -i -r -e 's/^(\s*)#\s*gzip on(.*)$/\1gzip on\2/' /etc/nginx/nginx.conf
sed -i -r -e 's/^(\s*)#\s*gzip_types(.*)$/\1gzip_types\2/' /etc/nginx/nginx.conf
@robwilkerson
robwilkerson / generate-self-signed-cert.sh
Last active December 17, 2015 14:59
Generates a self-signed SSL certificate. #bash #ssl
# Generate a self-signed certificate
echo -n "Generating a self-signed SSL cert..."
openssl req -new -x509 -days 365 -subj "/C=US/ST=MD/L=Baltimore/O=Rob Wilkerson Consulting, LLC/CN=*.MYDOMAIN.COM" -nodes -out /etc/ssl/certs/wildcard-cert.pem -keyout /etc/ssl/private/wildcard-cert.key
echo "complete."
@robwilkerson
robwilkerson / install-varnish.sh
Created June 19, 2013 13:15
Installs Varnish. Tested in a Vagrant shell provisioner for a Ubuntu 12.04 VM.
# Install Varnish
if [ -z `command -v varnishd` ]; then
echo -n "Installing varnish (http://www.varnish-cache.org)..."
# curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add - > /dev/null
# echo "deb http://repo.varnish-cache.org/ubuntu/ precise varnish-3.0" | sudo tee -a /etc/apt/sources.list > /dev/null
apt-get install varnish -qq -y > /dev/null
echo "complete."
else
echo "Varnish is aleady installed."
fi
@robwilkerson
robwilkerson / install-db.sh
Created June 25, 2013 16:24
Creates and populates a local (Vagrant) database from a remote production source database.
echo "--> Creating a fresh database..."
mysql -uroot --execute "DROP DATABASE IF EXISTS <db_name>; CREATE DATABASE <db_name> CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
echo "<-- Complete."
echo "--> Configuring SSH access to production resources for `id -un`..."
mkdir ~/.ssh
cp /vagrant/.ssh/<name>.pem ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
SSH_OPTIONS=''
@robwilkerson
robwilkerson / vagrant-set-hostname.sh
Created August 1, 2013 13:01
Sets and persists a custom hostname on an Ubuntu server.
# Set a helpful hostname as a convenient reference.
echo "project-name" > /etc/hostname
echo "127.0.0.1 project-name" >> /etc/hosts
hostname project-name