Skip to content

Instantly share code, notes, and snippets.

struct Map: Codable {
let width, height: Int
var cells: [Tile]
@maartene
maartene / ContentView.swift
Last active October 11, 2019 19:55
Day 19 challenge of "100 days of Swift UI" - length converter
//
// ContentView.swift
// Conversions
//
// Created by Maarten Engels on 11/10/2019.
// Copyright © 2019 thedreamweb. All rights reserved.
//
import SwiftUI
@maartene
maartene / ContentView.swift
Created October 19, 2019 09:50
Day 25 challenge: a sort of Rock-Paper-Scissors game
//
// ContentView.swift
// RockPaperScissers
//
// Created by Maarten Engels on 19/10/2019.
// Copyright © 2019 thedreamweb. All rights reserved.
//
import SwiftUI
@maartene
maartene / ContentView.swift
Created October 23, 2019 19:08
100 days of SwiftUI project 5 "Word Scamble" solution (including challenges)
//
// ContentView.swift
// Word Scramble
//
// Created by Maarten Engels on 23/10/2019.
// Copyright © 2019 thedreamweb. All rights reserved.
//
import SwiftUI
@maartene
maartene / ContentView.swift
Created November 9, 2019 16:04
Day 47 Challenge - Habits app
//
// ContentView.swift
// Habits
//
// Created by Maarten Engels on 09/11/2019.
// Copyright © 2019 thedreamweb. All rights reserved.
//
import SwiftUI
@maartene
maartene / Dockerfile
Created December 31, 2019 12:55
Vapor3 / Swift 5.1 Dockerfile
# You can set the Swift version to what you need for your app. Versions can be found here: https://hub.docker.com/_/swift
FROM swift:5.1 as builder
# For local build, add `--build-arg env=docker`
# In your application, you can use `Environment.custom(name: "docker")` to check if you're in this env
ARG env
RUN apt-get -qq update && apt-get install -y \
libssl-dev zlib1g-dev \
&& rm -r /var/lib/apt/lists/*
WORKDIR /app
COPY . .
@maartene
maartene / AnyWrapper.swift
Last active March 29, 2020 15:23
A simple wrapper so you get limited Codable comformance for Any values, including Array<Any> and Dictionary<String: Any> values.
// A simple way to get Codable comformance for [Any] and [String: Any] types,
// where Any can be any basic type as well as nested arrays and dictionaries.
//
// Use:
// let associativeStorage = [String: Any]()
// First wrap it
// let wrappedAssociativeStorage = try AnyWrapper.wrapperFor(associativeStorage)
// Then encode it using:
// let data = try encoder.encode(associativeStorage)
//
@maartene
maartene / ShadowCasting.swift
Created March 26, 2022 09:19
ShadowCasting as Bob Nystrom (translated from Dart to Swift)
// MARK: Shadowcasting
/// Based on the explanation and Dart code: https://journal.stuffwithstuff.com/2015/09/07/what-the-hero-sees/
/// Translated to Swift
private func transformOctant(row: Int, col: Int, octant: Int) -> Vector {
switch octant {
case 0:
return Vector( x: col, y: -row)
case 1:
return Vector( x: row, y: -col)
case 2: