Skip to content

Instantly share code, notes, and snippets.

View eleev's full-sized avatar

Astemir Eleev eleev

View GitHub Profile
@timonus
timonus / programmatic-dynamic-images.m
Last active June 27, 2023 22:41
Programmatically create iOS 13 dynamic images
View programmatic-dynamic-images.m
- (UIImage *)dynamicImage
{
UITraitCollection *const baseTraitCollection = /* an existing trait collection */;
UITraitCollection *const lightTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]]];
UITraitCollection *const purelyDarkTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
UITraitCollection *const darkTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[baseTraitCollection, purelyDarkTraitCollection]];
__block UIImage *lightImage;
[lightTraitCollection performAsCurrentTraitCollection:^{
lightImage = /* draw image */;
@lattner
lattner / async_swift_proposal.md
Last active November 23, 2023 04:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift
View async_swift_proposal.md

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@eleev
eleev / UIImage+SolidColor.swift
Created March 24, 2017 11:18
Extension for creating UIImage from a UIColor. Swift 3
View UIImage+SolidColor.swift
extension UIImage {
convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
let rect = CGRect(origin: .zero, size: size)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
color.setFill()
UIRectFill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
guard let cgImage = image?.cgImage else { return nil }
@jay18001
jay18001 / Matrix4.swift
Created February 24, 2017 02:57
Swift version of helper class from Ray Wenderlich: Metal Tutorial with Swift 3 Part 2
View Matrix4.swift
import UIKit
import GLKit
extension Float {
var radians: Float {
return GLKMathDegreesToRadians(self)
}
}
class Matrix4 {
@matthiasnagel
matthiasnagel / UIImageFixedOrientationExtension.swift
Created January 19, 2017 09:36 — forked from schickling/UIImageFixedOrientationExtension.swift
Extension to fix orientation of an UIImage (Sets orientation to portrait)
View UIImageFixedOrientationExtension.swift
import UIKit
extension UIImage {
public func fixedOrientation() -> UIImage {
if imageOrientation == UIImageOrientation.up {
return self
}
@eleev
eleev / URLForPHAsset.swift
Last active November 2, 2022 10:44
Getting URL for PHAsset (Swift 3.0)
View URLForPHAsset.swift
func getURL(ofPhotoWith mPhasset: PHAsset, completionHandler : @escaping ((_ responseURL : URL?) -> Void)) {
if mPhasset.mediaType == .image {
let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
return true
}
mPhasset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in
completionHandler(contentEditingInput!.fullSizeImageURL)
})
@velyan
velyan / StateMachine.swift
Last active March 4, 2020 18:31
Swift State Pattern
View StateMachine.swift
import Foundation
fileprivate protocol Statelike {
var stateMachine: StateMachine { get }
func logIn()
func logOut()
}
extension Statelike {
func logIn() {}
@vasanthk
vasanthk / System Design.md
Last active November 28, 2023 07:50
System Design Cheatsheet
View System Design.md

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@tahmidsadik
tahmidsadik / purgeAndroid.txt
Created September 19, 2015 18:47
How to completely remove Android Studio from Mac OS X
View purgeAndroid.txt
How to Completely Remove Android Studio
Execute these commands from the terminal
rm -Rf /Applications/Android\ Studio.app
rm -Rf ~/Library/Preferences/AndroidStudio*
rm ~/Library/Preferences/com.google.android.studio.plist
rm -Rf ~/Library/Application\ Support/AndroidStudio*
rm -Rf ~/Library/Logs/AndroidStudio*