Download and Unzip a Zip file with Node.js

1. Install a javascript zip implementation. I like adm-zip.

2. Require the node http module

3. Require the node file system module (fs)

5. Construct your temporary file path

6. Use http to get the url to the zip file, then synchronously append the data to the temporary file path. Use AdmZip to extract the zip to another directory.

7. Delete the zip file

Code and usage:

UIWebView Load PDF with Swift

Sometimes you just want to load a pdf in a UIWebView, so here’s an extension to help you. A little bit of encapsulation can make the world of difference in readability and maintainability.


UILabel and UIButton Font Kerning with Swift

Here’s an extension to UILabel that kerns it’s text with a specified kerning value.


This extension to UIButton kerns the text in it’s titleLabel property.


Note, as of XCode 6.2, the UIButton type must be custom so that the UIButton is resized with the kerned text. Resizing behavior occurs without a call to sizeToFit() or invalidateIntrinsicContentSize().

iOS Font Kerning with Swift and NSAttributedString

From Wikipedia –

In typography, kerning (less commonly mortising) is the process of adjusting the spacing between characters in a proportional font, usually to achieve a visually pleasing result.

Today I received a PSD with kerned fonts, so I created a type level method in Swift that lets me create an attributed string by specifying a kerning value.

Now lets say this method was in a class called “AppearanceService”, this usage would be like this:

Resize UIImage in Swift and iOS 8

Here is an extension to UIImage that adds a public method called resize(size:CGSize, completionHandler:(resizedImage:UIImage, data:NSData)->()). The image is resized on a global concurrent queue and the completion handler is called on the main queue with the new UIImage and image data. Good for resizing images before sending them to a server. The jpeg compression ratio should probably also be parameterized! Enjoy!

Open App Settings in iOS 8

Apple, Y is this so poorly documented?

1. Add a key to your app-info.plist file called UIApplicationOpenSettingsURLString

2. Set the value of this key to “app-settings:”

3. In your code, access this value as a global constant:

in Objective-C, and

in Swift

4. Use this global constant like so :

in Objective C and

in Swift.

Use canOpenURL: to test if this is possible during run time. It is not possible on iOS 7. I also wonder if there are paths you can add after “app-settings:” to open specific app settings screens such as privacy. Please leave a comment if you have any information on this.

Get Application Documents directory in iOS Using Swift

Heres the snippet:

Copy a pre-populated SQLite file to documents directory for Core Data using Swift

Here is a quick snippet that shows how to check for the existence of a sqlite file in the documents directory and how to copy the file from the app bundle to the documents directory if it does not exists. This should be done before adding the persistent store to the persistent store coordinator ensure that there is pre-populated data

Using NSURLSession and NSURLSessionDataTask in Swift to make a GET request

Make a simple GET request using NSURLSession and NSURLSessionDataTask. Here i’m creating a singleton that has access to ‘network’ struct that has a computed property called session.

In your ViewController.swift file or another file that references the API class use this: