Month: September 2018

Swift 4: An extension to define UIColors with “normal” RGB values and set some named colors

UIColors require you to enter red, green and blue as values between 0 and 1. In pracitcal terms that means you need to divide your values by 255 to obtain the CGFloat required. Easy enough? Surely! Still it is a tad annoying, especially as the rest of the world will give you RGB values between […]

Swift 4: Pull To Refresh / UIRefreshControl

TableViews can have a useful feature to refresh the data inside of them, simply pull to refresh. Apple didn’t invent this, that was Loren Brichter of Tweetie, which was sold to Twitter and Twitter was eventually granted a Patent for the feature. Today this feature is absolutely ambiguous and very easy to implement. For example, […]

Swift 4: scale image to width

For an app that I was writing I needed an easy function to scale an image to a specific width, the function below will accomplish this: func scaleImageWidth(sourceImage:UIImage, scaledToWidth: CGFloat) -> UIImage { let oldWidth = sourceImage.size.width let scaleFactor = scaledToWidth / oldWidth let newHeight = sourceImage.size.height * scaleFactor let newWidth = oldWidth * scaleFactor […]

PHP – use a regular expression to extract a URL from XML attribute

I was working on an API response, which provided data in a custom XML markup within the string, which was returned. I wanted to simply extract the “linkTerm”. The snippet I got looked like this: <link linkTarget=”URL” linkTerm=”″ linkWindow=”_blank”>Online-Zugang</link> Now surely there will be more elegant ways of doing it, but I felt that I […]

PHP – removing unwanted XML from string

Yesterday I was working on a small PHP script in which an API sends “xml” within the response. That XML is supposed to make handling the data easier, but to be fair I just didn’t need it. This is the snippet that the API returned <searchLink fieldCode=”AR” term=”%22Krugman%2C+Paul+R%2E%22″>Krugman, Paul R.</searchLink> At first I tried to […]

Scroll to top