Skip to content

Instantly share code, notes, and snippets.

# Ok, this is just a simplified example:
@parent.children.all_passing? # => true or false
# I want a method that returns something based on the collection of
# associated objects. Using association extensions, I can put a
# method on the has_many in parent model:
class Parent < ActiveRecord::Base
# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
DeflateCompressionLevel 9
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
andrew@feldspar ~/Sites/pemberton(master) $ git branch -r
trunk
trunk@289
whistler/php
whistler/trunk
whistler/wlpsite
whistler/wlpsite@42
andrew@feldspar ~/Sites/pemberton(master) $ git co -b whistler/master whistler/trunk
Switched to a new branch 'whistler/master'
# prompt for showing current git branch and dirty state:
__git_branch_status() {
local b
local d
if ! [[ $(git status 2> /dev/null) ]]; then
return
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
b="$(git rev-parse 2>/dev/null | cut -c1-7)..."
#! /usr/bin/env ruby
require 'find'
PATTERN = Regexp.new '(\r\n\r\n)?<script>[^\n]+</script>\n<!--[a-f0-9]{32}-->'
def kill_virus(dir)
Find.find(dir) do |path|
if File.file?(path)
text = File.read(path)
if text =~ PATTERN
class Gender
include Comparable
attr_reader :gender
VALID_ENUMS = [:male, :female]
def initialize(value)
value = value.to_s.downcase.to_sym
@gender = value if VALID_ENUMS.include?(value)
end
# Use an instance for the top-level form_for
form_for @parent do |f|
# Always use a symbol to access the nested association from f.object
f.fields_for :child do |fc|
# generates: params[:parent][:child_attributes][:field]
end
# Optionally, provide an instance as a *second* argument
f.fields_for :relative, (@other_parent or Person.new) do |fr|
SELECT @old_domain:='stage.example.com';
SELECT @new_domain:='www.example.com';
UPDATE wp_postmeta SET
meta_value=REPLACE(meta_value, @old_domain, @new_domain);
UPDATE wp_posts SET
post_content=REPLACE(post_content, @old_domain, @new_domain),
post_excerpt=REPLACE(post_excerpt, @old_domain, @new_domain),
guid=REPLACE(guid, @old_domain, @new_domain);
# usage:
# field_labeled('Select your address').should have_option("Home Address")
Spec::Matchers.define :have_option do |expected|
def options_for(select_field)
select_field.options.map(&:inner_text)
end
match do |select_field|
raise "Field is not a SelectField" unless select_field.kind_of?(Webrat::SelectField)
options_for(select_field).include?(expected)
<?php
$revcaptcha = md5($_SERVER['REMOTE_ADDR'] . 'random_salt');
function check_revcaptcha($key1, $key2, $revcaptcha) {
if ($_POST[$key1] == '' && $_POST[$key2] == $revcaptcha) {
unset( $_POST[$key1] );
unset( $_POST[$key2] );
return true;
} else {
return false;