This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test/acceptance/exercises_test.rb | |
# | |
# | |
# Attempt 1 | |
require_relative '../acceptance_helper' | |
class ExercisesTest < AcceptanceTestCase | |
def test_navigation_from_readme_to_readme | |
visit '/exercises/ruby/phone-number/readme' | |
click_on 'Readme' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Derivation of (f .) . g == f (g x y) | |
-- Examples | |
countWhere = (length .) . filter | |
duplicate = (concat .) . replicate | |
concatMap = (concat .) . map | |
-- Could also be written | |
countWhere p xs = length (filter p xs) | |
duplicate n xs = concat (replicate n xs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Tail-recursive Fibonacci | |
fib n = go n (0, 1) | |
where | |
-- (x, y) are the last two calculated Fibonacci numbers | |
-- n is how many more Fibonacci steps to take | |
-- calling `go` is the final step in evaluating `go (n - 1) (y, x + y)` | |
go n (x, _) | n < 1 = x | |
go n (x, y) = go (n - 1) (y, x + y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'curb' | |
require 'faraday' | |
require 'open-uri' | |
require 'rest_client' | |
def time_request | |
t = Time.now | |
yield | |
puts Time.now - t | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/clean_database_spec.rb | |
require 'rails_helper' | |
describe 'Checking for clean database' do | |
specify 'no data to start with' do | |
[ | |
# your model classes | |
].each do |model| | |
expect(model.count).to be_zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JoinList where | |
import Sized | |
import Data.Monoid ((<>)) | |
data JoinList m a = Empty | |
| Single m a | |
| Append m (JoinList m a) (JoinList m a) | |
deriving (Eq, Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Welcome to the Game!" | |
puts "What's your name?" | |
name = gets.chomp | |
puts "Hi, #{name}!" | |
puts "How old are you" | |
age = gets.chomp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Towers of Hanoi for three pegs | |
-- outputs a list of moves to transport a tower of specified size | |
-- from peg A to peg B, with peg C as reserve space. | |
-- | |
-- $ runghc hanoi.hs 3 | |
-- [("A","B"),("A","C"),("B","C"),("A","B"),("C","A"),("C","B"),("A","B")] | |
import System.Environment (getArgs) | |
main :: IO () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# View | |
model = MY_MODEL_NAME | |
model.methods.select { |method| method.to_s =~ /^_{1}[^_].+_callbacks$/ } | |
.each_with_object({}) { |method, memo| memo[method] = model.send(method).group_by(&:kind) | |
.each { |_, callbacks| callbacks.map! { |callback| callback.raw_filter } } } | |
# Nuke | |
%i(initialize validate create update save destroy validation find touch commit rollback).each do |event| | |
reset_callbacks event | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; > (-main 3) | |
; Hit you in the right knee! | |
; Hit you in the left achilles! | |
; Hit you in the back! | |
; I think you've had enough. | |
; => nil | |
(defn hit | |
"Expects a nested map with int keys pointing to maps of :name and :size, | |
and a :max key indicating the smallest strict upper bound of int keys" |