This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Importing | |
module HumanAttributeNameWriters | |
def self.included(base) | |
base.new # Force activerecord to initialize attributes | |
# only allow accessible attributes that are not foreign keys or nested attributes | |
foreign_keys = Agent.reflect_on_all_associations.map(&:association_foreign_key) | |
allowed_attributes = base.accessible_attributes.select do |name| | |
name.present? && !foreign_keys.include?(name) && !name.match(/_attributes$/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :account do | |
desc "Change the deploy user password" | |
task :reset_password do | |
deploy_user = user | |
deploy_pass = generate_password | |
as_sudo_user do | |
find_servers.each do |server| | |
if read_file("/etc/passwd", :hosts => server.host).lines.grep(/#{deploy_user}:/).any? | |
run "echo \"#{deploy_user}:#{deploy_pass}\" | #{sudo} chpasswd", :hosts => server.host |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails email validator is required by the secure validatable module in devise security extension | |
# However, it handles internation domain names and does mx lookups by default, and there's no easy way to change this default. | |
class EmailValidator | |
def validate_mx? | |
options[:validate_mx] == true | |
end | |
def allow_idn? | |
options[:allow_idn] == true | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
module NestedAttributes | |
module ClassMethods | |
# Skips validation of associated objects unless nested attributes have been provided. | |
# | |
# This is a horrid workaround for the fact that nested_attributes_for sets the autosave | |
# option for each assocation to true, which causes validation to fail for associated | |
# objects that have been loaded, whether any nested attributes have been provided or not. | |
# This causes problems with the parent object is updated from forms that don't include |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Address < ActiveRecord::Base | |
attr_accessible :line_1, :line_2, :line_3, :town, :region, :postcode | |
validates :line_1, :postcode, :presence => true | |
validates :postcode, :postcode => true, :allow_blank => true | |
after_validation do | |
self.postcode = PostalCode.new(self.postcode).to_formatted_s | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'highline/import' | |
def highlight(str) | |
"\e[33m" + str + "\e[0m" | |
end | |
def run_cmd(cmd) | |
say highlight "Executing \"#{cmd}\"" | |
Timeout::timeout(30) do | |
IO.popen(cmd).each{ |line| print line } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim color file | |
" Maintainer: Mark Woods | |
" Licence: Public Domain | |
" GUI only color scheme based on the eclipse color scheme, optimised for ruby. | |
set background=light | |
highlight clear | |
if exists("syntax_on") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Experimental script to fix fscked wordpress permissions, needs testing | |
usage() { | |
echo "Usage: $0 [-u user] path-to-wordpress-install" | |
} | |
# allow user to be set via command line option | |
while getopts “u:v” OPTION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from Jamis Buck's post "The road to faster tests" | |
# http://37signals.com/svn/posts/2742-the-road-to-faster-tests | |
# | |
# Disabling GC and running the collector manually every few seconds | |
# knocks 25-30% off the time taken to run all of my non-js scenarios | |
# on ruby 1.9.3p448, without any other memory management tuning. | |
DEFERRED_GC_THRESHOLD = (ENV['CUCUMBER_DEFERRED_GC_THRESHOLD'] || 3.0).to_f | |
last_gc_run = Time.now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Burns a rekordbox export to an MP3 CD compatible with older CDJs. | |
# | |
# Copies mp3, m4a and wav audio files from export volume to a single CD, | |
# converting to constant bit rate mp3 compatible with older CDJs and other | |
# non-pioneer CD players as required. | |
# | |
# Will explode if files won't fit onto a single CD. Yup, I know this is shit. | |
# |