Skip to content

Instantly share code, notes, and snippets.

View hwatkins's full-sized avatar

Hugh Watkins hwatkins

View GitHub Profile
@hwatkins
hwatkins / rspec_rails_cheetsheet.rb
Created October 15, 2012 22:38 — forked from them0nk/rspec_rails_cheetsheet.rb
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)
@hwatkins
hwatkins / FormHelperMonkeypatch.rb
Created December 3, 2012 15:48
Add form submit id back to rails
module ActionView
module Helpers
class FormBuilder
# code from rails 3.0
def submit(value=nil, options={})
value, options = nil, value if value.is_a?(Hash)
value ||= submit_default_value
@template.submit_tag(value, options.reverse_merge(:id => "#{object_name}_submit"))
end
end
@hwatkins
hwatkins / output.txt
Created February 27, 2013 16:05
Simple script to show the availability of starline brass
$ ruby starline.rb
357-SIG-Brass 500 ($98.50) 1000 ($163.50) Available: 04/29/2013
9MM-Brass
9MMP-Brass
380-Auto-Brass 500 ($73.00) 1000 ($129.00) Available: 04/16/2013
40-SandW-Brass
45-Auto-P-Brass
45-Auto-Brass
@hwatkins
hwatkins / powder_valley.rb
Created March 20, 2013 17:44
Check availability on powder valley
require 'rubygems'
require 'nokogiri'
require 'open-uri'
pages= %w[CCIprimers REMprimers WINprimers accurate alliant hodgdon BEBullets HPBullets SPPBullets]
pages.each do |page|
doc = Nokogiri::HTML(open("http://www.powdervalleyinc.com/#{page}.shtml"))
doc.xpath('//form//table//tr').each_with_index do |row, index|
next if index < 2
@hwatkins
hwatkins / creating_projects_spec.rb
Created May 14, 2013 19:19
Sample capybara test spec/integration/creating_projects_spec.rb
require 'spec_helper'
feature 'Creating Projects' do
scenario "can create a project" do
visit '/'
click_link 'New Project'
fill_in 'Name', :with => 'TextMate 2'
fill_in 'Description', :with => 'A text-editor for OS X'
click_button 'Create Project'
expect(page).to have_content('Project has been created.')
end
@hwatkins
hwatkins / memory.erl
Last active August 29, 2015 14:05
Tools for memory analysis
erlang:memory(total).
%% GC all processes
[erlang:garbage_collect(Pid) || Pid <- processes()].
[{K,V / math:pow(1024,3)} || {K,V} <- erlang:memory()].
[{T, ets:info(T, memory)} || T <- ets:all()].
[{T, mnesia:table_info(T, memory)} || T <- mnesia:system_info(tables)].