Skip to content

Instantly share code, notes, and snippets.

View afair's full-sized avatar

Allen Fair afair

View GitHub Profile
@afair
afair / gist:9648839
Created March 19, 2014 19:01
Factory Girl Basics
FactoryGirl.define do
factory :user do # class:User, aliases:[:name1, :name2]
name "Ruby"
date_of_birth { 21.years.ago } # Blocked called lazily at request time
association_factory_name
association :commenter, factory: :user, attrib:"value"
factory(:admin_user) do # Inheritance
admin true
end

Keybase proof

I hereby claim:

  • I am afair on github.
  • I am allenfair (https://keybase.io/allenfair) on keybase.
  • I have a public key whose fingerprint is F00B 3ED2 5CE8 F9AF 3D4A 55D9 1651 1D53 10AE 1388

To claim this, I am signing this object:

@afair
afair / straight-up-rspec-3.rb
Last active August 29, 2015 14:04
Notes from: Straight Up RSpec 3 - a neat Ruby BDD Tool
################################################################################
# Notes from: Straight Up RSpec 3 - a neat Ruby BDD Tool
#-------------------------------------------------------------------------------
# From: http://www.slideshare.net/gsterndale/straight-up-rspec-3
# By: Greg Sterndale
################################################################################
# .rspec
# lib/…
# spec/spec_helper.rb
@afair
afair / rubyref.rb
Last active August 29, 2015 14:04
Ruby Reference by Examples
module MyModule
def module_method
end
end
class RubyRef < BaseClass
include MyModule
attr_reader :a
attr_writer :b
attr_accessor :c
@afair
afair / nokogiri-freebsd-install.sh
Created December 5, 2014 16:11
Install Nokogiri on FreeBSD
#!/bin/sh
gem install nokogiri -- \
--use-system-libraries \
--with-xml2-lib=/usr/local/lib \
--with-xml2-include=/usr/local/include/libxml2/libxml \
--with-xslt-lib=/usr/local/lib \
--with-xslt-include=/usr/local/include/libxslt \
--with-iconv-lib=/usr/local/lib \
--with-iconv-include=/usr/local/include
@afair
afair / passenger-install-apache2-module-5.0.8.log
Last active August 29, 2015 14:28
passenger-install-apache2-module, versions 5.0.8 Success! :-)
allen@dev2 % passenger-install-apache2-module ~
Welcome to the Phusion Passenger Apache 2 module installer, v5.0.8.
This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.
Here's what you can expect from the installation process:
1. The Apache 2 module will be installed for you.
2. You'll learn how to configure Apache.
#!/bin/bash
# Inspired by http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost
apt-get update
apt-get upgrade -y
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev
apt-get -y install mysql-server libmysqlclient15-dev mysql-client
apt-get -y install ruby ruby1.8-dev irb ri rdoc libopenssl-ruby1.8
RUBYGEMS="rubygems-1.3.0"
#!/bin/bash
# Update the system first
sudo ntpdate ntp.ubuntu.com
sudo apt-get update
sudo apt-get upgrade
# Ubuntu stuff
sudo apt-get -y install git-core openssh-server openssh-client build-essential wget ntp-simple
# be aware: vim vim-ruby installed x crap :(
require 'active_support'
class MyLogger < ActiveSupport::BufferedLogger
SEVERITY_NAME = %w( DEBUG INFO WARN ERROR FATAL UNKNOWN )
def custom_line(severity, message)
# Customized Log Format!
message = [Time.now.strftime("%Y-%m-%d %H:%M:%S"), ENV['BL_JOB_ID']||$$, SEVERITY_NAME[severity], message].join("\t")
end
def add(severity, message = nil, progname = nil, &block)
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
class Cleaner
def read
f = File.open("nelson.xml")
@doc = Nokogiri::XML(f)
f.close
end