This article lists a curated list of Java libraries that I have used over the years for different projects. They are all well documented, and for most of them, plenty of examples can be found on the web.
Apache Commons Email Commons Email
Commons Email aims to provide a API for sending email. It is built on top of the Java Mail API, which it aims to simplify.
User Guide Apache Commons StringUtils <dependency> <groupId>org.
Two main approaches for doing this, the second one being for me the most appropriate.
Check values using regular if conditions:
if (opt1.isDefined && opt2.isDefined && opt3.isDefined) // do something Check values using match:
(opt1, opt2, opt3) match { case(Some(val1), Some(val2), Some(val3)) => ??? case _ => ??? }
This article goes through the process of creating and validating JWT’s (JSON web tokens) using Scala.
Our implementation uses the awesome io.jsonwebtoken library, and can be added to a sbt project like this:
libraryDependencies ++= Seq("io.jsonwebtoken" % "jjwt" % "0.9.1") Creating a token We are going to use Scala’s apply/unapply functions for this implementation. This will allow us to use matchers for checking JWT’s.
import java.time.Instant import java.util.{Date, UUID} import io.
This article shows how to make remote requests to services using Scala and the Play-Framework. It documents some recommended features that can improve the reliability of the request.
Setup Make sure you add the following dependency to build.sbt
libraryDependencies += ws GET request GET request to a remote service
import scala.concurrent.Future import play.api.http.Status._ import play.api.libs.ws.WSClient import play.api.libs.json.{JsSuccess, Json} case class UnexpectedResponseStatus(message: String) extends Exception(message) case class InvalidServiceResponse(message: String) extends Exception(message) class SomeClass @Inject()( ws: WSClient ) { def getFromRemoteService(url: String): Future[Option[MyClass]] = { ws.
The idea behind migrating to hugo is to avoid having to deal with server and certificate updates, backups and so on. Plus moving a site to a global network, like Netlify’s, comes with the added benefits of quick download speeds and an easy to use deployment process.
Migration steps Install the WordPress to hugo Exporter plugin to your WordPress site. This plugin does not have any configuration settings. You just have to export it.
When you do have money, the money gives you power… because you don’t have to answer to anybody. - Ben Mallah
It is not the employer who pays the wages. Employers only handle the money. It is the customer who pays the wages. - Henry Ford
The following example handles server and connectivity errors for javascript fetch requests.
function handleErrors(response) { if (!response.ok) throw new Error(response.status) return response } fetch('https://jsonplaceholder.typicode.com/todos/1') // handle network err/success .then(handleErrors) // use response of network on fetch Promise resolve .then(response => console.log("ok")) // handle fetch Promise error .catch(error => console.log('found an error: ', error)) handleErrors can be updated for handling different types of errors in different ways. This function is called whenever we get a response from the server (successful or failed).
On this tutorial we’re going to explore the basics of purely functional programming using Scala. One of the principles with purely functional style, is that we have to define concepts in terms of functions.
The basics: Comparing a number We’re going to create a simple function that lets us compare a number to a previously stored number in a purely functional way. For that, we can define the following function:
On this page you are going to find some examples of ‘for’ queries.
Let’s start by defining the following database:
case class Book(title: String, authors: List[String]) val books: List[Book] = List( Book("structure and interpretation of computer programs", List("abelson, harald", "sussman, gerald j.")), Book("introduction to functional programming", List("bird, richard", "wadler, phil")), Book("effective java", List("bloch, joshua")), Book("java puzzlers", List("bloch, joshua", "gafter, neal")), Book("programming in scala", List("odersky, martin", "spoon, lex", "venners, bill")) ) Find the titles of books whose author’s name is ‘bird’