Skip to content

Instantly share code, notes, and snippets.

View bubudrc's full-sized avatar

Marcelo Perretta bubudrc

View GitHub Profile
import SwiftUI
import PlaygroundSupport
struct Desktop: View {
var body: some View {
ZStack {
// Image(uiImage: #imageLiteral(resourceName: "IMG_6281.JPG"))
Color(UIColor.systemBlue)
macOS()
}
//
// ContentView.swift
//
//
// Created by Bernstein, Joel on 7/4/20.
//
import SwiftUI
struct ElementModel: Identifiable
@bubudrc
bubudrc / nstask.swift
Created July 15, 2020 16:12 — forked from Seasons7/nstask.swift
NSTask Sample for Swift
import Cocoa
import Foundation
var str = "Hello, playground"
var task:NSTask = NSTask()
var pipe:NSPipe = NSPipe()
task.launchPath = "/bin/ls"
task.arguments = ["-la"]
@bubudrc
bubudrc / nstask.swift
Created July 15, 2020 16:12 — forked from Seasons7/nstask.swift
NSTask Sample for Swift
import Cocoa
import Foundation
var str = "Hello, playground"
var task:NSTask = NSTask()
var pipe:NSPipe = NSPipe()
task.launchPath = "/bin/ls"
task.arguments = ["-la"]
@bubudrc
bubudrc / MWPButton
Last active August 3, 2020 17:40
Custom mac button
import Cocoa
import AppKit
protocol MWPButtonDelegate: AnyObject {
func userDidClickedtButton(sender: MWPButton)
}
@IBDesignable
@bubudrc
bubudrc / Middleware
Created September 22, 2021 18:55 — forked from bballentine/Middleware
Vapor - Example middleware that checks user's role before giving access to protected resources.
import Vapor
import HTTP
public class AdminAuthMiddleware: Middleware {
public let error: Error
public let authLevel: UserRole
public init(error: Error, authLevel: UserRole) {
self.error = error
self.authLevel = authLevel
}
@bubudrc
bubudrc / deploy.swift
Created November 18, 2021 21:50 — forked from 0xTim/deploy.swift
A Swift script to deploy an app (in this case Vapor) to AWS Fargate from scratch. It first checks to see if there's a repository in ECR for the app, if not it creates one, builds the container and pushes it. It then checks for a registered task definition. In one doesn't exist in ECS, it updates the provided task definition with the latest ECR i…
#!/usr/bin/swift
import Foundation
// MARK: - Script variables
let awsProfileName: String? = "myProfile"
let serviceName = "someService"
// MARK: - Functions
@discardableResult
func shell(_ args: String..., returnStdOut: Bool = false, stdIn: Pipe? = nil) -> (Int32, Pipe) {
@bubudrc
bubudrc / 1_JSONifyTag.swift
Created December 10, 2021 14:49 — forked from vzsg/1_JSONifyTag.swift
Custom Leaf tag for printing anything in the context as JSON (Vapor 4)
import LeafKit
final class JSONifyTag: UnsafeUnescapedLeafTag {
func render(_ ctx: LeafContext) throws -> LeafData {
guard let param = ctx.parameters.first else {
throw "no parameter provided to JSONify"
}
return LeafData.string(param.jsonString)
}
@bubudrc
bubudrc / 1_DynamicQuery.swift
Created December 10, 2021 14:51 — forked from vzsg/1_DynamicQuery.swift
Dynamic Query Support for Vapor 3
import Foundation
import Fluent
protocol DynamicQueryable {
static func dynamicMapping<DB: Database, QB: QueryBuilder<DB, Self>>() -> [String: (DynamicFilter, QB) throws -> QB]
}
protocol DynamicSortable {
static var dynamicFieldMapping: [String: FluentProperty] { get }
}
@bubudrc
bubudrc / IkigaJSON+Content.swift
Created December 10, 2021 14:54 — forked from vzsg/IkigaJSON+Content.swift
Example on how to integrate IkigaJSON with Vapor 4
import Vapor
import IkigaJSON
extension IkigaJSONEncoder: ContentEncoder {
public func encode<E: Encodable>(
_ encodable: E,
to body: inout ByteBuffer,
headers: inout HTTPHeaders
) throws {
headers.contentType = .json