Skip to content

Instantly share code, notes, and snippets.

import Foundation
class CounterSortaActor {
let queue = DispatchQueue(label: "CounterQueue")
private var _count = 0
var count: Int {
get {
queue.sync { _count }
}
@rhysm94
rhysm94 / LabelledImage.swift
Created April 9, 2021 23:35
Example of a UIViewRepresentable
import PlaygroundSupport
import SwiftUI
import UIKit
final class LabelledImage: UIView {
let label = UILabel()
let image = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
@dynamicMemberLookup
class Observable<T> { }
extension Observable {
func map<Result>(_ transform: @escaping (T) -> Result) -> Observable<Result> {
// Apply transform function here
fatalError()
}
subscript<Property>(dynamicMember keyPath: KeyPath<T, Property>) -> Observable<Property> {
@rhysm94
rhysm94 / SwiftUIDemo.swift
Created June 5, 2019 09:09
Runs in a Swift Playground, even on macOS 10.14!
import PlaygroundSupport
import SwiftUI
struct Pokemon {
let dexNum: Int
let species: String
}
extension Pokemon: Identifiable {
var id: Int { return dexNum }
import requests
import functools
url = 'https://petition.parliament.uk/petitions/241584.json'
json = requests.get(url).json()
signatures = json['data']['attributes']['signatures_by_country']
get_signature_count = lambda country: country['signature_count']
get_uk = lambda x: x['name'] == 'United Kingdom'
@rhysm94
rhysm94 / CreateMLUI.swift
Created June 5, 2018 10:42
Three lines of coded needed to open an ImageClassifierBuilder in a Playground in macOS Mojave
import CreateMLUI
let builder = MLImageClassifierBuilder()
builder.showInLiveView()
func daysInMonth(year: Int, month: Int) -> Int {
switch (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0), month) {
case (true, 2):
return 29
case (false, 2):
return 28
case (_, 1), (_, 3), (_, 5), (_, 7), (_, 8), (_, 10), (_, 12):
return 31
default:
return 30
//: HashMap data structure
public struct HashMap<Key: Hashable, Value> {
typealias Element = (key: Key, value: Value)
var arraySize: Int
var numberInserted = 0
var array: [Element?]
var loadFactor: Double {
return Double(numberInserted) / Double(arraySize)
}
@rhysm94
rhysm94 / keybase.md
Created February 22, 2017 13:15
Keybase Proof

Keybase proof

I hereby claim:

  • I am rhysm94 on github.
  • I am rhysmorgan (https://keybase.io/rhysmorgan) on keybase.
  • I have a public key ASAbl_ZFt2JzwcL9EoEBXltUczCrwMm0NZuTlDzqDDr59Ao

To claim this, I am signing this object: