Skip to content

Instantly share code, notes, and snippets.

View Joannis's full-sized avatar
🇺🇦
#StandWithUkraine

Joannis Orlandos Joannis

🇺🇦
#StandWithUkraine
View GitHub Profile
/* ESPNOW Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
/*
@available(macOS 14, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
final class DispatchSerialExecutor: SerialExecutor {
let queue: DispatchQueue
init(queue: DispatchQueue) {
self.queue = queue
}
init() {
self.queue = DispatchQueue(
import SwiftUI
@MainActor class ViewModel: ObservableObject {
private let events = AsyncStream<AwaitableEvent>.makeStream()
struct AwaitableEvent {
let event: Event
let continuation: CheckedContinuation<Void, Never>
}
final class NetworkUsers: URLRepresentable {
let apiVersion: APIVersion
let network: String
init(apiVersion: APIVersion, network: String) {
self.apiVersion = apiVersion
self.network = network
}
func makeURL() throws -> URL {
import MeowVapor
import JWT
final class CMSContext: Service {
struct Value {
public let meow: Meow.Context
public let token: AdministrativeUserToken?
public let user: AdministrativeUser?
}
// https://github.com/vapor/vapor
import Vapor
// https://github.com/Ikiga/IkigaJSON
import IkigaJSON
public struct JSONSafetyMiddleware: Middleware {
public init() {}
public func respond(to request: Request, chainingTo next: Responder) throws -> EventLoopFuture<Response> {
let encoder = JSONEncoder()
let decoder = JSONDecoder()
struct User: Codable {
let id: Int
let name: String
let age: Double
let roles: [String]
let awesome: Bool
}
@Joannis
Joannis / any.swift
Created October 27, 2018 21:08
Code using the Any type
import Foundation
let date = Date()
var array = [Any]()
for _ in 0..<100_000 {
array.append("Hello, world")
}
@Joannis
Joannis / VaporLeopardBridge.swift
Created August 11, 2017 14:16
Requires Leopard beta 1 and Vapor 2
import Vapor
import Leopard
import Lynx
import Sockets
import HTTP
public final class LynxServer : ServerProtocol, AsyncRouter {
public func register(at path: [String], method: Lynx.Method?, isFallbackHandler: Bool, handler: @escaping RequestHandler) {
router.register(at: path, method: method, isFallbackHandler: isFallbackHandler, handler: handler)
}
@Joannis
Joannis / MongoKitten.swift
Last active April 25, 2017 09:58
MongoKitten and Perfect-MongoDB
import MongoKitten
import Foundation
let client = try Server("mongodb://localhost")
// Creating a user Document
func createUser() throws -> Document {
return [
"username": "Joannis",
"age": 20,