Skip to content

Instantly share code, notes, and snippets.

View xpqz's full-sized avatar
🏠
Working from home

Stefan Kruger xpqz

🏠
Working from home
View GitHub Profile
//
// Cloudant.swift
//
// Created by Stefan Kruger on 19/08/2014.
// Copyright (c) 2014 Stefan Kruger. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the
@xpqz
xpqz / GeoWrapper.swift
Created October 13, 2014 09:38
JavaScript from Swift
import Foundation
import JavaScriptCore
public class GeoWrapper {
var jsContext: JSContext
public init?() {
jsContext = JSContext()
jsContext.exceptionHandler = { NSLog("ERROR: '%@'", $1) }
OsGridRef.toWGS84 = function(str) {
var grid = OsGridRef.parse(str);
var pOSGB36 = OsGridRef.osGridToLatLon(grid);
var pWGS84 = pOSGB36.convertDatum(LatLonE.datum.WGS84);
var latlon = pWGS84.toString(format="d");
return latlon;
}
var convert = function(str) {
return OsGridRef.toWGS84(str)
import Foundation
enum Tech {
case UK(level: Int, modifier: Character)
init?(level: Int, modifier: Character) {
if (4..<7 ~= level) && (find(["a", "b", "c"] as [Character], modifier) != nil) {
self = .UK(level: level, modifier: modifier)
} else {
return nil
import Foundation
enum Grade: Printable {
case UKTrad(adjectival: String, technical: String?)
var description: String {
switch self {
case let UKTrad(adjectival, technical):
if technical == nil {
return adjectival
let flyingButtressDirect = Grade.UKTrad(adjectival: "HVS", technical: "5b")
// In a playground we need the .description
println(flyingButtressDirect.description) // HVS 5b
enum Adjectival: Printable {
case Diff, VeryDifficult, Severe, HardSevere, VerySevere, HardVerySevere, Extreme(level: Int), Error
var description: String {
switch self {
case Diff:
return "D"
case VeryDifficult:
return "VDiff"
case Severe:
return "S"
enum Grade: Printable {
case UKTrad(adjectival: Adjectival, technical: String?)
var description: String {
switch self {
case let UKTrad(adjectival, technical):
if technical == nil {
return adjectival.description
}
let leftWall = Grade.UKTrad(adjectival: .Extreme(level: 2), technical: "5b")
println(leftWall.description) // E2 5b
enum Tech {
case UK(level: Int, modifier: Character)
init?(level: Int, modifier: Character) {
if (4..<7 ~= level) && (find(["a", "b", "c"] as [Character], modifier) != nil) {
self = .UK(level: level, modifier: modifier)
} else {
return nil
}
}