Null Safety firstWhere

The change to null safety in Dart is a good thing, however a common pattern I used firstWhere for got broken. The pattern is to search a collection and return null if the search returns nothing. The short answer is that you should use firstWhereOrNull instead in this case. Example of the Issue Before the null safe version of Dart the code would look like this: The naive conversion to null safety would be: But this conversion will show a warning that the test if ( null == val ) is not required because the value can’t be null. What’s [Read on…]

GOLANG unexpected directory layout error

I got this error trying to compile some GO code today and the usual searches didn’t immediately turn up the answer to my issue. The error output made it seem that something was wrong with the path setup in my GO environment which lead me into a dead end of searches and attempted resolutions. The actual problem was very simple. I was importing with a path relative to the project directory and GO no longer approves of that. All import paths should now be relative to the src directory within the directory given by the $GOPATH environment variable. Bad, don’t [Read on…]

Java Object Creation is Very Fast

I was recently doing a code review and suggested some refactoring to extract some behaviour into separate classes. A common question came up, “This code has to be fast so shouldn’t I avoid object creation?” My instinct is always no, ignore those considerations when coding, let the compiler handle it until proven that you have to step-in. This time I avoided my laziness and cross checked that instinct. The top result on a quick search said that object creation should be avoided due to expense, but mentioned a Pentium II so I was suspicious. I’m not going to link to [Read on…]

OAuth2 – Get a Token Via REST Google Sign In

Every time I want to get an access token for a REST service for an integration test or other non-interactive use I forget how to go about it using OAuth and then have to piece it back together. My use case is wanting to give some headless process access to a user level service like Google Calendar. This post is now my permanent memory of how to do it, I hope it helps someone else. The Steps Get an account on the service Define the client for OAuth access – example using a Google API Get the code using an [Read on…]

Widget Testing and Flutter 1.20.1

After the upgrade to Flutter 1.20.1 none of my widget tests worked anymore. On investigation I found that my widgets weren’t getting rendered at all, i.e. their build method wasn’t being called. This is a preliminary result but I was doing this in my test: Seems like that no longer works and must now be: I haven’t seen anything in the release notes that suggests this should be required. I’m still investigating but in case this helps someone else I thought I’d put it out there.

Custom Domains for AWS API Gateway Without Route 53

There’s some very good articles on using the Serverless Framework to setup custom domains for API Gateway endpoints. For my use case I wasn’t planning to use Route 53 for DNS hosting for the domain so they were missing a crucial step. This post documents that step. Configuration Follow the article linked above to setup the plugin and basic configuration. The configuration for the custom domain in theserverless.yml file is almost exactly as shown in the article with the exception of the createRoute53Record line which I changed to turn off the Route 53 DNS interaction. Setup Steps With that change [Read on…]

Compressing POST Requests in Flutter

Posting to REST endpoints from mobile applications is a very common use case. Some of those POST requests can get a little large and it can be useful to compress them before sending to save the user some data. It turns out to be very easy to do this compression in Flutter and I didn’t find resources for it when I went looking so I thought I’d record the steps I took. Code Example This is pretty much just the standard example of using POST. The two things that need to change to send compressed content is to add the [Read on…]

‘What’s My Name’ for Serverless Framework

It is frequently useful to know the name of a generated resource in the Serverless Framework when building for AWS. I had been struggling with this when I needed to refer to a generated resource in a separate CloudFormation section. After much searching I found a very useful trick that is probably already well documented but I’ll add my small bit of amplification here. Finding the Generated CloudFormation Serverless works by generating a CloudFormation template based on the serverless.yml file. This generated file is accessible in a hidden subdirectory of the directory that contains the serverless.yml file if you run [Read on…]

Handling permission requests in Android for Flutter plugins

Updated for the new plugin registration process in Flutter 1.12. While building the Android functionality for a plugin recently I had to handle a system permission request. Although all the parts of that are simple it took me a while to figure out how to put them together. In hopes of making it simpler for others looking to do this here’s all the bits in one place. Note: Code examples are Kotlin, there’s a full gist here. The gist is for pre 1.12, I’ll try to get a post 1.12 gist up in the next little while but until then [Read on…]

DST Dart and DateTime & How to Unit Test

Like all programmers I have a pretty long held grudge against daylight savings time, leap years, time zones, and just generally anything to do with dates and times. The ways in which date complexity have hurt over the years are many and varied. This year’s pain provided a good opportunity to use the excellent unit test support for time in Dart. This post is a tiny bit about date calculations and mostly about how to get control over dates in tests. What Went Wrong This Year This is the history and context part of the post. If you just want [Read on…]