Check multiple option values in Scala

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 _ => ??? }

Creating and validating JWT JSON web tokens

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.

Make a request to a remote service

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.

Migrating from WordPress to Hugo

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.

Meet the $250,000,000 man

When you do have money, the money gives you power… because you don’t have to answer to anybody. - Ben Mallah

Who pays wages?

It is not the employer who pays the wages. Employers only handle the money. It is the customer who pays the wages. - Henry Ford

Error handling for JS fetch requests

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).

A purely functional example using Scala

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:

Examples of ‘for’ queries with Scala

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’

Enterprise Architect – Synchronize model from a live database

Synchronize a model from a live database to Enterprise Architect. Select your database from the Database Model folder in Project Browser. Go to Tools > Database Builder Right click on Tables > Show Differences. We can also click on a different type of object. a. An active connection is needed to complete the previous step. If no one exists Enterprise Architect will ask us to create one. The list of differences will show up on the Database Compare tab Select the ones you want to import or click the Set Import All button.