Sitting at a Street Bean – coffee shop right next to my work. I started at Code Fellows a little less then a year ago thinking this will be my long term gig. Since then I’ve met a lot of energetic software engineers, passionate management… essentially people who care about changing people’s lives for the greater good… this is my last week here. Next week I start at Nike.
In addition to teaching iOS, I have spent the time covering data structures and helping students get ready for interviews. Learning how to “code” is only half the battle… I am sure most of my friends would agree.
What I’ve noticed is that typical interview questions evolve around Linked Lists, Palindromes, Base Conversion, Binary Search trees, etc. You might never use these data structures in production, but they come up quite often on interviews and thus are important to know if you want to get a job. In this article I will cover 3 questions and write implementation in Swift 3. Linked Lists topic has been covered pretty extensively already by other developers… I won’t bother.
Continue reading “Palindromes, Base 16 & Roman Numerals”
Some time ago, my friend Monty and I considered integrating Medium API into our app, in.notes. At that time their API was relatively young and unpolished.
A couple of days ago I decide to take another look at it. What started as a single class with two functions for token retrieval turned into a full blown OAuth client with Keychain support. If you would rather skip the explanation and go straight to sample code, here it is!
I should mention that I tried keeping my implementation somewhat flexible to support other APIs. I agree that it would have been much better to work with at least two end points to map out similarities, my current implementation can be modded with relative ease in the future.
Continue reading “Medium OAuth Client for iOS”
Generics are awesome. In fact, they are insanely cool when it comes to writing reusable code. To demonstrate their usefulness, let’s build a generic Cache storage.
Our cache should meet the following requirements:
- Should be fast (read, write) – O(1)
- Support hashable data type (NSData, UIImage, String, Int, etc)
- Support custom size to allow for initialization based on memory limitations
- Should keep track and clear out oldest objects before adding new ones
- Should keep recently accessed data by marking it as the most recent
Before writing code, let’s talk about implementation. For starters, I will use a dictionary to store the actual data. Reason behind using a dictionary (or a hash table) should be rather obvious… both the lookup and insertion of data takes constant time. This will be especially useful when dealing with large cache size.
Continue reading “Swift Generics – Cache”
It [Swift 3.0] is inevitable. – Agent Smith
We are getting pretty close to the release of Swift 3.0. Part of me is very excited (fifty percent of me, to be precise). Since a few of my projects are completely written in Swift, no Objective-C, I decided to dive into Swift 3.0 with the release of a toolchain snapshot. I was particularly interested in quantifying the amount of effort it will require to update my apps (I like to migrate my code manually and see new changes rather then using auto-migration tool shipped with Xcode).
Needless to say, my project secretly named “Cobra (think of Jesse from the Burn Notice) – Update to Swift 3.0” wasn’t successful. It is way too early. I still managed to get a simple project setup and got myself familiarized with the new syntax – awesome. By the way, Playgrounds don’t work.
If you are interested, here are simple steps on how to use the Swift 3.0 Preview Toolchain in current version of Xcode (7.3.1).
First of all, head over to www.swift.org and download the latest snapshot (direct link here).
Once downloaded, run the package installer. This will install the new toolchain. Next, you’ll need to go to Xcode / Toolchains and select Swift 3.0 Preview 1 Snapshot. You’ll be asked to restart Xcode…
From here, it is time to test the waters and create a new project. I would suggest starting with a Single View Application template… a couple of warnings and compiler errors later, you are on your way to write your code.
Happy Swift 3.0 writing…
UPDATE: I successfully updated my project to Swift 3.0.
Unbreakable encryption is possible. Welcome to One-time Pad or what also referred to as “the perfect cipher”. To be honest, it is comforting to know that it is possible to encrypt text conversations to the point where it is practically impossible to decrypt without having the correct key. While the previous two ciphers mentioned earlier (Caesar Cipher and Vigenere Cipher) provide a way to scramble text into “gibberish”, both can be easily decrypted using pattern matching without needing the original key.
Unlike previous crypto algorithms, Vernam uses random key composed of random numbers to encrypt text. It is a very simple, yet powerful algorithm as you will see shortly.
Continue reading “Vernam Cipher in Swift”
Here is another classic cipher in Swift. This time it’s Vigenere. Similar to the way Caesar cipher works, Vigenere cipher improves on a couple of things. If you can recall my previous article, Caesar cipher works by shifting each letter in the plaintext a certain number of places down the alphabet. Vigenere cipher tries to improve on that approach by utilizing the keyword to offset each plain text letter by the keyword letter. This, of course, requires the keyword to be of the same length as the plain text.
Continue reading “Vigenere Cipher in Swift”
If you are at all interested in encryption and its history, then you undoubtedly heard of Caesarian cipher. The Caesar cipher was developed and used by Julius Caesar to encrypt messages between him and his generals. The mechanics behind it is to encrypt plain text by shifting each letter in the plaintext a certain number of places down the alphabet. For example, we could shift alphabet down 3 letters so that A would become D, B would become C… A would become X, etc.
I should mention that Caesarian cipher is extremely easy to decrypt. Don’t use it to encrypt sensitive data. However, I would consider it an “additional step” to already secured information. For example, when storing access token in keychain, we could encrypt it using Caesarian cipher to provide an additional layer of security. After all, it is possible to get information stored in a keychain especially if you know / get a hold of / a Mac password (this assumes keychain being synched).
Continue reading “Caesar Cipher in Swift”