Skip to content

Instantly share code, notes, and snippets.

View AgentAntelope's full-sized avatar

fell sunderland AgentAntelope

  • London, UK
  • 17:07 (UTC +01:00)
View GitHub Profile
@AgentAntelope
AgentAntelope / fractionator.rb
Created September 7, 2021 11:31
A quick hack to calculate rational frations where digits can be cancelled to correctly reduce the fraction
class Array
# Subtract each passed value once:
# %w(1 2 3 1).subtract_once %w(1 1 2) # => ["3"]
# [ 1, 1, 2, 2, 3, 3, 4, 5 ].subtract_once([ 1, 2, 4 ]) => [1, 2, 3, 3, 5]
# Time complexity of O(n + m)
def subtract_once(values)
counts = values.inject(Hash.new(0)) { |h, v| h[v] += 1; h }
reject { |e| counts[e] -= 1 unless counts[e].zero? }
end
end
# Given user is logged in and on users#show
# When user edits a proof
# Then user expects to see the updated proof on users#show
scenario 'user edits a proof' do
proof = create(:proof)
create(:standard, name: "1.1.1", proof: proof)
visit signin_path
click_link 'Edit proof'
fill_in 'proof_image_url', with: 'http://www.imgur.com/1.1.1-updated_today.png'
click_button 'Submit'
def omniauth_github_response_for(user)
OmniAuth::AuthHash.new({
provider: 'facebook',
uid: user.uid,
info: {
name: user.name,
nickname: user.nickname,
image: user.image_url,
urls: {"Facebook" => user.facebook_url}
}
@AgentAntelope
AgentAntelope / entry.rake
Created July 12, 2013 06:48
This should live in lib/tasks. It can be run by doing `rake entry:category:change_dreams`.
namespace :entry
namespace :category
desc "Change all entry categories where the category is 'dreams' to 'dreams/sleep'
task :change_dreams => :environment do
Entry.where(:category => 'dreams').update_all(:category => 'dreams/sleep')
end
end
end
@AgentAntelope
AgentAntelope / gist:5244765
Last active December 15, 2015 10:19
Make RubyTest work with vagrant

Prefs -> Package Settings -> RubyTest -> Settings - User

{ "run_rspec_command": "commandusedtosshtovagrant 'cd /path/to/project/root/in/vagrant && zeus rspec {relative_path}'", "run_single_rspec_command": "commandusedtosshtovagrant 'cd /path/to/project/root/in/vagrant && zeus rspec {relative_path} :{line_number}'" }

{relative_path} and {line_number} are things sublime uses, and should remain as is. commandusedtosshtovagrant and /path/to/project/root/in/vagrant should be replaced with the appropriate command/path. You must also have run zeus start on your project root.