Skip to content

Instantly share code, notes, and snippets.

View pawankmrai's full-sized avatar
💭
I may be slow to respond.

Pawan Kumar Rai pawankmrai

💭
I may be slow to respond.
View GitHub Profile
import UIKit
class ExerciseOption: Decodable {
private enum ExerciseOptionCodingKeys: String, CodingKey {
case id
case appleHealthId = "apple_health_id"
case googleFitId = "google_fit_id"
case langsTranslation = "langs_translation"
}
@gokselkoksal
gokselkoksal / Channel.swift
Last active September 16, 2022 03:53
Channel implementation
public class Channel<Value> {
private class Subscription {
weak var object: AnyObject?
private let notifyBlock: (Value) -> Void
private let queue: DispatchQueue
var isValid: Bool {
return object != nil
@AliSoftware
AliSoftware / Coordinators-v2.swift
Last active May 4, 2023 12:26
Our implementation of the Coordinators pattern — V2, more strict than V1
// Coordinator.swift
import Foundation
public protocol Coordinator: class {
var components: CoordinatorComponents { get }
/// Set up here everything that needs to happen just before the Coordinator is presented
///
/// - Parameter modalSetup: A parameter you can use to customize the default mainViewController's
@lattner
lattner / TaskConcurrencyManifesto.md
Last active March 7, 2026 21:39
Swift Concurrency Manifesto
extension UIImageView {
/// Loads image from web asynchronosly and caches it, in case you have to load url
/// again, it will be loaded from cache if available
func load(url: URL, placeholder: UIImage?, cache: URLCache? = nil) {
let cache = cache ?? URLCache.shared
let request = URLRequest(url: url)
if let data = cache.cachedResponse(for: request)?.data, let image = UIImage(data: data) {
self.image = image
} else {
self.image = placeholder
@Bhavdip
Bhavdip / sketch-never-ending.md
Created October 6, 2016 15:53
Modify Sketch to never ending trial

###Sketch trial non stop

Open hosts files:

$ open /private/etc/hosts

Edit the file adding:

127.0.0.1 backend.bohemiancoding.com

127.0.0.1 bohemiancoding.sketch.analytics.s3-website-us-east-1.amazonaws.com

@delputnam
delputnam / TextColor.swift
Created June 25, 2016 12:27
Determine if a UIColor is light or dark
// Returns black if the given background color is light or white if the given color is dark
func textColor(bgColor: UIColor) -> UIColor {
var r: CGFloat = 0.0
var g: CGFloat = 0.0
var b: CGFloat = 0.0
var a: CGFloat = 0.0
var brightness: CGFloat = 0.0
bgColor.getRed(&r, green: &g, blue: &b, alpha: &a)
@k3zi
k3zi / MPNavigationAnimatedTransitiion.swift
Last active May 3, 2017 07:08
A basic transition that properly pushes off transparent views
import UIKit
class MPNavigationAnimatedTransitiion: NSObject, UIViewControllerAnimatedTransitioning {
let operation: UINavigationControllerOperation
init(operation: UINavigationControllerOperation) {
self.operation = operation
}
//
// UIBarButtonItem+Badge.swift
// PiGuardMobile
//
// Created by Stefano Vettor on 12/04/16.
// Copyright © 2016 Stefano Vettor. All rights reserved.
//
import UIKit
@jaanus
jaanus / gist:fdf0e9ab0fc64c029610
Created March 25, 2015 17:58
Create NSAttributedString out of NSString with Markdown-like syntax for bold text and links.
#if TARGET_OS_IPHONE
@import UIKit;
#define JKColor UIColor
#define JKFont UIFont
#else
@import AppKit;
#define JKColor NSColor
#define JKFont NSFont
#endif