Posted on February 23, 2024
Almost all my career I’ve been mostly a backend guy. Even when I was working with mobile platforms it usually was related to different background services. And I’m ok with that. Well, sometimes it might be difficult to explain people what are you actually doing, but I still prefer this things just because it’s more interesting for me, and, to be honest, I’m pretty bad in drawing, choosing colors, etc.
However, some time ago I played Duotrigordle and I thought what it would be great to have it in Russian. And that lead me to another pet project in a very uncommon environment for me. It’s a pure client word guessing game. Of course, I could use Scala.js for that, but I wanted to keep it light, and also, to have a little bit practice in the common frontend tools. It took couple of months for me to create it from scratch. It still have a nasty hard to reproduce bug, but it’s available at 32.limansky.me, so you can play it. Here I’d like to share some details and thoughts about this project development.
Continue readingPosted on October 6, 2023
Just a little bit about my free time. I haven’t been here for a while, but it was for a good reason. This year my band finished a debut album and it available for a while on the most of the streaming services.
Posted on July 26, 2021
In this post I’d like to discover Scala 3 generic programming abilities. Scala 3 provides a lot of new features, and generic programming is the one of the areas where we have a lot of changes. I assume that you have used shapeless with Scala 2, but if not, I’ll try to explain things in this post. However I’d recommend to read this post before if you don’t even know what shapeless is.
Continue readingPosted on November 13, 2018
I’d like to announce my new project called sbt-git-flow-version. As you might guess it’s a plugin for sbt. The goal of the project is set your sbt build version according to git flow rules.
I found that for big or medium size teams git flow is quite practical. What I didn’t
like about it, is that it requires to change the version all the time you change the branch
in your repository. At some point I took responsibilities of release engineer in our team.
Since I’m very lazy to do all of this styff I came up with some Scala code in the project
catalog
of my current working project. Later I rewrote it as an sbt plugin.
So, what can it do for you?
Continue readingPosted on August 9, 2017
I’m happy to announce the second release of BeanPurée library.
The main goal of this release is to make BeanConverter
more intelligent.
Previously, it required you to have the same type for the corresponding fields in a
bean and a product. If there are Java number classes in your beans, it’s possible you
don’t want to use it in your Scala code. Instead, you would like to use Options,
or you may know that these values are never null.
Now BeanConverter
can do these kinds of transformations for you.
JavaTypeMapper
type class was introduced to acheive that. It provides
two-way conversions for the following cases:
java.math.BigDecimal
to scala.math.BigDecimal
. If Java value is null it throws
NullPointerException.T
to an Option[T]
. Wraps nullable to Option.T
for which an instance of JavaTypeMapper
to class U
is
available to an Option[U]
. For example it is used to convert Integer
to
Option[Int]
.HList
of the elements which can be mapped with JavaTypeMapper
s, to HList
of mapped values.If you want to have a previous behavior from BeanConverter
use
StrictBeanConverter
class.
Posted on April 5, 2017
As a Scala developer I prefer to use Scala libraries rather than Java ones for my code. However, it is not always possible. Sometimes I might not find a required library, or I just have to use some legacy code I already have. Even though Scala runs on a JVM and is fully compatible with Java, the languages have different ideologies, different code styles and sometimes different API’s. Thus, in Scala it is preferable to use immutable case classes for the data modeling. However, in Java the common building blocks are JavaBeans, which are mutable. Another problem is that a lot of Scala libraries expect case classes. Even if they work with JavaBeans, usually you have to write some boilerplate code.
So, quite often it is easier to have a separate model in your Scala code, and converters between Java model classes and Scala ones.
BeanPurée is a library that helps you to automate this process. And it helps you to do even more, because it’s a bridge from JavaBeans to shapeless.
Continue readingPosted on February 2, 2017
In the previous
posts we
created the SqlSaver
class which can set values into the prepared
statement. It assumes that the SQL request is correct and the parameters are in the
required order (in the order they are defined in the model). What if the model class
is changed? If the query is not updated we’ll get a runtime error, since the
fields order in the query and the order of calls performed by SqlSaver
are not the same
anymore. So, it would be nice to generate SQL queries as well. Something like:
val query = StatementGenerator[Sale].insert(tableName)
val statement = connection.prepareStatement(query)
[Sale](statement, 1)(sale)
SqlSaver.execute() statement
Let’s try to implement it with shapeless.
Continue readingPosted on January 28, 2017
If you are XMonad and Firefox ESR user, just like me, you might know that there is a problem with full screen videos playback. A video hangs and you cannot close it. All you can do is just to kill Firefox. It’s already fixed in the main line, but it looks like they don’t want to port the patch to ESR version.
Fortunately the patch is not too big and I adopted it for the ESR version. Here is it:
Continue readingPosted on December 28, 2016
Yesterday I realized that there are more than ten posts in my blog. Not so many
for more than a year, but quite a lot for the index page. The simplest solution
is to just limit amount of posts with take
function, and write something like
“more posts in the archives”. But I prefer to have pagination
for the index page. Hakyll has built-in support for pagination in the module
Hakyll.Web.Paginate.
There is a very nice manual about how to use it in this blog
post.
Unfortunately, Paginate provides only first/previous/current/next/last functionality. It’s quite common to have only “Older posts” and “Newer posts” buttons for blogs, but I’d like to have a list of all pages in the Bootstrap pagination component. So, it’s time to write some Haskell code (of course you need to write code to add the standard Paginate, but I’m going to write a little bit more).
Continue readingPosted on December 22, 2016
In the previous post
I created SqlSaver
class. Later, playing with it, I found that it has
several bugs.
First of all, it doesn’t work properly with nested classes. Let’s start with a test:
case class SaleRecord(id: Int, sale: Sale, seller: String)
"save nested case classes" in {
it should val date = LocalDateTime.now
[SaleRecord].save(stm, 6)(
SqlSaverSaleRecord(1, Sale("bar", date, 42), "Shop")
) should equal(11)
verify(stm).setInt(6, 1)
verify(stm).setString(7, "bar")
verify(stm).setTimestamp(8, Timestamp.valueOf(date))
verify(stm).setBigDecimal(9, java.math.BigDecimal.valueOf(42))
verify(stm).setString(10, "Shop")
}
Unfortunately it doesn’t compile:
[error] SqlSaverTest.scala:38: diverging implicit expansion for type SqlSaver[LocalDateTime :: BigDecimal :: HNil]
[error] starting with method hlistSaver in object SqlSaver
[error] SqlSaver[SaleRecord].save(stm, 6)(
[error] ^
Note: here and later I rewrote HLists into the infix form, for readability.
Continue reading