Skip to content

Instantly share code, notes, and snippets.

View veronicacannon's full-sized avatar
♥️

Veronica Cannon veronicacannon

♥️
View GitHub Profile
@veronicacannon
veronicacannon / exercise_1
Last active April 4, 2020 17:39
telldontask exercise1
# frozen_string_literal: true
Map = Struct.new(:addresses) do
def within_radius(kms)
within_range = []
addresses.each do |address|
within_range << address.to_s if address.kms <= kms
end
within_range
end
@veronicacannon
veronicacannon / logging
Created March 21, 2020 19:11
Logging example of observer pattern
# frozen_string_literal: true
# observable object aka subject
module Observable
def attach_observer(observer)
@observers ||= []
@observers << observer unless @observers.include?(observer)
end
def remove_observer(observer)
within find('tr', text: 'My title') { click_link 'edit' }
item = find(".selector", text: "Company")
.first(:xpath, ".//..") # parent node
.find(".selector2")
https://thoughtbot.com/upcase/videos/rack
require "rack"
require "thin"
class HelloWorld
def call(env)
[ 200, { "Content-Type" => "text/plain" }, ["Hello World"] ]
end
end
http://augustl.com/blog/2008/procs_blocks_and_anonymous_functions/
Procs are useful code organization tools. Let’s say that you want to calculate the running time for a few code snippets, in order to benchmark them. To do this elegantly, you want to be able to call a method and pass some code to it, and have the execution time returned.
Here’s how you can use procs to do just that:
def time(a_proc)
start = Time.now
a_proc.call
puts Time.now - start
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.