Skip to content

Instantly share code, notes, and snippets.

@leandropjp
leandropjp / ISO8601DateFormatter.swift
Created August 30, 2023 17:14 — forked from Pash237/ISO8601DateFormatter.swift
Fast implementation for ISO8601 date formatter. Around 30 times faster than using (cached) DateFormatter
class ISO8601DateFormatter {
private static var cachedCalendar: Calendar = {
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone.gmt
return calendar
}()
static func format(_ date: Date) -> String {
let components = cachedCalendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
import Foundation
enum Either<A,B> {
case left(A)
case right(B)
}
// Works only using Swift 4.1
extension Either: Codable where A: Codable, B: Codable {
enum CodingKeys: CodingKey {
import PlaygroundSupport
import RxSwift
PlaygroundPage.current.needsIndefiniteExecution = true
extension ObservableType where E: Sequence {
typealias T = E.Iterator.Element
/// Create an observable which is an Array of the projected values
@leandropjp
leandropjp / cocoapods-bundle-id
Created July 4, 2019 21:00 — forked from daltonclaybrook/cocoapods-bundle-id
A post install script for CocoaPods that changes the bundle identifier of all pods to the one specified.
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == 'BREnterprise'
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'iPhone Distribution: The Carter Group LLC'
config.build_settings['PROVISIONING_PROFILE'] = '${BR_ENTERPRISE_PROVISIONING_PROFILE}'
end
end
end
@leandropjp
leandropjp / PromiseQueue.swift
Created June 29, 2019 03:28 — forked from zlangley/PromiseQueue.swift
An operation queue for Promises.
import Dispatch
import PromiseKit
/// A wrapper for a function that creates a Promise.
public class PromiseOperation<T> {
private let makePromise: () -> Promise<T>
public init(makePromise: @escaping () -> Promise<T>) {
self.makePromise = makePromise
}
@leandropjp
leandropjp / RealmObjectCodable.swift
Created April 8, 2019 13:39 — forked from ansonyao/RealmObjectCodable.swift
Realm Object Extension for Codable (RealmOptional and Realm List)
//
// RealmSwift+Codable.swift
//
// Created by Anson Yao on 7/25/18.
//
//Adding this file can make your classes inherited from Realm Object comfirm to Codable easily
//Inspired by @mishagray https://gist.github.com/mishagray/3ee82a3a82f357bfbf8ff3b3d9eca5cd
func savePdf(urlString:String, fileName:String) {
DispatchQueue.main.async {
let url = URL(string: urlString)
let pdfData = try? Data.init(contentsOf: url!)
let resourceDocPath = URL(fileURLWithPath: NSTemporaryDirectory())
let pdfNameFromUrl = "YourAppName-\(fileName).pdf"
let actualPath = resourceDocPath.appendingPathComponent(pdfNameFromUrl)
do {
try pdfData?.write(to: actualPath, options: .atomic)
@leandropjp
leandropjp / gist:dfaf7c0b4f82e361074de0f1caf46afb
Created July 18, 2018 01:58
Build increment when archiving
if [ $CONFIGURATION == Release ]; then
echo "Bumping build number..."
plist=${PROJECT_DIR}/${INFOPLIST_FILE}
# increment the build number (ie 115 to 116)
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "No build number in $plist"
exit 2
fi
@leandropjp
leandropjp / Device.swift
Created October 11, 2017 00:16 — forked from imkevinxu/Device.swift
iOS device checks for OS version and screen size in Swift
//
// Device.swift
// imHome
//
// Created by Kevin Xu on 2/9/15. Updated on 6/20/15.
// Copyright (c) 2015 Alpha Labs, Inc. All rights reserved.
//
import Foundation