Skip to content

Instantly share code, notes, and snippets.

View collinsrj's full-sized avatar

Robert Collins collinsrj

View GitHub Profile
//
// CalculatorBrainTests.swift
// Calculator
//
// Created by Robert Collins on 30/03/2015.
// Copyright (c) 2015 Robert Collins. All rights reserved.
//
import XCTest
@collinsrj
collinsrj / CustomUIViewPlayground.swift
Last active August 29, 2015 14:21
An Xcode playground showing a custom UIView
import UIKit
import XCPlayground
class MyView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@collinsrj
collinsrj / HttpsRequestPlayground.swift
Created May 26, 2015 17:55
ExampleHTTPSRequestInPlayground
import UIKit
import XCPlayground
// Plain HTTP Request
var session = NSURLSession.sharedSession()
var url = NSURL(scheme: "http", host: "www.ibm.com", path: "/")!
var request = NSMutableURLRequest(URL: url)
var plainHttpTask = session.dataTaskWithRequest(request) {
(data, response, error) -> Void in
if error != nil {
@collinsrj
collinsrj / NSURLErrorHandling.swift
Created May 27, 2015 06:26
Looking at NSError Handling from NSURLSession
import UIKit
import XCPlayground
// HTTPS Request
var secureSession = NSURLSession.sharedSession()
if let url = NSURL(scheme: "https", host: "api.github.com", path: "/users/collinsrj/repos") {
//if let url = NSURL(scheme: "https", host: "goo.gl", path: "/WsXbKr") {
var httpsTask = secureSession.dataTaskWithURL(url) {
(data, response, error) -> Void in
if error != nil {
@collinsrj
collinsrj / server.js
Created July 22, 2015 05:10
TLS 1.2 Node.js Server
// A super simple HTTPS service which allows you to GET a collection of names from https://<hostname>/names
var express = require('express');
var https = require('https');
var app = express();
var fs = require('fs');
app.get('/names', function (req, res) {
res.json(["Simon", "Bob"])
});
@collinsrj
collinsrj / Swift2httpsExample.swift
Last active August 29, 2015 14:25
An example in Swift 2 of connecting to an HTTPS service and parsing the resulting JSON.
let urlString = "https://example.com/names"
guard let url = NSURL(string: urlString) else {
fatalError("The URL: \(urlString) wasn't valid!")
}
let request = NSMutableURLRequest(URL: url)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) -> Void in
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves)
# The following is an example - it may not represent best practice. Your security is your own responsibility.
# Create the fake CA key and cert.
openssl genrsa -des3 -out ca.key 2048
openssl req -new -x509 -sha256 -days 365 -key ca.key -out ca.crt
# Generate a key for the server
openssl genrsa -out server.key 2048
# for this next command, make sure you specify your domain as the Common Name e.g. example.com
openssl req -new -key server.key -out server.csr
openssl x509 -sha256 -req -in server.csr -out server.crt -CA ca.crt -CAkey ca.key -CAcreateserial -days 365
@collinsrj
collinsrj / HttpsPlayground.swift
Created May 7, 2016 13:14
Synchronous HTTPS Request in Playground
import Foundation
func getEncoding(response: NSHTTPURLResponse) -> NSStringEncoding {
guard let encodingName = response.textEncodingName else {
return NSUTF8StringEncoding
}
let encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding(encodingName))
if encoding != UInt(kCFStringEncodingInvalidId) {
return encoding
}
@collinsrj
collinsrj / FlattenIntArray.js
Created May 10, 2017 22:38
A simple JavaScript (ES6) function to flatten a nested integer array.
/**
* Flattens an integer array. The function should handle deeply nested arrays
* without issue using an ES6 interpretter which supports Tail Call
* Optimisation.
*
* @returns {Array} a flattened Integer array
*/
const flattenIntArray = array => array
.filter(item => {
if (Number.isInteger(item) || Array.isArray(item)) {

I work for IBM, on a very large, mature enterprise product. My role is technical architect, I was tasked with building a new application for consumers. By consumers, I mean systems real people interact with, not those employees of a business paid to use it. This wasn't something which had been done before for the product.

We faced two big challenges. We had to deliver an application which would work well across all platforms and my team were a a set of native iOS developers. The second was I strongly believed that the existing framework for web UI development would not deliver the great experiences required by our customer.

Addressing the team issue was not a big hurdle. We had already been looking at web applications to expand our reach. It didn't take too much convincing. The team were used to change, we'd been working in the Swift programming language following the latest builds and language changes.

The enterprise product had a long established way of building user interfaces. For end users, it resul