Skip to content

Instantly share code, notes, and snippets.

View danmcclain's full-sized avatar

Dan McClain danmcclain

View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>nginx</string>
<key>Program</key>
<string>/opt/nginx/sbin/nginx</string>
<key>KeepAlive</key>
<true/>
# post.rb
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :required => true
property :body, Text, :required => true
property :slug, String
before :save, :make_slug
Then /^I should see the assigned to my students$/ do
@user.students.map(&:notes).flatten.each do |note|
have_note_content(note, :should)
end
end
# @user.students.map(&:notes).flatten is equivalent to
students = @user.students
note_arrays = students.map { |student| student.notes } #shorthand: .map(&:notes)
notes = note_arrays.flatten
note_ids = NotesStudent.where(student_id: current_user.student_ids).select(:note_id).map {|n| n.note_id }
user_id = current_user.id
@notes = Note.accessible_by(current_ability).where{ (id >> note_ids) | (counselor_id == user_id) }
module Rack
module Utils
def escape(s)
CGI.escape(s.to_s)
end
def unescape(s)
CGI.unescape(s)
end
end
end
@danmcclain
danmcclain / gist:1376643
Created November 18, 2011 14:48
Jenkins Build Step
source ~/.bashrc > /dev/null
cd .
cp ~/example-database.yml config/database.yml
[ -d jenkins ] && rm -rf jenkins
mkdir jenkins
rake db:schema:load > jenkins/schema_load.txt
bundle install > jenkins/bundler.txt
echo Rspec results available at http://example.com/job/Ducky-develop/ws/jenkins/rspec.html
rake rspec_html > jenkins/rspec.html
echo Cucumber results available at http://example.com/job/Ducky-develop/ws/jenkins/cucumber.html
@danmcclain
danmcclain / custom_rspec.rake
Created November 19, 2011 21:25
Jenkins Build Task
RSpec::Core::RakeTask.new(:rspec_html) do |t|
t.pattern = 'spec/**/*_spec.rb'
t.rspec_opts = '--format html'
end
module Rubyoverflow
class Base
def initialize(client)
@client = client
end
def fetch(params = {})
ids = params.delete(:id) if params[:id]
ids = ids.join(';') if ids and ids.kind_of? Array
hash,url = @client.request "#{@path}#{"/#{ids}" if ids}", params
@danmcclain
danmcclain / User.rb
Created December 2, 2011 02:04
Metaprogramming instance methods
module Rubyoverflow
class Users < Rubyoverflow::Base
#...
end
end
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.include Rails.application.routes.url_helpers, :type => :request
config.include EmailSpec::Helpers
config.include EmailSpec::Matchers
config.extend VCR::RSpec::Macros
end