Skip to content

Instantly share code, notes, and snippets.

View amosavian's full-sized avatar

Amir Abbas Mousavian amosavian

View GitHub Profile
//
// RedisValueHelper.swift
//
//
// Created by Amir Abbas Mousavian on 01/01/2020.
//
import Foundation
import Vapor
import NIO
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>iPhone5,1</key>
<string>iPhone 5 (GSM)</string>
<key>iPhone5,2</key>
<string>iPhone 5 (GSM+CDMA)</string>
<key>iPhone5,3</key>
<string>iPhone 5C (GSM)</string>
@amosavian
amosavian / UIKitEmbed.swift
Last active August 18, 2019 15:39
Helper methods to ease usage of auto-layout
extension UIViewController {
enum LayoutGuide {
case none
case layoutMargin
case readableContent
case safeArea
}
func embed(_ viewController: UIViewController, into: UIView? = nil, inset: UIEdgeInsets = .zero, edges: UIRectEdge = .all,
guide: UILayoutGuide? = nil, priorities: UIView.EdgePriorities = .init()) {
struct Bill: Codable {
let b: String
let c: String
}
struct B2: Codable {
enum CodingKeys: String, CodingKey { case a }
let bill: Bill
let a: Int
extension NSCoder {
func encode<T: RawRepresentable>(_ object: Any?, forKey key: T) where T.RawValue == String {
switch object {
case let object as Bool:
encode(object, forKey: key.rawValue)
case let object as Int32:
encode(object, forKey: key.rawValue)
case let object as Int64:
encode(object, forKey: key.rawValue)
case let object as Float:
@amosavian
amosavian / App-Bridging-Header.h
Last active February 11, 2019 16:10
Workaround OneSignal embargo
/// Add these lines to your app bridging header
#import <OneSignal/OneSignal.h>
#import "OneSignalTweak.h"
protocol A {
func foo() -> Int
}
extension A {
func foo() -> Int {
return 10
}
}
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if let response = task.response as? HTTPURLResponse, response.statusCode >= 400 {
return
}
// Workaround a CFNetwork bug which cause a write posix error.
// Invalidates session and start tasks again.
if let error = error as? POSIXError, error.code == .ENOENT {
session.invalidateAndCancel()
return
extension String {
private func regionalIndicatorSymbol(unicodeScalar: UnicodeScalar) -> UnicodeScalar? {
let uppercaseA = UnicodeScalar("A")!
let regionalIndicatorSymbolA = UnicodeScalar("\u{1f1e6}")!
let distance = unicodeScalar.value - uppercaseA.value
return UnicodeScalar(regionalIndicatorSymbolA.value + distance)
}
public var emojiFlag: String {
return self.uppercased().unicodeScalars.map({
@amosavian
amosavian / target-platform-condition.md
Last active December 12, 2017 21:27
Target platform condition Proposal for Swift

Target platform condition

Introduction