Skip to content

Instantly share code, notes, and snippets.

View aChase55's full-sized avatar

Alex Chase aChase55

  • Los Angeles
View GitHub Profile

Keybase proof

I hereby claim:

  • I am achase55 on github.
  • I am achase (https://keybase.io/achase) on keybase.
  • I have a public key ASBaMNAosgYvs_nf0BLeiB9kEk4a3oNUrpVmzx2fgUhNlgo

To claim this, I am signing this object:

@aChase55
aChase55 / UIColor+Array.swift
Created February 13, 2018 05:46
Expressing RGB Colors as Arrays in Swift
//Cleanly instantiate UIColors using 1 or 3 Int, Double, Float, or CGFloat Values
//UIColor convience initializer UIColor(4, 20, 69)
//UIColor convience initializer for gray(all three values the same) UIColor(69)
//Instantiate gray from a number: 210.rgbTriple()
//Instantiate color from an array of numbers:[40, 33, 60].rgbColor()
//Optionally express an alpha value
//UIColor(4, 20, 69, 0.4)
#if defined(TARGET_IOS) || defined(TARGET_TVOS)
@import UIKit;
#define PlatformViewController UIViewController
#else
@import AppKit;
#define PlatformViewController NSViewController
#endif
// Our view controller
@interface MyViewController : PlatformViewController
@aChase55
aChase55 / AsyncOperation.swift
Last active September 19, 2018 16:50
An Operation subclass that does work asynchronously
import Foundation
class AsyncOperation: Operation {
private var _isFinished: Bool = false
private var _isExecuting: Bool = false
open func execute() { assertionFailure("Overide execute() in subclass") }
override var isAsynchronous: Bool { return true }
@aChase55
aChase55 / gist:f095bf5f4586fcdc3ccfb859b3ff572e
Created November 3, 2018 19:38
Objc Random UIColor macro
#define RANDOM_COLOR [[UIColor alloc] initWithRed:arc4random()%256/256.0 green:arc4random()%256/256.0 blue:arc4random()%256/256.0 alpha:1.0]
@aChase55
aChase55 / RoundedCornerView.h
Created January 4, 2019 23:19
Rounded Corner View
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface RoundedCornerView : UIView
@property (nonatomic) IBInspectable CGFloat cornerRadius;
@end
NS_ASSUME_NONNULL_END
@aChase55
aChase55 / UIImage+Loading.swift
Created February 18, 2019 23:51
Alamofire image
import Foundation
import Alamofire
import AlamofireImage
extension UIImageView {
func loadImage(_ url:String?) {
guard let url = url else { return }
Alamofire.request(url).responseImage {[weak self] response in
guard let self = self else { return }
if let image = response.result.value {
@aChase55
aChase55 / CGPointOffset.swift
Created June 6, 2019 02:58
SwiftUI CGPoint Offset
import SwiftUI
extension View {
public func offset(_ offset: CGPoint) -> Self.Modified<_OffsetEffect> {
self.offset(x: offset.x, y: offset.y)
}
}
struct ContentView : View {
@aChase55
aChase55 / TextSlider.swift
Last active June 8, 2019 16:56
Text Slider
import SwiftUI
extension View {
public func offset(_ offset: CGPoint) -> Self.Modified<_OffsetEffect> {
self.offset(x: offset.x, y: offset.y)
}
}
struct ContentView : View {
@State var location: Double = 0
@aChase55
aChase55 / StringOrInt.swift
Last active July 11, 2019 19:47
StringOrInt Codable
enum StringOrInt: Codable {
case string(String)
case int(Int)
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let value = try? container.decode(Int.self) {
self = .int(value)
return
}