The Japanese yen’s exchange rate took a nosedive this year, and my monthly cloud costs for running a tiny beach recommendation site ballooned from “I can ignore this” to “this is getting silly”. instabeach.io 1 , a site I built a decade ago to help my wife and me find beach destinations based on weather and travel dates, was running on a Kubernetes cluster that started to cost more and more per…
This blog was started almost 11 years ago, on Octopress 2.0. It was a different world: Ruby 1.x was king of the hill, and Docker wasn’t even a thing yet. It was an amazing thing to use. Over the years, every time I switched machines, I noticed it was getting harder and harder for me to get the blog and in particular Octopress 2.0 working on it. It was plagued by incompatibility between system…
Have you ever wanted to write a structurally typed function in Rust? Do you spend a lot of time and effort getting your Rust struct s just so , and want to DRY-out data access for common field paths without declaring a new trait and implementing it for each struct (let’s say, Cat and Dog both have a name: String field)? If so, read on. This post talks about how we can leverage LabelledGeneric to…
The 1st year anniversary of my first line of Rust code is coming up, and it’s getting for 5 years since I wrote my first line of Scala code. I thought it would be a good idea to summarise my Scala-tinted perspective of The Rust Experience TM , one year on. Rusty spiral staircase by Jano De Cesare This is not an objective language vs language comparison. I’ve written this post as part experience…
The last several posts have introduced a number of abstractions, namely HList, Generic, LabelledGeneric, as well as pluck() and sculpt() . Although each of those have impressive party tricks of their own, I’d like to share how you can use them to write a reuseable, generic function that handles converting between structs with mis-matched fields and thus have different LabelledGeneric…
Getting the type signature right was 99% of the work in implementing pluck and sculpt for HList s in Frunk. Here’s what I’ve learnt along the way: what works, and what doesn’t work (and why). As you may already know, Rust eschews the now-mainstream object-oriented model of programming (e.g. in Java, where behaviour for a type is added to the type/interface definition directly) in favour of a…
What is LabelledGeneric ? How does one encode type-level Strings in Rust? What is a labelled HList? Hold on, let’s take a step back. In a previous post about implementing Generic in Rust , I briefly mentioned the fact that Generic could cause silent failures at runtime if you have 2 structs that are identically shaped type-wise, but have certain fields swapped. While we can work around this using…
Have you ever wanted to convert Hlist s into Structs or to reuse logic across different types that are structurally identical or very similar (e.g. same data across different domains)? Generic can help you do that with minimal boilerplate. Generic is a way of representing a type in … a generic way. By coding around Generic , you can write functions that abstract over types and arity, but still…
Rust describes itself as: a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. ### Featuring * zero-cost abstractions * minimal runtime *efficient C bindings So, it’s likely that developers who choose to program in Rust are focused on performance. You can make sure your code is efficient by writing benchmarks, but in order to prevent…
Rust comes out of the box with a Result<T, E> type in its standard library. For those not familiar with it, it is a union-like enum type where T is a type parameter denoting the kind object held in a Result in the success case ( Result::Ok<T> ), and E is a type paramter denoting the kind of error object held in the failure case ( Result::Err<E> ). In Scala, this is represented in the standard…
A heterogeneous list (henceforth “HList”) is a useful abstraction that is implemented in many statically-typed functional programming languages. Unlike normal list-like structures (e.g. Vec , Slice , Array ), a heterogenous list is able to hold elements of different types (hence heterogenous) and expose those types in its own type signature. 1 2 let h = hlist ! [ "Joe" , "Blow" , 30 , true ]; // h…
It’s been a while since the last major release of Enumeratum , and in 1.4.0, minor changes include Play 2.5 support, integration library version bumps, and small internal refactorings. More excitingly though, the latest version adds support for a new kind of enumeration, ValueEnum , as well as an integration with the Circe JSON library . Points of interest: Unlike other value enum implementations,…
In Episode 1 of this series on Scala and computer vision, we created a basic Akka-Streams-powered webcam feed app. To bring it to the next level, we will dig a little deeper into the OpenCV toolset and bring in feature detection as well as video stream editing. We will build on the foundations from the previous post and continue with the usage of Akka Streams, modeling our application as a series…
In a previous post , I talked about SBT-OpenCV, a plugin for SBT that makes it easy to get started with OpenCV in any SBT-defined JVM app using just one line in project/plugins.sbt . Having handled the issue of getting the proper dependencies into a project, we can turn our attention to actually using the libraries to do something cool. This post is the beginning of a series, where the end goal is…
OpenCV is arguably the defacto free, open-source computer vision library, but setting it up for usage in a JVM project can be hard because OpenCV itself is written in C++, so there are a bunch of system-dependent things that you need to download/compile/install before you can use it. JavaCV , written by Bytedeco is a library that makes it more bearable to use OpenCV from JVM projects by providing…
Play is one of two officially-supported web frameworks from Typesafe, the company behind Scala (the other is Spray ). It runs on its own webserver, is non-blocking, and encourages the use of idiomatic Scala. It is often compared with Rails because of its emphasis on convention over configuration and because it’s a full-on framework that comes with most of the bells and whistles needed to build a…
If you’ve been working with Scala for a while, you might have come across a few “problems” with the built in Enumeration that’s provided out-of-the-box. This is especially true if you have colleagues who come from a Java background and yearn for the Java-style Enum that gave them lots of power and flexibility. A quick search on the internet for “Scala enumeration alternative” will yield a lot of…
Last week, I decided to take a stab at learning Scala macros . I had played around with macros when I wrote Scheme for a living (yes, believe it or not, these places exist…and existed long before Clojure made Lisp hip again), but the complexity of Scala’s macros always put me off (if you don’t believe me, check out the example given in the offical docs for a simple print macro ). In Scala, things…
A couple days ago, I released v0.1.3 of Schwatcher , which introduces the ability to monitor events on file paths using a composable Rx Observable interface. “What does that even mean and why should you care?” is what this blog post tries to answer. The original version of Schwatcher allowed you to tell a MonitorActor what callback you want to fire when a certain type of event happened on a file…
Version 0.1.3 of Schwatcher has been released. This version brings a new Observable interface that exposes a “stream” (or channel) of EventAtPath s that can be composed. Using this interface, you no longer need to register callbacks - you simply register paths and get notifications for events on them either by subscribing to the Observable or by composing. For more information on how to use…