Skip to content

Instantly share code, notes, and snippets.

View konrad1977's full-sized avatar

Mikael Konradsson konrad1977

View GitHub Profile
--recurse
--exclude=.git
--exclude=venv
--exclude=Pods
--exclude=Carthage
--exclude=vendor
--exclude=node_modules
@konrad1977
konrad1977 / .spacemacs
Last active December 14, 2021 15:04
Swift support for Spacemacs (.spacemacs)
;; -*- mode: emacs-lisp; lexical-binding: t -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Layer configuration:
This function should only modify configuration layer settings."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
;; `+distribution'. For now available distributions are `spacemacs-base'
@konrad1977
konrad1977 / PlaygroundXCTest.swift
Created January 21, 2020 13:16
Unit test support in Swift Playgrounds
import XCTest
// MARK: Comparable ---
@discardableResult
public func assertGreaterThan<A: Comparable>(_ lhs: A, _ rhs: A) -> String {
return lhs > rhs ? "✅" : "❌"
}
@discardableResult
public func assertGreaterThanOrEqual<A: Comparable>(_ lhs: A, _ rhs: A) -> String {
@konrad1977
konrad1977 / kitura-helloworld.swift
Created April 9, 2017 10:16
Hello world in kitura
import Kitura
let router = Router() router.get("/") { request, response, next in
response.send("Hello, World!")
next()
}
Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()
@konrad1977
konrad1977 / login_version2.swift
Created June 14, 2015 12:13
Refactored version of login
func login() {
do {
let token = try loginUserWithUsername("konrad1977", password: nil)
print("user logged in \(token)")
} catch let error as LoginError {
print(error.description)
} catch {
print(error)
}
@konrad1977
konrad1977 / extension.swift
Created June 14, 2015 12:09
Login error extension
extension LoginError : CustomStringConvertible {
var description: String {
switch self {
case .EmptyUsername:
return "Username cannot be empty"
case .EmptyPassword:
return "Password cannot be empty"
}
}
func login() {
do {
let token = try loginUserWithUsername("konrad1977", password: nil)
print("user logged in \(token)")
} catch LoginError.EmptyUsername {
print("empty username")
} catch LoginError.EmptyPassword {
print("empty password")
} catch {
func loginUserWithUsername(username: String?, password: String?) throws -> String {
guard let username = username where username.characters.count != 0 else {
throw LoginError.EmptyUsername
}
guard let password = password where password.characters.count != 0 else {
throw LoginError.EmptyPassword
}
///Handle all the other,
return "token:" + username
enum LoginError : ErrorType {
case EmptyUsername
case EmptyPassword
}
@konrad1977
konrad1977 / enums.swift
Created June 13, 2015 12:06
swift new enums
enum TextCase {
case Uppercase(String)
case Lowercase(String)
}
let values: [TextCase] = [
.Uppercase("FOO"),
.Lowercase("iamlow"),
.Uppercase("BAR"),
]