Skip to content

Instantly share code, notes, and snippets.

Avatar
🤗
Biting shoulders

Mikey Ward wookiee

🤗
Biting shoulders
View GitHub Profile
@wookiee
wookiee / StructuredConcurrencyProposals.md
Last active May 20, 2021
Swift Structured Concurrency Proposals
View StructuredConcurrencyProposals.md
  • async/await and Structured Concurrency introduce the syntactical building blocks (including the Task type) for writing asynchronous code using Swift-native language features.
  • There is a WIP standalone proposal to add async let syntax to greatly reduce a pain point of filling values asynchronously for later use.
  • actor types introduce a new top-level reference type (like class) that require and statically enforce that access to any of their mutable state be done asynchronously (such as by using the async/await syntax), and exist to help model thread-safe mutable data structures. The idea of [global actors](https://github
View paste
“_wrappers.so” cannot be opened because the developer cannot be verified.
View paste
https://gist.github.com/70547c03a0df58b349eed8d600fced9b
View paste
import Foundation
@propertyWrapper public struct Percentage<Value: FloatingPoint> {
private var storage: Value
private let upperBound: Value
public init(wrappedValue: Value, upperBound: Value = (1.0 as! Value)) {
self.storage = wrappedValue
self.upperBound = upperBound
@wookiee
wookiee / PickWeighted.swift
Created Feb 14, 2020
Swift function to pseudorandomly choose an item from an Array, allowing for individual weighting of their likelihood of choice.
View PickWeighted.swift
/// Pseudorandomly choose a value from an array of values, where each is weighted relative to the others in the collection.
///
/// The `weight` component of each tuple is a positive integer signalling how likely a value is to be chosen vs. other values with different weights. For example, a value with a weight of `4` is four times as likely as a value with a weight of `1` to be chosen.
///
/// - Parameter values: an array of `(value:Thing,weight:Int)` tuples.
///
/// - Returns: a single chosen value.
///
func pickWeighted<Thing>(from weightedValues: [(value: Thing, weight: Int)]) -> Thing {
// compute the sum of the weights of all of the value/weight pairs
View CreateMLOutput.txt
Image augmentation option 'exposure' selected.
Image augmentation option 'shear' selected.
Automatically generating validation set from 10% of the data.
Extracting augmented image features from training data set.
Analyzing and extracting image features.
+----------------------+------------------+--------------+------------------+
| Raw Images Processed | Augmented Images | Elapsed Time | Percent Complete |
+----------------------+------------------+--------------+------------------+
| 1 | 16 | 2.31s | 2% |
| 2 | 32 | 2.98s | 4% |
@wookiee
wookiee / zip3.swift
Last active Feb 5, 2018 — forked from JRHeaton/zip3.swift
Implementing zip3 in Swift
View zip3.swift
struct Zip3Iterator
<
A: IteratorProtocol,
B: IteratorProtocol,
C: IteratorProtocol
>: IteratorProtocol {
private var first: A
private var second: B
@wookiee
wookiee / DragTableController.swift
Created Aug 19, 2017 — forked from sooop/DragTableController.swift
NSTableView reordering row with drag and drop
View DragTableController.swift
//
// ViewController.swift
// DragTable
//
// Created by Anna Kim on 2017. 2. 9..
// Copyright © 2017년 Anna Kim. All rights reserved.
//
import Cocoa
@wookiee
wookiee / UserDefault.swift
Last active May 29, 2017
Convenience wrapper for UserDefaults-bound computed properties
View UserDefault.swift
//
// UserDefault.swift
//
// Created by Michael L. Ward on 5/29/17.
// Copyright © Michael L. Ward. All rights reserved.
//
import Foundation
struct UserDefault<T> {
@wookiee
wookiee / ImageStore.swift
Created Sep 30, 2016
ImageStore.swift to use with the Advanced iOS pre-course workbook
View ImageStore.swift
//
// Copyright © 2015 Big Nerd Ranch
//
import UIKit
class ImageStore {
let cache = NSCache<NSString, UIImage>()