Skip to content

Instantly share code, notes, and snippets.

@uday-rayala
uday-rayala / gist:1243290
Created September 26, 2011 20:20
Builder pattern standard
case class AuthorBuilder(familyName: String = "John",
givenNames: Seq[String] = Seq("Doe"),
books: Seq[String] = Seq(),
affiliations: Seq[String] = Seq()) {
def asXML =
<Author>
<FamilyName>{familyName}</FamilyName>
<GivenNames>
{for (name <- givenNames) yield <GivenName>{name}</GivenName>}
@uday-rayala
uday-rayala / euler11
Created March 13, 2012 23:11
Project Euler - Problem 11
(ns euler)
(def grid
[
[8 2 22 97 38 15 0 40 0 75 4 5 7 78 52 12 50 77 91 8]
[49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 4 56 62 0]
[81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 3 49 13 36 65]
[52 70 95 23 4 60 11 42 69 24 68 56 1 32 56 71 37 2 36 91]
[22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80]
[24 47 32 60 99 3 45 2 44 75 33 53 78 36 84 20 35 17 12 50]
@uday-rayala
uday-rayala / rover.hs
Created June 15, 2012 20:10
Mars rover in haskell
data Position = Position Int Int Direction
deriving (Show, Eq, Read)
data Direction = N | E | W | S
deriving (Show, Eq, Enum, Bounded, Read)
data Command = L | R | M
deriving (Show, Eq, Enum, Bounded, Read)
data DeltaPosition = DeltaPosition Int Int
data State = State {
(defn get-change [coins value]
(->> (tree-seq #(> value (reduce + %))
#(map (fn [c] (sort (conj % c))) coins)
[])
(filter #(= 10 (reduce + %)))
distinct))
(get-change [1 2 3] 10)
RSpec.configure do |c|
# Enable profiling on the spec
c.before(:all) do |x|
RubyProf.start
end
c.after(:all) do |x|
results = RubyProf.stop
results.eliminate_methods!([/RSpec::Core/])
def login_with(username, password)
click '#login'
sleep 5
fill_in 'username', username
fill_in 'password', password
sleep 10
end
def login_with(username, password)
click '#login'
expect(page).to have_css('#login-popup')
fill_in 'username', username
fill_in 'password', password
expect(page).to have_no_css('#login-popup')
expect(page).to have_css('header .username', text: username)
end
Capybara::Poltergeist::Driver.new(app, phantomjs_options: ['--load-images=false', '--ignore-ssl-errors=yes'])
page.driver.browser.url_blacklist = ['http://www.google-analytics.com', 'https://ssljscdn.airbrake.io']
@uday-rayala
uday-rayala / local_pricing_engine.rb
Created March 9, 2017 15:23
LocalPricingEngine
class LocalPricingEngine
def estimate(param1, param2, param3)
...
PriceEstimate.new(..)
end
end