Skip to content

Instantly share code, notes, and snippets.

View tsarikovskiy's full-sized avatar
๐ŸŽฏ
Focusing

Serhii Tsarikovskyi tsarikovskiy

๐ŸŽฏ
Focusing
View GitHub Profile
protocol DefaultDecodable: Decodable {
associatedtype FallbackType: Decodable
static var fallback: FallbackType { get }
}
extension KeyedDecodingContainerProtocol {
func decodeValue<T: DefaultDecodable>(_ type: T.Type, forKey key: Self.Key) throws -> T {
return try decodeIfPresent(type, forKey: key) ?? T.fallback as! T
}
}
import SwiftyJSON
class JsonTestFileHandler {
enum FilePath: String {
case funnelSettings = "Settings.json"
}
static func writeTo(file filePath: FilePath, json: JSON) {
let currentFilePathArray = #file.split(separator: "/")
.map { String($0) }
@discardableResult
func measure<A>(name: String = "", _ block: () -> A) -> A {
let startTime = CACurrentMediaTime()
let result = block()
let timeElapsed = CACurrentMediaTime() - startTime
print("Time: \(name) - \(timeElapsed)")
return result
}
extension URLRequest {
public var curlString: String {
// Logging URL requests in whole may expose sensitive data,
// or open up possibility for getting access to your user data,
// so make sure to disable this feature for production builds!
#if !DEBUG
return ""
#else
var result = "curl -k "
@tsarikovskiy
tsarikovskiy / gist:2b8062bedfa6525ddae78852a0f7f5e2
Created February 23, 2018 08:06
UIViewController+TopViewController.swift
extension UIViewController {
public var isTopViewController: Bool {
if let navigationController = navigationController {
return navigationController.visibleViewController === self
} else if let tabBarController = tabBarController {
return tabBarController.selectedViewController == self && presentedViewController == nil
} else {
return presentedViewController == nil && isVisible
}
}
@tsarikovskiy
tsarikovskiy / OwnershipTLDR.md
Created December 20, 2017 15:31 — forked from Gankra/OwnershipTLDR.md
Swift Ownership Manifesto TL;DR

Swift Ownership Manifesto TL;DR

Most of the manifesto is background and detailed definitions -- if you're confused or want details, read the manifesto!

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170213/032155.html

Note also that manifestos aren't complete proposals -- syntax and details may change!

One piece of background: inout is kinda complicated because it can be used on computed properties -- foo(&val.x) might be sugar for

@tsarikovskiy
tsarikovskiy / gist:28e0d121269396a9ad3d3fc46343a156
Created December 15, 2017 11:15 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: ๐Ÿ˜„ :smile: ๐Ÿ˜† :laughing:
๐Ÿ˜Š :blush: ๐Ÿ˜ƒ :smiley: โ˜บ๏ธ :relaxed:
๐Ÿ˜ :smirk: ๐Ÿ˜ :heart_eyes: ๐Ÿ˜˜ :kissing_heart:
๐Ÿ˜š :kissing_closed_eyes: ๐Ÿ˜ณ :flushed: ๐Ÿ˜Œ :relieved:
๐Ÿ˜† :satisfied: ๐Ÿ˜ :grin: ๐Ÿ˜‰ :wink:
๐Ÿ˜œ :stuck_out_tongue_winking_eye: ๐Ÿ˜ :stuck_out_tongue_closed_eyes: ๐Ÿ˜€ :grinning:
๐Ÿ˜— :kissing: ๐Ÿ˜™ :kissing_smiling_eyes: ๐Ÿ˜› :stuck_out_tongue:
# =============== #
# Unity generated #
# =============== #
[Tt]emp/
[Oo]bj/
[Bb]uild
[Ll]ibrary/
sysinfo.txt
*.stackdump
@tsarikovskiy
tsarikovskiy / GetStreamingAssetsPath.cs
Created September 23, 2015 09:49 — forked from amowu/GetStreamingAssetsPath.cs
Get Unity StreamingAssets file path with Android and iOS.
// Put your file to "YOUR_UNITY_PROJ/Assets/StreamingAssets"
// example: "YOUR_UNITY_PROJ/Assets/StreamingAssets/db.bytes"
string dbPath = "";
if (Application.platform == RuntimePlatform.Android)
{
// Android
string oriPath = System.IO.Path.Combine(Application.streamingAssetsPath, "db.bytes");