Posts

quick note on optimizing scala.js compilation and linking

quick note on optimizing scala.js compilation and linking If you use scala.js, you probably use mill or sbt to handle the compilation and linking phases. sbt’s fastOptJS runs the scala.js compiler as a plugin to the scala compiler. Then the linker is run to create the final .js file. Both the the scala.js compiler and linker are provided as standalone CLI at https://github.com/scala-js/scala-js-cli so you can download and run the compiler and linker by hand. However, you need to add scala.js compiled jars to include external libraries. It’s not convenient to use the compiler or linker by hand if you have alot of dependencies. Also, the compiler and linker are jvm programs so they have slow startup times. Can we do better? You could use the CLI individually without needing to run mill or sbt. This would shrink, somewhat, the continuous memory overhead at the expense of compile time. You could also run bloop standalone which reduces overhead from build tools. ...

mill for dotty

mill for dotty I was putting together some content for my upcoming scalar 2020 full stack workshop in Poland and I used dotty to whip up a short data fetch programs for the AI part. I created the dotty program quite easily using sbt but as I was typing in some of the boilerplate for sbt, I thought this was perfect time to try mill–a scala build tool. Mill handles more than scala but I was specifically interested in using it for dotty. I installed using coursier by running cs install mill mill-interactive . Coursier is great! Note that mill-interactive installs the interactive version, think interactive prompt, of mill. If you install mill via the shell installer, you only have one command, mill , versus via the coursier way where you get 2 commands mill and mill-i (the CLI names). I developed the short “script” using dotty’s “main” feature and some ammonite libs that are available independent of ammonite. Mill was fast to start and easy to put a build config...

graal, scala and python together note

graal, scala and python together note If you use graal with scala and python, you can import modules but you need to do it differently. In python, the import sys is actually a statement so it has no return value to return to graal. Instead, you need to use the “function” version: Python 3.7 . 6 ( default , Jan 30 2020 , 09 : 44 : 41 ) [ GCC 9.2 . 1 20190827 ( Red Hat 9.2 . 1 - 1 ) ] on linux Type "help" , "copyright" , "credits" or "license" for more information . >> > s = __import__ ( "sys" ) >> > s . version '3.7.6 (default, Jan 30 2020, 09:44:41) \n[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]' >> > So in graal via ammonite, do: @ import org . graalvm . polyglot . _ @ val cs = Context . create ( ) val sys_module = cs . eval ( "python" , """__import__("sys")""" ) @ sys_module . getMember ( "ve...

swift on linux

swift on linux This blog is a quick note on swift for linux. swift has been designated by google as a major machine learning language. google appears to be rewriting tensorflow in swift. More info is here: https://www.tensorflow.org/swift . While python is not going away, they are working hard in making python a smooth integration, much in the same way that the graal project is integrated in multiple languages into the jvm platform. When you want to run python code in swift, the tensorflow example on their web site assume you are use google colab which already has the swift-python interop module installed. You can also install “swift for tensorflow” from binaries provided on github. Check out https://github.com/tensorflow/swift/blob/master/Installation.md for instructions. If you are not using ubuntu, you may be out of luck as the build process for tensorflow can be complex. If you are able to install this version, you will get a swift version that already has...

sbt plugin to generate apollo graphql scala sources

sbt plugin to generate apollo graphql scala sources I modified the apollo-codegen-scala sources to output generic scala sources. At the moment, it is dependent on slinky. With my changes it is not dependent on slinky. Along the way, I created a plugin to generate the sources from the npx apollo codegen:generate command. Since it is my second plugin I’ve ever written, it took forever to write. There is an add occurance in that the JvmPlugin reset the sourceGenerators setting. Tracknig that down cost me a day of time. Anyway, the plugin is below and I’ll try to turn it into a real plugin shortly. For the moment, just copy this into a .scala file such as [your project]/project/apollo_codegen.scala and add the plugin to your project. Read the keys below to see what settings are available. If you need see the actual command generated, use the sbt last command or turn on debugging for this task via [your project]/Compile/apolloCodeGenerator/logLevel := Level.Debug ...

simple graphql with scala.js, zio and apollo-server-express

simple graphql with scala.js, zio and apollo-server-express WIP - please ignore this blog until its done or check back periodically for new content. REST is a bit on its way out, if its not out already. Graphql has been where the action has been at for a few years now. graphql is relatively easy to use and significantly more express than say, odata. It’s relatively straight forward to create a simple graphql server that uses a RDBMS behind the scenes. If you use the express version of the apollo server library you can get instant reload, solid debugging and other features that makes it easy to use and adopt. While express is not multi-threaded, it may be good enough as a solution. There are quite a few graphql libaries: apollo-graphql-express: From community and a backing company. graphql-express: From FB + Relay. graphql-yoga: Dev friendly, fast starter graphql database. sangria: scala calahan: scala + zio (newer) …endless list by language… We will use ...

http server: node.js, express, zio, error channels, mixed code base

http server: node.js, express, zio, error channels, mixed code base This is a quick blog on integrating zio into node.js+express and scala.js. It also shows you how to align the zio error channel with the semantics of the domain. An explicit goal is to enable scala.js and zio in a mixed code base. You would normally create a http server using one of the many scala+jvm based libraries. play, cask, akka-http or http4s. They are all good and integrate well with scala. Most of them allow you choose the underlying java http server library. The scala layer is typically an API layer on top. I like the idea that cask is focused on making it quick and simple to build websites even although cask is not asynchronous. Allowing you to start small and quick then incrementally build out your server’s logic is a good way to get programmers started and allow them to grow their usage as their understanding of the API increases. node.js+express is like that. Although it is easy to ...