Skip to content

Instantly share code, notes, and snippets.

View gupta-himanshu's full-sized avatar

Himanshu Gupta gupta-himanshu

View GitHub Profile
# Package for Log4R
library("log4r")
# Default Logger
default_logger <- logger()
# Debug level enabled Logger (by default DEBUG level is suppressed)
debug_logger <- logger("DEBUG")
# File Logger
  1. Prefer static factory methods over constructors

    • Advantage - They are not required to create a new object each time they’re invoked. This allows immutable classes to use preconstructed instances, or to cache instances as they’re constructed, and dispense them repeatedly to avoid creating unnecessary duplicate objects.

    • Disadvantage - The classes without public or protected constructors cannot be subclassed. For example, it is impossible to subclass any of the convenience implementation classes in the Collections Framework. Arguably this can be a blessing in disguise because it encourages programmers to use composition instead of inheritance, and is required for immutable types.

  2. Prefer a builder when there are too many Constructor parameters

  • Advantage - It combines the safety of the telescoping constructor pattern with the readability of the JavaBeans pattern. It is a form of the Builder pattern. Instead of making the desired object directly, the client calls a c
@padurean
padurean / Scala-SBT-Pass-JVM-Options-To-Test.md
Last active May 21, 2022 14:47
SBT, Scala - Pass JVM options when running tests

Use javaOptions sbt setting in Build.scala or build.sbt to pass jvm options to tests e.g.

  • statically:
javaOptions in Test ++= Seq("-Dconfig.file=conf/staging.conf")

or

@dbalduini
dbalduini / JodaConverters.scala
Created November 10, 2014 18:46
Play json Joda-Time Converters
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.{Period, LocalDate, DateTime, Duration}
import play.api.data.validation.ValidationError
import play.api.libs.json._
/**
* @author dbalduini
*/
object JodaConverters {