Skip to content

Instantly share code, notes, and snippets.

View bubudrc's full-sized avatar

Marcelo Perretta bubudrc

View GitHub Profile
//Import Javascript core
import JavaScriptCore
//[...]
//Get the JS Context
let context = JSContext()!
//write your function in javascript and feed it to context
context.evaluateScript(#"""
@vzsg
vzsg / 1_JSONifyTag.swift
Last active March 11, 2023 18:49
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)
}
@vzsg
vzsg / 1_DynamicQuery.swift
Last active December 10, 2021 14:51
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 }
}
import Foundation
import Combine
import SwiftUI
import FuncNetworking
import AddaMeModels
import KeychainService
import InfoPlist
public struct WebsocketClient {
@BrentMifsud
BrentMifsud / Image+Data.swift
Last active July 14, 2024 12:50
SwiftUI Image from data
import Foundation
import SwiftUI
#if canImport(UIKit)
import UIKit
#elseif canImport(AppKit)
import AppKit
#endif
extension Image {
/// Initializes a SwiftUI `Image` from data.
@0xTim
0xTim / deploy.swift
Last active December 19, 2022 13:13
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) {
@vzsg
vzsg / IkigaJSON+Content.swift
Created October 9, 2020 01:18
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
//
// ContentView.swift
//
//
// Created by Bernstein, Joel on 7/4/20.
//
import SwiftUI
struct ElementModel: Identifiable
@jordansinger
jordansinger / macOS.swift
Last active February 14, 2024 03:41
macOS SwiftUI Playgrounds code
import SwiftUI
import PlaygroundSupport
struct Desktop: View {
var body: some View {
ZStack {
// Image(uiImage: #imageLiteral(resourceName: "IMG_6281.JPG"))
Color(UIColor.systemBlue)
macOS()
}
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
Text("Hello World")
}
}
PlaygroundPage.current.setLiveView(ContentView())