This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User: Equatable { | |
var firstName: String | |
var lastName: String | |
} | |
@main | |
struct MyApp: App { | |
@State var value = User(firstName: "", lastName: "") | |
@State var showEdit = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A fun little game written in SwiftUI | |
// Copyright (c) John Sundell 2020, MIT license. | |
// This is a hacky implementation written just for fun. | |
// It's only verified to work on iPhones in portrait mode. | |
import SwiftUI | |
final class GameController: ObservableObject { | |
@Published var plane = GameObject.plane() | |
@Published private(set) var clouds = [GameObject]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ellipticCurveHeader = [UInt8]([0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, | |
0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, | |
0x01, 0x07, 0x03, 0x42, 0x00]) | |
let begin = "-----BEGIN PUBLIC KEY-----\n" | |
let end = "\n-----END PUBLIC KEY-----" | |
func retrivePublicKey() -> String? { | |
var error: Unmanaged<CFError>? | |
if let publicKey = getPublicKey(), | |
let keyRef = SecKeyCopyExternalRepresentation(publicKey, &error) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(cors) { | |
@cors_preflight{args.0} method OPTIONS | |
@cors{args.0} header Origin {args.0} | |
handle @cors_preflight{args.0} { | |
header { | |
Access-Control-Allow-Origin "{args.0}" | |
Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" | |
Access-Control-Allow-Headers * | |
Access-Control-Max-Age "3600" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Either<A, B> { | |
case left(A) | |
case right(B) | |
} | |
extension Either: Decodable where A: Decodable, B: Decodable { | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if let a = try? container.decode(A.self) { | |
self = .left(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CommonCrypto | |
// MARK: AES128 暗号、復号化 | |
public extension String { | |
func aesEncrypt(key: String, iv: String) -> String? { | |
guard | |
let data = self.data(using: .utf8), | |
let key = key.data(using: .utf8), | |
let iv = iv.data(using: .utf8), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import CommonCrypto | |
struct AES256 : Codable { | |
private var key: Data | |
private var iv: Data | |
public init(key: Data, iv: Data) throws { | |
guard key.count == kCCKeySizeAES256 else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import CoreData | |
extension NSManagedObjectContext { | |
func changesPublisher<Object: NSManagedObject>(for fetchRequest: NSFetchRequest<Object>) | |
-> ManagedObjectChangesPublisher<Object> | |
{ | |
ManagedObjectChangesPublisher(fetchRequest: fetchRequest, context: self) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Credit here: https://www.ixsystems.com/community/threads/howto-freenas-11-rancheros-docker-and-portainer.54595/ | |
So when FreeNAS 11 came, I updated from 9.10 to get rolling on the new options. Unfortunately this killed my VirtualBox jail that I was using to run some services I couldn't get working in a jail. So I started looking on how to get Docker running under FreeNAS 11 so I could replace those services and get some future proofing for the 11.1 and onward releases that should support Docker out of the box. From the posts on the forums they look to be heading for RancherOS as the underlying Docker operating system. | |
I originally tried to get this working under the default VM tab in the new interface, but it was not cooperating. I then moved over to using iohyve and bhyve from the command line to get this working. Here are the basic steps I used to get this kicking. | |
Prep | |
Setup the iohyve pool and options. Select where the pool you want, and the main network card you want attached. | |
iohyve setup pool=<stora |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public protocol ValueTransforming: NSSecureCoding { | |
static var valueTransformerName: NSValueTransformerName { get } | |
} | |
public class NSSecureCodingValueTransformer<T: NSObject & ValueTransforming>: ValueTransformer { | |
public override class func transformedValueClass() -> AnyClass { T.self } | |
public override class func allowsReverseTransformation() -> Bool { true } |