Posts

First look at terraform

Terraform is client based like Ansible (which is good). Very cloud focussed and relies on Cloud API's to manage the infrastructure. This is good as it means you dont have to worry about authentication and ports etc but it does need to be a supported cloud vendor. You couldn't use it manage your own on-premise servers (presumably). Example config file: provider "aws" {   access_key = "AKIAIFZVQTBBG3YF46LQ"   secret_key = "SfEjiU0I2I7wxXQqbRWLPYCbEfdSxhI/4r44CgaV"   region     = "us-east-1" } resource "aws_instance" "example" {   ami           = "ami-2757f631"   instance_type = "t2.micro" } > terraform init > terraform apply > terraform show  Terraform is purely declarative. Ansible IS declarative but you need to be disciplined as it can be used imperatively. One blog calls Terraform an 'orchestration' tool with ansible being a more traditio

A brief look into Cloudformation

Image
In this blog, i just wanted to record details and my thoughts on following a first tutorial on Cloudformation. This is the free AWS offering for managing and provisioning infrastructure resources within a cloud environment - effectively their IaC service. A cloud formation template describes a group of resources that form a stack. Resources can references resources within the template or outside of the stack entirely. Template can be written in JSON or YAML. A stack is free in AWS but the resources within are priced as normal. Templates have several useful features: * Parameters * Mappings for conditional values (eg AMI ID's differ between regions) * Functions can be used to join values etc * Output values Ultimately i would like to compare and contrast with Terraformer. Updating a stack This tutorial describes how to update a stack implementing a sample PHP app on apache. MetaData/Init section for an EC2 instance allows you to specify things like which packages ar
Factory functions New keyword creates a new object sets the this context to the new object good examples at  https://stackoverflow.com/ questions/1646698/what-is-the- new-keyword-in-javascript    Factory function any function that returns a new object (just done manually) createUser : function(username) {       return {           name: username       } }
https://simonsmith.io/dipping-a-toe-into-functional-js-with-lodash-fp/ Great blog on Functional programming. For me does an excellent job of highlighting the difference between pure functions and bonified functional programming. lodash fp is a wrapper around lodash to provide immutable, auto curried, iteratee first data last functions. Currying seems to make sense here, just functions that return a function. The data param is often omitted at the end to make the function more re-usable. Currying, just keeps returning a function until it has all the arguments. This is why it makes sense to have the data arg last so it can be provided last. I still can't see the functional programming being realistically easier to use but pure functions definitely make a lot of sense.

Stubbing constructors in JS

If a  constructor is exported directly from a module, it cannot be stubbed in any module that requires it directly. For instance ========= MyConstructor.js ========= module.exports = function(){    console.log('MyConstructor called');  }; and a SUT ========= MyConsumer.js ========= var MyConstructor = require('./MyConstructor'); function MyConsumer(){     this.useful = new MyConstructor(); }; module.exports = MyConsumer; You cannot stub the constructor. From my understanding the ECMAScript spec doesnt provide hooks for the new() operator.  Lets look at some workarounds. 1) Use an init method. This involves using a constructor which calls an init() method. The init() method can then be stubbed out in the usual way.  2) Stub the constructor using rewire // in "dependency.js" module . exports = function ( args ) { return new Dependency ( args ); } // in "foo.js" var dependency = require ( &#

Measuring execution time

Image
To measure the time take to run a section of code: > console.time("toggleSeries"); ... > console.timeEnd("toggleSeries"); Where the parameter is any label you want. Gives the following output: