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 January 1, 2024 12:08
Programmatically create iOS 13 dynamic images
- (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 / TaskConcurrencyManifesto.md
Last active May 5, 2024 22:32
Swift Concurrency Manifesto
@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

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
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
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)
import UIKit
extension UIImage {
public func fixedOrientation() -> UIImage {
if imageOrientation == UIImageOrientation.up {
return self
}
@eleev
eleev / URLForPHAsset.swift
Last active February 17, 2024 23:56
Getting URL for PHAsset (Swift 3.0)
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
import Foundation
fileprivate protocol Statelike {
var stateMachine: StateMachine { get }
func logIn()
func logOut()
}
extension Statelike {
func logIn() {}
@vasanthk
vasanthk / System Design.md
Last active May 6, 2024 13:07
System Design Cheatsheet

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
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*