Skip to content

Instantly share code, notes, and snippets.

View slashmo's full-sized avatar
🐦
Coding in Swift

Moritz Lang slashmo

🐦
Coding in Swift
View GitHub Profile
struct Stack<Element> {
var items = [Element]()
mutating func push(item: Element) {
items.append(item)
}
mutating func pop() -> Element {
return items.removeLast()
}
}
var stackOfInts = Stack<Int>()
stackOfInts.push(0)
stackOfInts.push(1)
stackOfInts.push(2)
stackOfInts.pop()
func findIndex<T: Equatable>(array: [T], _ valueToFind: T) -> Int? {
for (index, value) in array.enumerate() {
if value == valueToFind {
return index
}
}
return nil
}
let numbers = [1, 6, 5, 9]
findIndex(numbers, 6)
let strings = ["a", "b", "c"]
findIndex(strings, "d")
### Keybase proof
I hereby claim:
* I am slashmo on github.
* I am slashmo (https://keybase.io/slashmo) on keybase.
* I have a public key whose fingerprint is 4EB0 6D1D 8D08 EF63 FEE0 49AF C9C3 5336 33D3 FF7B
To claim this, I am signing this object:
@slashmo
slashmo / flat_vs_flatMap-1.swift
Last active December 1, 2016 23:03
First code snippet for my Medium post on map vs. flatMap in Swift.
struct Product {
let name: String
}
struct Person {
let firstName: String
let lastName: String
var products: [Product]
}
@slashmo
slashmo / flat_vs_flatMap-2.swift
Created December 1, 2016 22:59
Second code snippet for my Medium post on map vs. flatMap in Swift.
let productNames = people
.flatMap { $0.products }
.map { $0.name }
@slashmo
slashmo / ComposableArchitecture.swift
Last active March 16, 2020 18:42
ComposableArchitecture
import Foundation
// MARK: - Architecture
typealias Reducer<Value, Action> = (inout Value, Action) -> Void
final class Store<Value, Action> {
private(set) var value: Value
private let reducer: Reducer<Value, Action>

Keybase proof

I hereby claim:

  • I am slashmo on github.
  • I am slashmo (https://keybase.io/slashmo) on keybase.
  • I have a public key ASBT8CLwyFAOitIwtSyeW4qRhfzwr4g3VhjCrRe_h3o50go

To claim this, I am signing this object:

@slashmo
slashmo / docker-compose.yaml
Created February 6, 2022 17:31
3-Node Kafka Cluster via Docker Compose
---
version: '3'
services:
zookeeper1:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 12181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 12181:12181