Skip to content

Instantly share code, notes, and snippets.

@YA2O
YA2O / build.sbt
Created June 14, 2018 11:33
SBT config for playing with scalaz in console
scalaVersion := "2.11.4"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.2.24"
initialCommands += "import scalaz._, Scalaz._"
@YA2O
YA2O / NonEmpty.scala
Created January 12, 2018 10:18
Container for non empty values. Uses Equal and Monoid type classes from Scalaz.
import scalaz.{Equal, Monoid}
import scalaz.Scalaz._
final case class NonEmpty[A] private[NonEmpty](value: A)
object NonEmpty {
def wrap[A: Monoid: Equal](value: A): Option[NonEmpty[A]] =
if (implicitly[Monoid[A]].zero === value)
None
else
@YA2O
YA2O / GetSystemProperties
Created June 18, 2013 13:35
List system properties
Properties props = System.getProperties();
props.list(System.out);
@YA2O
YA2O / ReadFileAsString
Created June 18, 2013 13:34
Read file as String
import org.apache.commons.io.FileUtils;
...
File file = new File(this.getClass().getClassLoader()
.getResource("/relativePath/fileName").toURI());
String st = FileUtils.readFileToString(file, "UTF-8");
if resource in same package as present file:
@YA2O
YA2O / WhereAmI
Created June 18, 2013 13:31
In which folder are we?
System.out.println(System.getProperty("user.dir"));
@YA2O
YA2O / Get current method name
Created June 18, 2013 13:28
Get current method's qualified name
String currentName = new Throwable().getStackTrace()[0].toString();