avatar

Andres Jaimes

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: 1if (opt1.isDefined && opt2.isDefined && opt3.isDefined) // do something Check values using match: 1(opt1, opt2, opt3) match { 2 case(Some(val1), Some(val2), Some(val3)) => ??? 3 case _ => ??? 4}

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: 1libraryDependencies ++= 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. 1import java.time.Instant 2import java.util.{Date, UUID} 3 4import 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 1import scala.concurrent.Future 2import play.api.http.Status._ 3import play.api.libs.ws.WSClient 4import play.api.libs.json.{JsSuccess, Json} 5 6case class UnexpectedResponseStatus(message: String) extends Exception(message) 7case class InvalidServiceResponse(message: String) extends Exception(message) 8 9class SomeClass @Inject()( 10 ws: WSClient 11) { 12 def getFromRemoteService(url: String): Future[Option[MyClass]] = { 13 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.

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. 1function handleErrors(response) { 2 if (!response.ok) throw new Error(response.status) 3 return response 4} 5 6fetch('https://jsonplaceholder.typicode.com/todos/1') 7 // handle network err/success 8 .then(handleErrors) 9 // use response of network on fetch Promise resolve 10 .then(response => console.log("ok")) 11 // handle fetch Promise error 12 .catch(error => console.log('found an error: ', error)) handleErrors can be updated for handling different types of errors in different ways.

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: 1case class Book(title: String, authors: List[String]) 2 3val books: List[Book] = List( 4 Book("structure and interpretation of computer programs", 5 List("abelson, harald", "sussman, gerald j.")), 6 Book("introduction to functional programming", 7 List("bird, richard", "wadler, phil")), 8 Book("effective java", 9 List("bloch, joshua")), 10 Book("java puzzlers", 11 List("bloch, joshua", "gafter, neal")), 12 Book("programming in scala", 13 List("odersky, martin", "spoon, lex", "venners, bill")) 14) 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.