Skip to content

Instantly share code, notes, and snippets.

View hwatkins's full-sized avatar

Hugh Watkins hwatkins

View GitHub Profile
@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)].
@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 / 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 / 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 / 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 / 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 / mongoid_3_multiple_database.txt
Created September 18, 2012 18:57
Mongoid 3.x multiple database
If you want to use multiple dbs at once there are several different ways...
1) If you want to do this on a per-model level, use .store_in (This is for all threads):
class Band
include Mongoid::Document
store_in database: "secondary" # This can be any name you want, no need to put it in the mongoid.yml.
end
class Artist
@hwatkins
hwatkins / gist:3491399
Created August 27, 2012 19:10 — forked from seyhunak/gist:3479066
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@hwatkins
hwatkins / ratings.rb
Created December 2, 2011 23:15
A script to use the Netflix paginated "What You've Rated" to pull what you have rated in Netflix. This call is not exposed in the Netflix API so it's hard to get any other way. This is quick and dirty so not the best Ruby constructs.
#!/usr/bin/env ruby
require 'iconv'
require 'nokogiri'
# This is a simple script to spider your Netflix paginated "What You've Rated" list.
# It requires an OS X based system with Ruby 1.9+, Safari, and AppleScript
#
# I could not find a way to back up my ratings (for all titles, not just my rental activity)
# without registering for a Netflix API key or handing my Netflix credentials over to someone
# who had an API key, so I decided to take a brute force approach and just parse the HTML for
@hwatkins
hwatkins / application_helper.rb
Created December 18, 2010 14:40
Telephone number link
module ApplicationHelper
def phone_number_link(text)
sets_of_numbers = text.scan(/[0-9]+/)
number = "+1-#{sets_of_numbers.join('-')}"
link_to text, "tel:#{number}"
end
end