Skip to content

Instantly share code, notes, and snippets.

View ryanwood's full-sized avatar

Ryan Wood ryanwood

View GitHub Profile
#
# Lunar/Moon phases ruby class
#
# Code is based upon Bradley E. Schaefer''s moon phase algorithm.
# Ruby version based on JavaScript Phase Calculator by Stephen R. Schmitt
class Moon
attr_reader :epoch, :phase, :days, :icon, :dist, :ll
# Return the current (or input a date) moon.
# Moon.new
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
function my-rvm-prompt() {
rvmvg=$(~/.rvm/bin/rvm-prompt v g)
if [[ x$rvmvg != x ]]; then
color=$fg[yellow]
[ x$rvmvg != x ] && echo " %{$color%}$rvmvg$reset_color%}"
fi
}
@jimweirich
jimweirich / analysis.rb
Created July 20, 2011 16:37
Results from Roman Numeral Calculator Kata at @cincinnatirb
# When I posted the results of the Roman Numeral Calculator kata
# earlier this week, I said that I felt that the evolution of the code
# through TDD was much more interesting than the final result. Let me
# explain.
#
# First, some background. The goal of this Kata is to produce a
# RomanNumeralCalculator object that converts from arabic numbers to
# Roman numerals, and from Roman numerals back to arabic.
Then { calculate("1").should == "I" }
@un33k
un33k / sed cheatsheet
Created August 22, 2011 13:28
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@brentertz
brentertz / rvm2rbenv.txt
Created November 21, 2011 23:00
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@seangaffney
seangaffney / gist:1469551
Created December 12, 2011 22:59
Print functions bound to currently selected's click event
jQuery.each($($0).data("events").click, function(key, handlerObj) { console.log(handlerObj.handler) });
@riyad
riyad / bootstrap_breadcrumbs_builder.rb
Created February 28, 2012 17:38
How to make breadcrumbs_on_rails render a Bootstrap compatible breadcrumb navigation
# The BootstrapBreadcrumbsBuilder is a Bootstrap compatible breadcrumb builder.
# It provides basic functionalities to render a breadcrumb navigation according to Bootstrap's conventions.
#
# BootstrapBreadcrumbsBuilder accepts a limited set of options:
# * separator: what should be displayed as a separator between elements
#
# You can use it with the :builder option on render_breadcrumbs:
# <%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder, :separator => "&raquo;" %>
#
# Note: You may need to adjust the autoload_paths in your config/application.rb file for rails to load this class:
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@joselo
joselo / test_helper.rb
Created April 13, 2012 03:18 — forked from gnepud/test_helper.rb
MiniTest::Spec with Rails 3.2 setup
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/autorun'
require 'minitest/pride'
require 'capybara/rails'
class MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown