A few of my thoughts on a few web-related issues. Feel free to contact me at michal@charemza.name or post a comment.

Avoid stateful variables

How I gently prod myself to write purer code

Coming from an imperative programming background, or working in an imperative code base, it can be tricky to write purer code. However, there is one guideline I try to follow that gently prods me in the "right" direction. Avoid stateful…

Non atomic deployments

Cron-free deferred delete of obsolete static resources

When designing a deployment strategy for your web application or site, keep in mind that browsers do not request a site atomically. They ask for the HTML, and then, some time later, ask for the resources such as scripts and stylesheets. If a…

Overriding methods is spaghetti in disguise

An argument for composition over inheritance

A common pattern I have seen is having some default behaviour in a base class, that is sometimes overwritten in subclasses, and sometimes not. class Base(object): def colour(self): return "red" class ClassA(Base): pass class…

E2E Tests: Test as a user would

Make your E2E tests less of a time-sink

This post contains a few recommendations on how to write certain aspects Protractor E2E tests. Specifically how to depend less on the internals of the page. You can't entirely not depend on internals: they all depend some amount of HTML, and…

Reasons to not use page objects in E2E tests

They can result in code that is harder to reason about

Page objects seem to have gained a bit of traction in AngularJS E2E testing, especially since they seem to be officially recommended. In this post I offer a few reasons not to use them. Your scientists were so preoccupied with whether or not…

Say no to more optional arguments

They're often smelly and biased towards historical code

Often you want to pass in an extra variable to an existing function def my_func(a): ... so it supports a new use. You usually want the old use to remain the same, so you add a optional argument with a default value. Often, in Python at least,…

Pragmatic Purity

Keep pure and impure code separate, with fewer impure code paths

The code below follows a common pattern in impure code. if (condition) { doFooImpurely(); } else { doBarImpurely(); } If you can extract out common logic from doFooImpurely and doBarImpurely into a meaningful intermediate variable that can be…

Blue-Green Deployment of Static Site on S3

API Gateway in a blue-green deployment strategy

This post contains the high level steps for the site architecture and deployment strategy for blue-green deployment for a static site hosted on S3. There are a few things that are required for a reasonable blue-green strategy. No downtime…

Defer node stream processing

Delay chain of piped streams until a promise is resolved

There might be times when you have a chain of piped streams where you want to delay a part of the chain until a promise is resolved. You can do this with a function that returns a simple Transform stream. function waitFor(promise) { return…

Animating elements moving between lists

Anchored CSS transitions to move elements between ng-repeat lists

Animating elements between parts of an application can be tricky. The beauty of ng-repeat means we can declare that a list, such as a ul, should represent a data model, such as an Array of data, and the list keeps up to date with whatever changes we…

Throttled variable changes

Delay variable changes in AngularJS templates using shadowing

Usually shadowing introduced by prototypical inheritance of $scope is something to be avoided, often the source of bugs cause by not having a dot in models. However, there is a way it can be used to throttle variable changes in templates. Thottling…

Same-domain iframe communication

AngularJS scope events for same-domain bi-directional iframe communication

It's possible for Angular apps to communicate, where one is running in an iframe of a parent, using standard scope events. This means you can treat an iframe much like a custom directive, responding to $broadcast-ed events, or $emit-ting its…

AngularJS Transclude

Break free from the DOM: move compiled elements to arbitrary locations

Transclusion allows a directive to move clone(s) of the contents of a directive to an arbitrary place in the DOM. Usually this is at the original location of the directive, wrapped in some extra elements, but it doesn't have to be. So why move the…

AngularJS Promises

Chaining, failures, notifications

AngularJS promises are an extremely powerful tool. They allow you to make a multi-layered and complex system based on asynchronous functions, with error and in-progress notification handling, all without getting into callback hell. This post…

ECONNRESET Errors in node.js

Socket.io and Express on the same port

The Problem Running a basic node.js + express + socket.io setup, I would occasionally get ECONNRESET errors. After a bit of trial and error, I found that this seems to have been caused by running socket.io and express on the same port, port…

Dependency-Based Cache Invalidation

Russian doll dependency-based cache invalidation system for PHP and Memcached. Part 1: Design.

The problem With an ever-increased user and code-base, with ever increasing amounts of data, we are approaching limits of what any single relational database can handle over at intelligentgolf. Caching output of database queries and/or generated…

About This Site

Jekyll, S3 and Cloudfront

A few technical details about this site. Front End A couple of fonts are included from Typekit. and a few Fontawesome icons are used as well. Disqus for comments, as below. Repsonsive by way of a single @media query to change the position of…

JQuery UI Datepicker Incorrect Century

On certain yearRange options

This is a known bug bugs.jqueryui.com/ticket/8873, but I couldn't find it on a search, so it might be helpful to post here. I was creating a datepicker for a date of birth field, with no default value, and with a yearRange of "c-100:c-1". However,…

Thinking Fast and Slow

A few thoughts / review

Thinking Fast and Slow is a pop psychology book, but one that leans on the academic side, detailing psychological experiments and applications of their consequences. Its main theme is how the assumptions of traditional Behavioural Economics, the…

AWS Load Balancer

Beware long POSTS: they duplicate

A word of warning to those who use AWS Elastic Load Balancing. The default configuration is that any request that hasn't had any data sent from the web server for 60 records, results in the balancer resending the request. The reason for this,…