Skip to content

Instantly share code, notes, and snippets.

View ionel71089's full-sized avatar
🍎
Eating an apple.

Ionel Lescai ionel71089

🍎
Eating an apple.
View GitHub Profile
@PEZ
PEZ / UIControl+ListenBlock.swift
Created September 20, 2017 23:04
Swift3 UIControl extension for adding block event listeners. Adapted from: https://stackoverflow.com/a/44917661/44639
import Foundation
import UIKit
extension UIControl {
func listen(_ action: @escaping () -> (), for controlEvents: UIControlEvents) -> AnyObject {
let sleeve = ClosureSleeve(attachTo: self, closure: action, controlEvents: controlEvents)
addTarget(sleeve, action: #selector(ClosureSleeve.invoke), for: controlEvents)
return sleeve
}
@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.

@Azoy
Azoy / install-swift-ubuntu.md
Last active December 9, 2022 03:42
Guide on how to install Swift on Ubuntu

Install Swift on Ubuntu

Requirements

  1. Ubuntu 14.04, 16.04, or 16.10

Step 1 - Dependencies

  1. Open up terminal
  2. Install core deps: sudo apt-get install clang libicu-dev git

Step 1.1 - Ubuntu 14.04 Clang

@BenziAhamed
BenziAhamed / Templater.swift
Created January 18, 2017 23:33
My lame little templating engine in Swift
import Cocoa
// more of a POC
// not production ready
protocol PropertyReflectable { }
extension PropertyReflectable {
subscript(property key: String) -> Any? {
let mirror = Mirror(reflecting: self)
@eneko
eneko / xcodeclean.sh
Created July 19, 2016 00:04
xcodeclean
alias xcodeclean='rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*'
@nakiostudio
nakiostudio / UpdateRealmObject.swift
Last active June 25, 2019 14:04
Make RealmSwift write and update an Object keeping the existing relationships
/**
Writes a set of objects in the database.
- parameter objects: Array of `Objects` to be stored on the database
- parameter configuration: Realm `Configuration` in which the write action will be performed
- parameter update: Enabled the custom *update* maintaining existing relationships
*/
static func write(objects : [Object], configuration: Realm.Configuration, update: Bool = false) {
if let realm = try? Realm(configuration: configuration) {
realm.beginWrite()
@mlafeldt
mlafeldt / x.md
Created February 16, 2016 15:48
Providing a Homebrew tap backed by private GitHub repo

First of all, install Homebrew itself.

As the tap is a private Git repo, you need to generate a GitHub token with repo scope and then add this token to your ~/.netrc file like this:

machine github.com
  login <your GitHub user>
  password <your GitHub token>
@hilen
hilen / UIBarButtonItem+Block.swift
Last active February 15, 2023 12:08
Custom UINavigationItem and custom back item with block . Swift 2.0
//
// UIBarButtonItem+Block.swift
// IllidanSpeed
//
// Created by Hilen on 12/10/15.
// Copyright © 2015 IllidanSpeed. All rights reserved.
//
import Foundation
@epohs
epohs / ncurses.swift
Last active July 7, 2020 01:23
How to setup and use ncurses in a Swift script
#!/usr/bin/env xcrun swift -i
import Foundation
import Darwin.ncurses
initscr() // Init window. Must be first
cbreak()
noecho() // Don't echo user input
nonl() // Disable newline mode
intrflush(stdscr, true) // Prevent flush
@geekmanager
geekmanager / make-git-use-sublime.markdown
Last active July 3, 2023 12:22
Making git use Sublime Text for rebase etc

Making git use Sublime Text

First up, let's make Sublime Text 2 available from the command line in terminal, by creating a link to subl which is the launcher from terminal:

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

(added bonus of this approach is when you upgrade to ST3 or change text editor, you can just redirect the symlink).

If there's any chance that bash doesn't check usr/local/bin then use [Launch Sublime Text 2 from Mac OSX Terminal] for more detailed instructions on how to make this happen.