I write about software engineering and technology in general.

Calculating Color Contrast Ratio in Swift

When it comes to dynamic templating of apps sometimes it’s helpful to determine at runtime if two colos have enough constrast so that one can be the background color and the other the foreground color. The W3C defines in it’s Web Content Accessibility Guidelines (WCAG) 2.0 a formula to find this ratio. Let’s take a look on how to implement this calculation using a Swift UIColor extension. We start by creating a simple UIColor extension:

Swift Essentials - Remove Duplicates

Swift Array contains a lot of quality of life functions that help the developer code operations on Array elements. One thing that the Swift Standard Library falls short is in it’s ability to remove duplicates from an Array. By leveraging Swift Extensions we can create a function that enhances the Swift Array built-in functionality to remove duplicates, provided their element conforms to the Equatable protocol. We begin by writing a Swift Array Extension, specifying that it should only apply if the Element conforms to Equatable.

Swift Essentials - UIColor from Hex

While working on a past project, a requirement was to set the background colour of a button with a specified colour retrieved from a REST API endpoint. This colour was a HEX string value in the format #FF0000. Unfortunately, UIKit has no UIColor constructor that receives a colour in the Hex format, so I needed to implement a way to achieve this. Firstly we need to understand what colour in the Hex format is.

Leaving Facebook, at long last

It’s long overdue. The reason I have lasted so long in Facebook is the fact that a lot of my contacts I find only there. But since all of them have mobile phones and email I realized that’s just convenience, and so, it ends. Give people the power to build communities and bring the world closer together ¹ Facebook’s mission. A bunch of PR good looking, heart appealing bull shit. Facebook connects people to Facebook.

Writing C#’s Rfc2898DeriveBytes in PHP

Recently I came across a third party backend writen in C# that encrypted small pieces of sensible data for storing in the database with AES-256-CBC. The piece of code responsible for the encryption and decryption can be found at the bitlush blog (kudos to the authors). This backend would send this encrypted information to our backend system writen in PHP, and it was our responsability to decrypt those pieces of data on our end, and so we had to effectively at least write the decrypt function exactly the same way as the C#’s counterpart.

How VIPER changed iOS development

(At least for me…) I have been developing iOS apps for the past 5 years, much has happened then in the world of iOS development. Objective-C is starting to (slowly) be replaced with Swift and if you don’t master Auto Layout yet, you should definitely consider it heavily. However as much as something changes I always have this gut feeling, that programming for iOS could be done better, cleaner, and that it has nothing to do with the OS itself, or even how Apple develops their APIs, but instead how you think your code, and ultimately how you structure it.

Why care about your online privacy?

Ever wonder how Google can give the world amazing and above all free software? How can one, who apparently gives everything for free make, last year alone, a 16 Billion dollar net income? Well, Google sells advertisement, and they are damn good at it. Why? Because they know more about you than you probably know about yourself. Credits to the author In 2015 I watched a talk by mikko on re-publica entitled “Is our online future worth sacrificing our privacy and security?