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 / 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
@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 / 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 / gist:d408da3f91b17c266a0e
Last active August 29, 2015 14:15
Noindex deal criteria - i.e. instruct search engines to ignore deals (and remove from index) and *not* publish in xml sitemap.
# Deal types currently included in xml sitemap
# * "LocalDeal", "EscapesDeal", "AtHomeDeal", "FamiliesDeal"
# * live event deals are included
# URLs are generated with LS::Routing
# * Need to support a mobile version of the url for alternate content and mobile sitemap in near future.
def search_engine_ignore?(deal)
deal.exclusive? || deal.boomerang? || !deal.active?
end
# this logic expands to
@gfmurphy
gfmurphy / synch.cc
Created May 2, 2013 23:08
Mesa style wait and signal algorithm
void Condition_H::Wait() {
IntStatus oldLevel = interrupt->SetLevel(IntOff);
count++;
if (mon->next_count > 0) {
mon->next->V();
mon->next_count--;
}
else mon->mutex->V();
sem->P();
@gfmurphy
gfmurphy / simple_histogram.rb
Created April 16, 2013 13:56
Find top 16 most freq. occurring words greater than 4 characters
paragraphs.join("\n").split(/\W/)
.reject { |w| w.size < 4 }
.map(&:downcase)
.reduce(Hash.new(0)) { |words, word| words[word] += 1; words }
.sort { |a, b| a.last <=> b.last }
.take(16)
.map(&:first)
.join(' ')
@gfmurphy
gfmurphy / taxon_import.rb
Created February 20, 2012 16:13
Proposed Spree Data Import API
Spree::DataImport.for(:taxons).run("https://abcdef012356789:x@wherethedatalives.com/taxons.xml")
@gfmurphy
gfmurphy / resource_bs.rb
Created January 23, 2012 21:29
Le sigh...
def load_resource
"#{controller_name.classify}".constantize.find(params[:id])
end
@gfmurphy
gfmurphy / order.rb
Created January 17, 2012 15:41
Spree Price Bucket Calculator Fix
Order.class_eval do
def amount
line_items.map(&:amount).sum
end
end
@gfmurphy
gfmurphy / gah.rb
Created January 10, 2012 20:49
Sweet Sassy Rails
zone.try(:user).try(:has_carrier?, carrier.try(:name))