This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let url = Bundle.main.url(forResource: "cat1", withExtension: "jpg")! | |
let size: CGSize = CGSize(width: 60, height: 90) | |
let scale = UIScreen.main.scale | |
// Bind the URL to the object without decoding (will not use memory yet). | |
let options = [kCGImageSourceShouldCache:false] as CFDictionary | |
let source = CGImageSourceCreateWithURL(url as CFURL, options) | |
let dimension = max(size.width, size.height) * scale |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run (https://github.com/wilddylan/WKWebViewWithURLProtocol) | |
// Be aware it is a private API, it is wisely handled and shouldn't be a prloblem at Apple's code review | |
[NSURLProtocol wk_registerScheme:@"http"]; | |
// URLProtocol.h | |
#import <Foundation/Foundation.h> | |
@interface URLProtocol : NSURLProtocol |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GCDWebServer *_webServer = [[GCDWebServer alloc] init]; | |
[_webServer addDefaultHandlerForMethod:@"GET" | |
requestClass:[GCDWebServerRequest class] | |
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) { | |
GCDWebServerDataResponse *response = [GCDWebServerDataResponse responseWithHTML:@"true"]; | |
[response setValue:@"*" forAdditionalHeader:@"Access-Control-Allow-Origin"]; | |
[response setValue:@"X-Requested-With, Content-Type" forAdditionalHeader:@"Access-Control-Allow-Headers"]; | |
[response setValue:@"GET, POST, OPTIONS" forAdditionalHeader:@"Access-Control-Allow-Methods"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do not jump to initila state after animation completed. | |
CATransaction.begin() | |
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions) | |
self.maskShape.path = toPath | |
CATransaction.commit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@discardableResult | |
func measureTime<R>(name: String = #function, body: () -> R) -> R { | |
#if DEBUG | |
let startTime = CACurrentMediaTime() | |
let result: R = body() | |
let endTime = CACurrentMediaTime() | |
print("execution time of \(name): \(endTime - startTime)") | |
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
func findFirstSubview(with className: String) -> UIView? { | |
if String(describing: type(of: self)) == className { | |
return self | |
} | |
for subview in subviews { | |
if String(describing: type(of: self)) == className { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
func gradientImage(_ colors: [UIColor]) -> UIImage? { | |
guard let source = withRenderingMode(.alwaysTemplate).cgImage else { | |
return nil | |
} | |
// Create gradient | |
let cgColors = colors.map({ $0.cgColor }) | |
let colors = cgColors as CFArray | |
let space = CGColorSpaceCreateDeviceRGB() | |
guard let gradient = CGGradient(colorsSpace: space, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface ApplicationDelegateProxyType () | |
@property (nonnull, nonatomic) NSArray<id <UIApplicationDelegate>> *objects; | |
@end | |
@implementation ApplicationDelegateProxyType |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIRectCorner { | |
func asCornerMask() -> CACornerMask { | |
var corners: CACornerMask = [] | |
if self.contains(.bottomRight) { | |
corners.insert(.layerMaxXMaxYCorner) | |
} | |
if self.contains(.topRight) { | |
corners.insert(.layerMaxXMinYCorner) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'webrick' | |
require 'webrick/https' | |
require 'openssl' | |
require 'json' | |
# curl https://localhost:port/test (pass '-k' to accept self signed certificate) | |
# openssl req -x509 -newkey rsa:4096 -keyout priv.pem -out cert.pem -days 365 -nodes | |
# cert = OpenSSL::X509::Certificate.new File.read 'cert.pem' | |
# pkey = OpenSSL::PKey::RSA.new File.read 'priv.pem' |
NewerOlder