Skip to content

Instantly share code, notes, and snippets.

View lazyvar's full-sized avatar

Mack Hasz lazyvar

View GitHub Profile
import UIKit
/* attempt 1 */
protocol HasApply { }
extension HasApply {
func apply(_ applying: (Self) -> Void) -> Self {
applying(self)
//: Playground - noun: a place where people can play
import UIKit
func ward<T: AnyObject, A, Return>(_ object: T?, _ keyPath: KeyPath<T, (A) -> Return>, else defaultValue: Return) -> ((A) -> Return) {
return { [weak object] a in
guard let object = object else {
return defaultValue
}
/**
Inspired by rails `StringInquirer`
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/string_inquirer.rb
**/
@dynamicMemberLookup
struct StringInquirer {
let string: String
//
// main.swift
// Mad
//
// Created by Mack on 10/13/19.
// Copyright © 2019 Mack. All rights reserved.
//
import Foundation
/// hanoi.swift
struct Tower: OptionSet {
static let all: Tower = [.a, .b, .c]
static let a = Tower(rawValue: 1 << 0)
static let b = Tower(rawValue: 1 << 1)
static let c = Tower(rawValue: 1 << 2)
let rawValue: Int
}
//
// RxDataSources+SkeletonView.swift
//
// Created by mack on 4/7/20.
//
import Foundation
import UIKit
import RxSwift
import RxDataSources
import YPImagePicker
struct NewPost {
/// YPMediaItem translates to either a UIImage for photo or Data/URL for video
var media: Either<[YPMediaItem], [NewPost.Medium]>
struct Medium {
let url: String
let thumbnailUrl: String?
let mediumType: Post.Medium.MediumType
// Equatable+nil.swift
struct Model: Equatable { }
let model = Model()
print(model == nil) // This compiles and produces a warning
print(model == .none) // This compiles with no warning
# When you let copilot go..
defmodule Sayings do
@hello "Hello"
@goodbye "Goodbye"
@thanks "Thanks"
@bye "Bye"
@see_you "See you"
@see_you_later "See you later"
@see_you_soon "See you soon"