Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile
@IanKeen
IanKeen / Example_Complex.swift
Last active January 23, 2024 07:53
PropertyWrapper: @transaction binding for SwiftUI to make changes to data supporting commit/rollback
struct User: Equatable {
var firstName: String
var lastName: String
}
@main
struct MyApp: App {
@State var value = User(firstName: "", lastName: "")
@State var showEdit = false
@JohnSundell
JohnSundell / StarPlane.swift
Created July 8, 2020 22:41
A simple game written in SwiftUI. Note that this is just a fun little hack, the code is not meant to be taken seriously, and only works on iPhones in portrait mode.
// 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]()
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) {
@ryanburnette
ryanburnette / Caddyfile
Last active May 31, 2024 00:23
Caddy v2.1+ CORS whitelist
(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"
@TerryCK
TerryCK / Either.swift
Created December 12, 2019 09:06 — forked from pofat/Either.swift
Codable Either
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)
@matsuda
matsuda / String+AES.swift
Created November 18, 2019 10:45
AES encryption in Swift
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),
@quangDecember
quangDecember / wrapper+AES+CommonCrypto.swift
Created November 13, 2019 10:53
property wrappers for encryption, using builtin Apple library
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 {
@mjm
mjm / ManagedObjectChangesPublisher.swift
Created November 3, 2019 20:41
Observe changes to a Core Data fetch request with Combine
import Combine
import CoreData
extension NSManagedObjectContext {
func changesPublisher<Object: NSManagedObject>(for fetchRequest: NSFetchRequest<Object>)
-> ManagedObjectChangesPublisher<Object>
{
ManagedObjectChangesPublisher(fetchRequest: fetchRequest, context: self)
}
}
@zenxedo
zenxedo / FreeNAS,Rancher,Portainer
Last active June 11, 2023 15:13
FreeNAS,Rancher,Portainer
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
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 }