How to change Windows/DOS line breaks to Unix style with Vi

I had a file that was edited in Windows, so it had CRLF line breaks. It was a script and I had to change the line breaks to LF before I could run the script in bash. I converted the line breaks to Unix style using the vi editor and…

How to verify if server supports TLS 1.2

I was implementing an Apple Pay functionality for a website and one of the requirements was that the server must support the Transport Layer Security (TLS) 1.2 protocol. There was an easy way to check that from MacOS command line. openssl s_client -connect example.com:443 -tls1_2 I got a certificate chain…

How to set a port number for Vapor server on localhost

Vapor defaults to port 8080 on localhost. I couldn’t use the 8080, since that was reserved for another server on my MacBook Pro. Here’s how I set a different port number from the command line. swift run Run –hostname localhost –port 9000 This works with Vapor Framework 3.0.8 and Toolbox…

Using DispatchSemaphore to control asynchronous resources

A counting semaphore is a way of controlling access to a resource from multiple contexts. It can be also a solution for handling asynchronous methods in command line utilities. I was making a command line utility to access REST APIs recently. I needed a way to make sure that the…

How to make a progress bar for WKWebView

Progress bar is a nice way of showing users that our app is downloading content and things are progressing. The progress bar can be placed anywhere on the screen, but it is usually a thin line just under the navigation bar. We can create a progress bar programmatically and set…

Debugging Auto Layout: Unsatisfiable Contraints

When we work with auto layout we will hit an unsatisfiable constraint error at some point. The result is a view that looks somehow broken and there are a lot of text in the Xcode’s debugger window. The unsatisfiable constraint error means that there are some conflicting constraints and the…