Non-Java Language

A list of things I changed in a Scala 2->3 upgrade

implicit parameter -> using variables explicitly passed-in parameters will be passed like this: foo(using someVariable) implicit variables -> given variables implicit class -> extension Pureconfig com.github.pureconfig:pureconfig_2.13 -> com.github.pureconfig:pureconfig-generic-scala3_3 implicit def hint[T] = … -> given [T]: ProductHint[T] = … Add given ConfigReader[MyConf] = deriveReader Mockito remove org.mockito:mockito-scala because it doesn’t support scala3 mock[SomeClass] -> mock(classOf[SomeClass]) …

A list of things I changed in a Scala 2->3 upgrade Read More »

Note: Doobie’s row->case class mapping is not based on case class property name

Instead it’s based on position. To be specific, the first column in the select sql will be mapped to the first property of the case class. Here is an example: Let’s say in the db there is a table called foo_bar foo bar fff bbb This is not desirable. But the author of Doobie won’t …

Note: Doobie’s row->case class mapping is not based on case class property name Read More »

In Cats-effect, when is xxx inside IO.pure(xxx) executed?

It’s said IO.pure() means eager evaluation. But it doesn’t seem to so in this example: Here println(“print in pure”) is executed just like as if it’s IO.apply() Another example, however, discloses the truth Here is it how it works: When printTwice() is called, every expression inside it is evaluated IO.apply(println(“print in lazy”)) is evaluated as …

In Cats-effect, when is xxx inside IO.pure(xxx) executed? Read More »

Python: PIL generates an image too big?

You’ve tried thumbnail(), resize(), save(quality=20),  but you still get an image too big? Maybe it’s because you are generating a PNG file.  Change it to JPG and you will get a much smaller file ! It’s because PNG format is a lossless compression file format.  Without losing quality you can’t get a considerably small image …

Python: PIL generates an image too big? Read More »

Let Django’s migration run raw SQL

You’ve created a new column and you want set its value as the "id" column. What to do?  Add the following line to the generated migration file or you can create new migration file migrations.RunSQL(sql=”update some_table set new_column = id”)

man.get_things() or Thing.get_things_by_man() when Active Records Pattern is used?

There is requirement for a method to get things of a man.  Where to put it?   man.get_things() or   (static) Thing.get_things_by_man()  ?   From OO’s perspective, the former sounds more natural.   I was planning to adopt this approach until I found a problem:  it may lead to duplicate db access code because not …

man.get_things() or Thing.get_things_by_man() when Active Records Pattern is used? Read More »