Building a Slack Bot in PureScript

I recently open sourced my first large PureScript project. It’s a slack bot that allows searching for cards from the Epic Card Game. In this post, I’ll discuss the process of writing the application, what went well and what went poorly. An Overview of the Slack Bot I was excited about building this project in PureScript because it was complicated enough to be interesting but not so complicated as to be overwhelming. The key requirements for the bot were: ...

January 31, 2020 · Drew Olson

PureScript Async FFI

I recently posted about using Aff for asynchronous effects in PureScript. In this follow-up post, I’m going to discuss using JavaScript FFI in conjuction with Aff. Aff and FFI PureScript gives us very nice FFI utilities to call JavaScript code. Aff provides a function called fromEffectFnAff that lets us turn asynchronous JavaScript behavior into an Aff in our PureScript code. Let’s create an example that reads a file from the file system using FFI. We’ll pass our foreign function a String and expect to get back an Aff String of the contents of the file. ...

January 4, 2020 · Drew Olson

Asynchronous PureScript

One of my favorite features of PureScript is its ability to work with asynchronous effects. While learning the language, I struggled to find any beginner material that introduced the relevant topics and included small examples. This post hopes to fill that gap. Getting Started with Aff PureScript’s built-in type for effects is called Effect. However, this type represents synchronous effects. This means if we want expose asynchronous APIs to our users using Effect, we’re stuck with the callback-style. Here’s a contrived example that “slowly” adds two numbers together using Effects: ...

December 17, 2019 · Drew Olson

Laziness in PureScript

I’ve been learning PureScript for the past few months and really enjoying it. PureScript is a Haskell dervied language that compiles to JavaScript. You can target node for the backend or the browser for frontend code. One of my favorite features of PureScript is its fantastic interop with JavaScript. This makes the language very pragmatic – though it has a large ecosystem of native packages, anything that’s missing can easily be handled with an existing npm package and interop. PureScript made a big departure from Haskell in order to make this interop more convenient. While Haskell is a lazy language by default, PureScript is strict. ...

June 19, 2019 · Drew Olson

Go Dependency Injection with Wire

Several months ago I wrote a blog post about dependency injection in go. In the time since that post was written, Google has released a fantastic new dependency injection container for go called wire. I much prefer wire to other containers in the go ecosystem. This post will explain why. A (Very) Brief Primer on Dependency Injection Dependency injection (DI) is a style of writing code such that the dependencies of a particular object (or, in go, a struct) are provided at the time the object is initialized. ...

April 7, 2019 · Drew Olson

Concurrent Ruby with Tasks

Yes, you read the title correctly. And yes, ruby still has a GIL. However, ruby has long been able to support concurrency for IO-bound calls. Ruby will not block the current thread if it is waiting on IO. In practice, this means that many of our ruby programs (like web applications) can use ruby’s threads to concurrently serve multiple requests. Working directly with ruby’s threading primitives can be complicated. This is a problem that the concurent-ruby library aims to solve. This library is mature and comprehensive but it offers a staggering number of APIs for modeling concurrency in your application. ...

October 29, 2018 · Drew Olson

So You Bought a Pixelbook

Initial Setup First, follow the Quickstart instructions here. You now have two things set up – a VM called termina and a container inside of that VM called penguin. This VM and container are “special” – files within penguin are accessible via the Files app and any GUI applications installed inside of penguin will be accessible via the launcher. Other than that, penguin is just a regular debian stretch LXC container. To access a shell inside of pengiun (which is inside of termina), simply launch the Terminal program. This starts the termina VM (if not already started), starts the penguin container (if not already started) and drops you in a shell. ...

June 16, 2018 · Drew Olson

Lazy Providers in Dig

If you haven’t yet read my previous post on depedency injection in Go, please do so first. This post describes a simple technique to make dig’s DI container even more powerful. All values provided by dig’s container are singletons. The provider is called the first time the value is required and the result is cached. All subsequent providers that depend on this value used the cached result. This behavior is usually very desireable but there are times when we want a fresh value to be produced by the container. Often this is useful for data that is scoped by a lifecycle that is shorter than the lifecycle of the application itself (say, the lifecycle of an HTTP request inside of an HTTP server). ...

May 25, 2018 · Drew Olson

Dependency Injection in Go

Update - you should probably read my more recent post about dependency injection with wire. I recently built a small project in Go. I’ve been working with Java for the past few years and was immediately struck by the lack of momentum behind Dependency Injection (DI) in the Go ecosystem. I decided to try building my project using Uber’s dig library and was very impressed. I found that DI helped solve a lot of problems I had encountered in my previous Go applications – overuse of the init function, abuse of globals and complicated application setup. ...

May 15, 2018 · Drew Olson

Promises as Values

I was recently working on a small JavaScript project in which I needed to perform several asynchronous operations sequentially. I had a collection of images on a page and I needed to fade each of them out one at a time. I ended up with a nice technique using Promises. Let’s suppose we have a function that fades out an image given a selector and a duration (I was using jQuery, but the details don’t matter). We can call this function like so: ...

July 13, 2017 · Drew Olson