Skip to content

Instantly share code, notes, and snippets.

View eleev's full-sized avatar

Astemir Eleev eleev

View GitHub Profile
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 /
Last active November 23, 2023 04:43 — forked from oleganza/
Concrete proposal for async semantics in Swift

Async/Await for Swift


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 / 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)
let image = UIGraphicsGetImageFromCurrentImageContext()
guard let cgImage = image?.cgImage else { return nil }
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 / 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 / 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
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 / System
Last active November 28, 2023 07:50
System Design Cheatsheet
View System

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 / 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\
rm -Rf ~/Library/Preferences/AndroidStudio*
rm ~/Library/Preferences/
rm -Rf ~/Library/Application\ Support/AndroidStudio*
rm -Rf ~/Library/Logs/AndroidStudio*