Skip to content

Instantly share code, notes, and snippets.

View gfmurphy's full-sized avatar

George F Murphy gfmurphy

  • Salesforce
  • Little Rock
View GitHub Profile
@gfmurphy
gfmurphy / Div.hs
Last active November 28, 2015 19:59
Readability
digits n =
findDigits (rem n 10) [] (quot n 10)
where addDigit d ds = (abs d): ds
findDigits d ds 0 = addDigit d ds
findDigits d ds b = findDigits (rem b 10) (addDigit d ds) (quot b 10)
divisableDigits n =
length (filter divisable (digits n))
where zero 0 = True
zero _ = False
@gfmurphy
gfmurphy / ostruct_context_bench.rb
Created March 6, 2016 13:05
OpenStruct Performance Test
require "benchmark"
require "ostruct"
BadContext = Class.new(OpenStruct)
class BetterContext
attr_accessor :a, :b, :c, :d, :e, :f
end
def test_it(klass, &b)
@gfmurphy
gfmurphy / request_path_protocol.ex
Last active December 28, 2017 14:04
Request path protocol spike
defprotocol JsonApiClient.RequestPath do
@moduledoc """
The `JsonApiClient.RequestPath` protocol provides a single function to be implemented that maps
a given Elixir term to a string representation of an url path.
"""
@doc """
Converts `term` to a string representation of a given path.
"""
@spec to_path(term()) :: String.t