Learning Java 8 Streams

I’ve never had a good opportunity to use Java 8 Streams since traditional iteration approaches always seemed to be appropriate for what I needed. Working on my Sudoku related projects (in particular an implementation of a Human Solver) I needed an approach to count occurrences of numbers in Lists and also find where pairs existed in Lists.

To get started, I started with a number of simpler examples to gradually work up to what I was looking for. I’ve collected a number of my examples in this project here.

Creating a new AWS Lambda project with Serverless

Assuming the Serverless cli is already installed (here), init a new project with ‘serverless’ and answer the following questions:

% serverless       
 Serverless: No project detected. Do you want to create a new one? Yes
 Serverless: What do you want to make? AWS Node.js
 Serverless: What do you want to call this project? lambda-example
 Project successfully created in 'lambda-example' folder.

To deploy, run ‘serverless deploy’

AWS CloudFormation basics – part1

Collection of notes, templates and tips for building AWS CloudFormation templates.

The basic structure of CloudFormation files (in JSON):

{
  "Resources" : {
    "ExampleResourceName" : {
      "Type" : "AWS::?::?",
      "Properties" : {
        "Example" : "propertyvalue"
      }
    }
  }
}
  • Resources: the AWS services to be provisioned. There can be multiple repeating Resource elements in this section, to provision/configure multiple services in a stack
  • ExampleResourceName: a name for each resource being provisioned
  • Type: the AWS type for the resource, e.g. AWS::S3::Bucket
  • Properties: properties for the service being provisioned/configured

AWS CLI commands:

aws cloudformation create-stack --stack-name STACK-NAME
  --template-body file://template-file.json
  --parameters ParameterKey=example1,ParameterValue=value1    
    ParameterKey=example2,ParameterValue=value2
aws cloudformation list-stacks
aws cloudformation delete-stack --stack-name STACK-NAME

If your stack creates IAM resources, you’ll also need to pass:

--capabilities CAPABILITY_NAMED_IAM

Otherwise you’ll see this error:

An error occurred (InsufficientCapabilitiesException) when calling the CreateStack operation: Requires capabilities : [CAPABILITY_NAMED_IAM]

Bulk converting image file formats with MacOS Preview

The Preview app on MacOS has a ton of useful features, from annotating images to converting file formats. Recently I had a bunch on .png screenshots that I needed to convert to jpegs. While I was aware you can Export an image file in Preview and save it in any other supported format, I was looking for a quicker way to bulk convert a large number of files.

Turns out, as explained in this article, if you select a group of images in Finder and double-click one of them to open them all in one go, you can select all the images from their thumbnails on the left:

… then from File click ‘Export Selected’. From the dialog chosoe where to write the converted files, and press Options button to change the file format. Done!