Skip to content

Instantly share code, notes, and snippets.

View Ezimetjan's full-sized avatar

Ezimet Imam Ezimetjan

View GitHub Profile
@Ezimetjan
Ezimetjan / NSNumber.isReal().swift
Created September 9, 2021 18:46 — forked from krzyzanowskim/NSNumber.isReal().swift
Check if NSNumber value is integer or real value
import Cocoa
extension NSNumber {
func isDouble() -> Bool {
guard let encoding = String.fromCString(self.objCType) else {
return false
}
return encoding == "d"
}
@Ezimetjan
Ezimetjan / async_swift_proposal.md
Created August 18, 2021 19:51 — forked from lattner/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.

@Ezimetjan
Ezimetjan / AsyncOperation.swift
Created January 3, 2021 04:40 — forked from ole/AsyncOperation.swift
An (NS)Operation subclass for async operations
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must override `main()` to perform any work and call `finish()`
/// when they are done. All `NSOperation` work will be handled automatically.
///
/// Source/Inspiration: https://stackoverflow.com/a/48104095/116862 and https://gist.github.com/calebd/93fa347397cec5f88233
open class AsyncOperation: Operation {
public init(name: String? = nil) {
super.init()
@Ezimetjan
Ezimetjan / MacEditorTextView.swift
Created December 26, 2020 04:52 — forked from unnamedd/MacEditorTextView.swift
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@Ezimetjan
Ezimetjan / StreamReader.swift
Created September 22, 2020 17:54 — forked from sooop/StreamReader.swift
Read a large text file line by line - Swift 3
import Foundation
class StreamReader {
let encoding: String.Encoding
let chunkSize: Int
let fileHandle: FileHandle
var buffer: Data
let delimPattern : Data
var isAtEOF: Bool = false
BIG iOS URL SCHEME LIST
HAD TO MAKE A DROPBOX FILE BECAUSE THIS LIST WAS TOO LONG TO POST IN THE COMMENTS OR NOT MAKE THE WORKFLOW APP TAKE FOREVER TO READ IT.
☠JAILBREAK/SYSTEM APPS
--------------------------
activator://
itms-apps://
itms-services://
@Ezimetjan
Ezimetjan / querystring.swift
Created February 16, 2017 09:53 — forked from gillesdemey/querystring.swift
Retrieve specific query string parameter from NSURL
func getQueryStringParameter(url: String, param: String) -> String? {
let url = NSURLComponents(string: url)!
return
(url.queryItems? as [NSURLQueryItem])
.filter({ (item) in item.name == param }).first?
.value()
}
@Ezimetjan
Ezimetjan / scrollViewWillEndDragging.swift
Created December 14, 2016 16:00 — forked from anonymous/scrollViewWillEndDragging.swift
iOS: Example of how to use UIScrollViewDelegate's scrollViewWillEndDecelerating method in Swift
func scrollViewWillEndDragging (scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
// how to get value from targetContentOffset:
let y = targetContentOffset.memory.y
// how to set value to targetContentOffset:
targetContentOffset.memory.y = 0 //i.e. amount * value
}
@Ezimetjan
Ezimetjan / htmltest.m
Created April 7, 2016 11:31 — forked from romaonthego/htmltest.m
UITextView with HTML text (iOS 7)
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] init];
textView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:textView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />";
@Ezimetjan
Ezimetjan / markup.swift
Created September 25, 2015 17:15
Swift Playground MarkupFormat
//: Playground - noun: a place where people can play
//: Markup Format
// Heading #
/*:
# Heading1 in Block