Skip to content

Instantly share code, notes, and snippets.

View drewag's full-sized avatar

Andrew Wagner drewag

View GitHub Profile
@drewag
drewag / MonospacedText.swift
Last active June 4, 2020 23:56
SwiftUI view to display normal text as monospaced (fixed width characters)
import SwiftUI
struct MonospacedText: View {
let content: String
let characterWidth: CGFloat
init(_ content: String, characterWidth: CGFloat) {
self.content = content
self.characterWidth = characterWidth
}
@drewag
drewag / LikeableTableCell.swift
Created August 31, 2019 19:59
Playground to Illustrate a Likable Table Cell
import UIKit
import PlaygroundSupport
// -----------------------------------------------------
// Model
//
// Types having to do with the storing and processing of
// data should be a part of the "Model" layer.
// -----------------------------------------------------
@drewag
drewag / CompareTriplets.swift
Last active August 27, 2019 01:49
Compare Triplets Algorithms
import Foundation
typealias Algorithm = (name: String, execute: ([Int],[Int]) -> [Int])
let algorithms: [Algorithm] = [
(name: "Drewag", { a, b in
return zip(a,b)
.map{(
$0 > $1 ? 1 : 0,
$1 > $0 ? 1 : 0
)}
@drewag
drewag / QueensAttack.swift
Last active August 26, 2019 04:43
Queen's Attack II With Declarative Emphasis
import Foundation
// ==========================================================================
// My Solution
// ==========================================================================
struct Position {
let row: Int
let column: Int
}
@drewag
drewag / swift-challenge-2.swift
Last active August 29, 2015 14:04
Swift Challenge #2
struct TakeWhileGenerator<T: GeneratorType>: GeneratorType {
typealias Element = T.Element
var generator: T
let test: (element: T.Element) -> Bool
mutating func next() -> Element? {
if let next = generator.next() {
if test(element: next) {
return next