Skip to content

Instantly share code, notes, and snippets.

#Code is Data, So Own Your Code!

Other day a co-worker showed me this piece of code and asked me how we could re-write it in a more Scala way.

//generate id based on rule characteristics
if(priceStatusRule && hierarchyRule && markdownRule && lastReceivedDateRule){
  priorityId = 1
} else if(hierarchyRule && markdownRule && lastReceivedDateRule && !priceStatusRule){
  priorityId = 2
@sirmes
sirmes / gist:5e03afcc2144dc34b523
Last active August 29, 2015 14:01
Questions for Martin Odersky @ Saks

#Questions for Martin Odersky @ Saks ##Grouped by areas

  1. Future of JVM and Scala

    • Where do you see the future of JVM languages going? Scala, Java 8, Closure.
    • Can you speak about dotty and how older scala versions will be impacted?
    • Future evolution of the Scala Stack: should we expect more new features in the core of the language (e.g. Macros in * Scala 2.10) or more on the "enterprise" stack (e.g. Akka, Play, ...) ?
    • Java 8 lamba expressions: is Scala going to include that as part of its syntax or is it going to keep the same functional syntax leveraging the implementation on lambda expressions?
  2. Functional Programming

    • It's been 35 years since John Backus's Turing award speech about FP. What are your thoughts about where FP is today?
@sirmes
sirmes / gist:c23b796a452e49f17ed6
Last active August 29, 2015 14:00
Coding Exercise

#Coding Exercise ##Abstract

The exercise is broken in 3 parts, as described below. When you are done, follow these steps to delivery your answers.

  • Create a new repository in Github, and upload your entire project, with the code you wrote, into Github
  • Send us the URL to the repository
  • Note, we should be able to clone your repo and compile all code in the project you created.

##Exercises

#How to handle caching in a functional way
scala> case class StlCache(pcode : String, stl_pcode : List[String], ttl : Int)
defined class StlCache
scala> val lamer = StlCache("01", List("02", "03"), 100)
lamer: StlCache = StlCache(01,List(02, 03),100)
scala> val lancome = StlCache("04", List("05", "06"), 500)
lancome: StlCache = StlCache(04,List(05, 06),500)
package controllers
import play.api.mvc._
import ProductDetailService.app.models.{ProductLike, Product}
import play.api.libs.json.{Json, JsValue}
import scala.concurrent.{Await, Future}
import com.s5a.service.utils.Slf4JLogger
import com.s5a.service.metrics.Timer
import com.s5a.metrics.{MetricNamespace, Recorder}
import scala.concurrent.duration._
@sirmes
sirmes / gist:8715260
Created January 30, 2014 18:22
.gitignore
#Java/Scala
*.class
*.log
*.jar
# sbt specific
dist/*
target/
lib_managed/
src_managed/
@sirmes
sirmes / gist:7453768
Last active December 28, 2015 05:59
PRS - Proposed changes for ResponseAggregator and ProductDataRepository
package com.s5a.service.product_repo
import com.s5a.service.core.akka.EndpointUriSet
import akka.camel.CamelMessage
import com.s5a.service.core.akka.SimpleProducer
import play.api.libs.json._
import play.api.libs.json.Json._
import play.api.libs.json.JsArray
import play.api.libs.json.JsSuccess
import play.api.libs.json.JsString
@sirmes
sirmes / gist:7453751
Created November 13, 2013 18:18
CMP - Proposed changes for ResponseTopicConsumer and ESBBootstrap
package com.s5a.cmp.scala.esb
import com.s5a.service.core.akka.LifeCycle
import com.s5a.config.{Config, S5AConfigFactory}
import akka.actor.{ActorRef, ActorSystem}
import org.hornetq.jms.server.embedded.EmbeddedJMS
import javax.jms.ConnectionFactory
import org.apache.camel.component.jms.JmsComponent
import org.slf4j.{LoggerFactory, Logger}
import akka.camel.CamelExtension
@sirmes
sirmes / gist:7453724
Last active December 28, 2015 05:59
ServiceCore - Proposed trait Query changes
package com.s5a.service.messages
import play.api.libs.json._
import org.slf4j.{LoggerFactory, Logger}
import com.eaio.uuid.UUID
import org.joda.time.Instant
import play.api.libs.json.JsSuccess
//{"query" : "inventory", "product_code":"04827348293"}
trait Query{