Skip to content

Instantly share code, notes, and snippets.

@healsjnr
healsjnr / hd_event_flows.md
Last active May 1, 2017 17:38
Hooroo direct event flows.

Successful flow

#create_booking
:booking_created
:booking_reservation_started
#create_reservation
  :reservation_created
:booking_reservation_creation_request_successful
:booking_reservation_added
@healsjnr
healsjnr / keybase.md
Last active September 26, 2016 01:02

Keybase proof

I hereby claim:

  • I am healsjnr on github.
  • I am healsjnr (https://keybase.io/healsjnr) on keybase.
  • I have a public key ASCPGqgsaMB--PaGSHicvGb4zXjYZzNT9okwl3Jv4CEZBgo

To claim this, I am signing this object:

@healsjnr
healsjnr / zipWithPredicate.scala
Created April 14, 2016 05:08
Zip with predicate
def zipWithPredicate[A,B](predicate: (A, B) => Boolean)(listA: Seq[A], listB: Seq[B]): Seq[(A, B)] = {
listA.flatMap(a => listB.find(b => predicate(a, b)).map(b => (a, b)))
}
@healsjnr
healsjnr / stringLikeReads.scala
Created April 7, 2016 01:15
Scala Play Json "string like reads"
// Can be used as explicit Reads when you want to read any String like Json type into a string.
val stringLikeRead: Reads[String] = new Reads[String] {
override def reads(json: JsValue): JsResult[String] = {
json match {
case JsNumber(n) => JsSuccess(n.toString)
case JsString(s) => JsSuccess(s)
case JsBoolean(b) => JsSuccess(b.toString)
case x => JsError(s"Expected a String like Json type (string, boolean or number). Found: $x")
}
}
@healsjnr
healsjnr / instantiate.scala
Created April 6, 2016 01:23
Instantiation order in scalas
trait BaseTrait1 {
println("BaseTrait1 Created");
val numVal: Int
val listVal: List[Int]
println(s" numVal:$numVal\n listVal:$listVal")
}
trait BaseTrait2 extends BaseTrait1 {
println("BaseTrait2 Created");
@healsjnr
healsjnr / logicTransformers.scala
Created February 16, 2016 12:04
Clean logic with Monad Transformers
// An example of how a MonadTranformer, particular EitherT, can be used to make complicate business logic far easier to read.
class PushTemplateRequestBuilder(messageFilters: ClientFilterRules, campaignTokens: Map[MessageType, String], messagePart: MessagePart) extends TemplateRequestBuilder[CreatePushMessageRequestTemplate] with ServiceResultTransformer {
import DisjunctionSupport._
def build(): Future[\/[ServiceFailure, Seq[CreatePushMessageRequestTemplate]]] = {
// The following is an example of a complex set of business requirements. In this case we need to ensure that data
// retrieved from DBs and WebService meet the criteria for creating an entry in a legacy system.
// Using the Transformers we can clearly see at each stage what the requirement is and what the error will be if
@healsjnr
healsjnr / scratch.rb
Created February 16, 2016 11:56
Ruby Scratch
# Sum the length of all words starting with t and longer than 5.
data = ["test", "alpha", "beta", "delta", "tennis", "time", "temp", "terrible"]
t_words = data.select { |x| x.start_with? "t" }
t_words_length = t_words.map { |x| x.length }
t_words_longer_than_5 = t_words_length.select { |x| x > 5 }
t_words_longer_than_5.reduce(0,:+)
@healsjnr
healsjnr / ImprovedFilterable.rb
Created February 2, 2016 03:27
Improved Filterable
module Filterable
extend ActiveSupport::Concern
module ClassMethods
def filter(filtering_params)
# Create an anonymous scope and then reduce it base on key / value
filtering_params.inject(self.where(nil)) do |results, (key, value)|
results.public_send(key, value) if value.present?
end
end
end
@healsjnr
healsjnr / Filterable.rb
Created February 2, 2016 03:24
Exist-filtering-module
module Filterable
extend ActiveSupport::Concern
module ClassMethods
def filter(filtering_params)
results = self.where(nil)
filtering_params.each do |key, value|
results = results.public_send(key, value) if value.present?
end
results
@healsjnr
healsjnr / writesTest.scala
Last active February 1, 2016 21:54
Using the Writes
val writesTest = contramapWrites(writesWriteable, ((t: Test) => Writeable(t.a, t.b.toString)))