Skip to content

Instantly share code, notes, and snippets.

View anthonycastelli's full-sized avatar

Anthony anthonycastelli

View GitHub Profile
@samalone
samalone / Database+transaction.swift
Last active September 6, 2019 21:25
Transactions for Vapor 4 alpha 3
import FluentPostgresDriver
import FluentSQLiteDriver
// This extension adds transaction support to the Database protocol.
// It has to be specialized for each Database type used by your application,
// since the Database protocol does not support the raw() method.
extension Database {
func transaction(callback: @escaping (Database) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
return self.withConnection { (db) -> EventLoopFuture<Void> in
@bardonadam
bardonadam / DynamicColor.swift
Last active August 20, 2021 03:22
DynamicColor property wrapper type to remove boilerplate code when defining dynamic colors to adopt dark mode on iOS 13
@DynamicColor(lightVariant: .black, darkVariant: .white)
static var dynamicLabelColor: UIColor
@propertyWrapper
struct DynamicColor {
let lightVariant: UIColor
let darkVariant: UIColor
var wrappedValue: UIColor {
get {
@epaga
epaga / TappableView.swift
Last active December 13, 2021 17:57
SwiftUI View for getting taps with(!) the tap locations unlike the current tapAction and tapGestures of SwiftUI
// SwiftUI View for getting taps with(!) the tap locations unlike the current tapAction and tapGestures of SwiftUI
// There may be a way easier way to do this, not sure...
/*
Use like so:
TappableView {
(location, taps) in
if taps == 1 {
print("single tap at \(location)")
let xs = [1, 2, 3, 4, 5]
for (element, index) in zip(xs, xs.indices) {
if index == xs.startIndex {
print("START")
}
print(element)
if index == xs.index(before: xs.endIndex) {
public struct BoundedSequence<Base>: Sequence, IteratorProtocol where Base: Sequence {
public struct Boundary: Equatable {
public let isStart: Bool
public let isEnd: Bool
}
private var _iterator: Base.Iterator
private var _previous: Base.Element?
private var _current: Base.Element?
private var _next: Base.Element?
@vzsg
vzsg / 1_AppStoreReceiptValidation.swift
Last active September 15, 2023 18:42
Starting point for App Store receipt validation with Vapor 3
import Foundation
struct AppStoreReceiptValidationRequest: Encodable {
let receiptData: String
let password: String?
let excludeOldTransactions: Bool
private enum CodingKeys: String, CodingKey {
case receiptData = "receipt-data"
case password
#!/bin/sh
filter='subsystem contains "com.apple.TimeMachine"'
log show --style syslog --info --last 12h --predicate "$filter"
log stream --style syslog --info --predicate "$filter"
@vzsg
vzsg / Config+Setup.swift
Created May 25, 2017 22:35
HTML5 Routing Compatibility Middleware for Vapor 2
extension Config {
public func setup() throws {
// ...
addConfigurable(middleware: Html5RoutingMiddleware.init, name: "html5")
}
// ...
}
@michaelevensen
michaelevensen / PagingCollectionViewController.swift
Last active April 10, 2024 08:46
An example of perfectly paging horizontal UICollectionViewController with overflowing cells. Works great with Storyboard — no need to set any specific attributes, just add this Class to the Controller and set your desired size for the cells like you would normally.
import UIKit
private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController {
/* Custom scrollView for paging */
let pagingScrollView = UIScrollView()
/* Return item size */
@steve228uk
steve228uk / commalist.swift
Created July 25, 2016 21:02
Comma List Swift
extension SequenceType where Generator.Element == String {
func commaList() -> String {
var result = joinWithSeparator(", ")
let range = result.rangeOfString(", ", options: .BackwardsSearch)
result.replaceRange(range!, with: " & ")
return result
}
}