Skip to content

Instantly share code, notes, and snippets.

View fassko's full-sized avatar
👋
Hi! I'm Kristaps - Web3 and iOS Swift developer. Let's chat!

Kristaps Grinbergs fassko

👋
Hi! I'm Kristaps - Web3 and iOS Swift developer. Let's chat!
View GitHub Profile
@fassko
fassko / Custom date formats with Swift 4 Decodable
Created September 21, 2017 12:53
Parse custom date formats with Swift 4 and new Decodable protocol
import Foundation
struct CustomDate: Decodable {
let dateISO8601: Date
let dateISO8601Milliseconds: Date
}
let json = """
{
"dateISO8601": "2017-06-21T15:29:32Z",
@fassko
fassko / New macOS install
Last active December 4, 2017 12:42
Apps for fresh macOS install
## Moved to https://github.com/fassko/random/blob/master/macOS-install.md
@fassko
fassko / LogglyDestination.swift
Created March 13, 2018 13:51
XCGLogger loggly
//
// LogglyDestination.swift
// qminder-tv
//
// Created by Kristaps Grinbergs on 03/01/2018.
// Copyright © 2018 Qminder. All rights reserved.
//
import Foundation
@fassko
fassko / XCGLogger+Loggly.swift
Created March 13, 2018 13:53
XCGLogger+Loggly destination
let logglyDestination = LogglyDestination(owner: self, identifier: "logglyDestination")
logglyDestination.logQueue = XCGLogger.logQueue
logglyDestination.showLogIdentifier = false
logglyDestination.showFunctionName = true
logglyDestination.showThreadName = true
logglyDestination.showLevel = true
logglyDestination.showFileName = true
logglyDestination.showLineNumber = true
logglyDestination.showDate = true
logglyDestination.outputLevel = .verbose
@fassko
fassko / swift-switch-value-bindings.swift
Created May 21, 2018 12:01
Swift switch value bindings
/// Wind speed with direction
enum WindSpeed {
case north(Double)
case east(Double)
case south(Double)
case west(Double)
}
let direction = WindSpeed.north(3.6)
@fassko
fassko / spm
Created September 28, 2018 09:29 — forked from JohnSundell/spm
A script that makes it easier to use the Swift Package Manager by making common commands less verbose 👍
#!/usr/bin/env bash
# Put this file in /usr/local/bin and then run chmod +x on it to make it executable
command=$1
shift
case $command in
"init" )
swift package init "$@"
@fassko
fassko / websockets1.swift
Created July 30, 2019 06:05
WebSockets iOS13 #1
func webSocketTask(with: URL) -> URLSessionWebSocketTask
func webSocketTask(with: URLRequest) -> URLSessionWebSocketTask
func webSocketTask(with: URL, protocols: [String]) -> URLSessionWebSocketTask
@fassko
fassko / websocket2.swift
Created July 30, 2019 06:08
Opening connection
let urlSession = URLSession(configuration: .default)
let webSocketTask = urlSession.webSocketTask(with: "wss://echo.websocket.org")
webSocketTask.resume()
@fassko
fassko / websocket3.swift
Created July 30, 2019 06:09
Sending messages with Websocket iOS 13
let message = URLSessionWebSocketTask.Message.string("Hello World”)
webSocketTask.send(message) { error in
if let error = error {
print("WebSocket couldn’t send message because: \(error)")
}
}
@fassko
fassko / websocket4.swift
Created July 30, 2019 08:03
Receiving messages with Websocket iOS13
webSocketTask.receive { result in
switch result {
case .failure(let error):
print("Error in receiving message: \(error)")
case .success(let message):
switch message {
case .string(let text):
print("Received string: \(text)")
case .data(let data):
print("Received data: \(data)")