What does ES6’s spread operator (…) do and what can you use it for?

Some language features are easy to guess what they do even if you’re unfamiliar with them, but it’s not immediately obvious what the ES6 spread operator ‘…’ does.

Here’s a great article that gives some practical examples of how you can use the spread operator, for example, to:

  • insert one array into another
  • copy the contents of an array
  • convert a String into an array of chars

Rendering arrays of Components with React

React doesn’t support the use of a for() loop in it’s render method. If you need to render a list of components based on data, one approach is to build a var representing the list of components in a helper function as described here.

Another approach is to use .map() to build an array of Components from an array of values, like this:

this.state.grid.map( (cell, index) => (
<CellComponent key={index} value={this.state.grid[index]}
onChange={this.handleChangeForArrayFields.bind(this, index)}/>
)
)}

In this example, this.state.grid is an array containing values to map to each rendered value attribute on my Component. Each rendered element needs to be unique, so we add the key attribute, and set it to the index from each element that comes out of the map function.

I’ll look at the onChange handler in a followon post.

Kubernetes: installing helm tiller with RBAC role and service account

From here.

kubectl create namespace tiller-world
kubectl create serviceaccount tiller --namespace tiller-world

role-tiller.yml:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager
  namespace: tiller-world
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]

rolebinding-tiller.yml:

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-binding
  namespace: tiller-world
subjects:
- kind: ServiceAccount
  name: tiller
  namespace: tiller-world
roleRef:
  kind: Role
  name: tiller-manager
  apiGroup: rbac.authorization.k8s.io

helm init with service account and namespace:

helm init --service-account tiller --tiller-namespace tiller-world

Combining with tls certs (from here):

helm init --tiller-tls --tiller-tls-cert ./tiller.cert.pem --tiller-tls-key ./tiller.key.pem --tiller-tls-verify --tls-ca-cert ca.cert.pem --service-account tiller --tiller-namespace tiller-world

Does use of Twitter discourage exploring ideas in greater depth?

Twitter makes it incredibly easy to share random thoughts and links to topics of interest. For me personally, this is the main attraction of using Twitter, but the drawback of the brevity is that it discourages exploring and expanding a thought beyond 280 characters (how did we ever survive with only 140 characters?!)

After posting a short sentence about something I’m thinking about or have recently read elsewhere, I usually think “I could write a whole article on this single topic”. For example:

I could have easily taken this idea of open office spaces having the opposite intended effect on worker productivity and explored this in more depth in a longer article, but instead captured this thought as a single paragraph and left it at that.

In this sense I think Twitter makes us lazy. It makes it easy to quickly share a quick thought, but in doing so we throw out these nuggets of info and then leave them there, unexplored.

I don’t make New Years Resolutions, but if there’s one thing I plan to do more of this year, it’s to spend more time writing more articles, and less time sharing quick, throwaway thoughts.