Skip to content

Instantly share code, notes, and snippets.

class WorkingTwelveHourFormat < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A(?>(?>1[0-2]|0[1-9]):[0-5][0-9] pm|(?>1[01]|0[0-9]):[0-5][0-9] am)\z/
record.errors[attribute] << (options[:message] || "is not a valid working twelve hour format")
end
end
end
@mengqing
mengqing / chef-solo-on-ubuntu.sh
Last active December 17, 2015 21:49
Bash script to bootstrap chef solo using RVM on an Ubuntu server
DEFAULT_RUBY_VERSION="2.0.0-p195"
sudo apt-get -y install curl git-core bzip2 build-essential zlib1g-dev libssl-dev autoconf
if [ -x /usr/local/rvm/bin/rvm ]; then
echo "RVM Found..nothing to do";
else
echo "Installing RVM";
curl -L https://get.rvm.io | bash -s -- --autolibs=read-fail;
fi
@mengqing
mengqing / mage-dbdump.sh
Created May 7, 2013 11:35
Magento database dump
#!/bin/bash
IGNORE_TABLES=( core_url_rewrite dataflow_batch_export dataflow_batch_import log_customer log_quote log_summary log_summary_type log_url log_url_info log_visitor log_visitor_info log_visitor_online report_viewed_product_index report_compared_product_index report_event index_event enterprise_logging_event_changes core_cache core_cache_tag enterprise_customer_sales_flat_quote enterprise_customer_sales_flat_quote_address sales_flat_quote sales_flat_quote_address sales_flat_quote_shipping_rate )
CONFIG_FILE="./app/etc/local.xml"
IGNORE_STRING=""
TMP_FILE="./var/.tmp.local.xml"
if [ ! -f "$CONFIG_FILE" ]; then
echo "$CONFIG_FILE does not exist"
exit