Skip to content

Instantly share code, notes, and snippets.

View garkhipov's full-sized avatar

Gleb Arkhipov garkhipov

  • Amsterdam, Netherlands
View GitHub Profile
@garkhipov
garkhipov / SmartXCUICoordinate.swift
Created November 19, 2016 10:58
Workaround for XCUICoordinate in landscape
import XCUI
class SmartXCUICoordinate
{
let element: XCUIElement
let normalizedOffset: CGVector
init(element: XCUIElement, normalizedOffset offset: CGVector) {
self.element = element
self.normalizedOffset = offset
@garkhipov
garkhipov / Watchdog.swift
Created January 9, 2016 23:23
Quick and dumb main thread watchdog that fires *before* the main thread is done
// WARNING: No thought involved while writing this, introduce some prior to production use. I warned you.
var timer: dispatch_source_t!
func startWatchdog() {
let q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
guard let timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, q) else { return }
self.timer = timer
dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, 0), NSEC_PER_SEC / 10, (UInt64(1) * NSEC_PER_SEC) / 10)
dispatch_source_set_event_handler(timer) {
@garkhipov
garkhipov / TaggedPointers.m
Created December 8, 2015 09:48
NSNumber tagged pointers
NSNumber *a = @5;
NSNumber *b = @5;
NSLog(@"%d", a == b); // 1
NSNumber *c = @(NSIntegerMax);
NSNumber *d = @(NSIntegerMax);
NSLog(@"%d", c == d); // 0
@garkhipov
garkhipov / example.swift
Created April 24, 2015 16:05
Swift 1.2 segmentation fault example
enum E {
case A
case B
}
let dict: [String: E?] = [
"a": nil,
"c": .A
]
@garkhipov
garkhipov / DateFormatters.swift
Created April 15, 2015 13:56
NSDateFormatter and NSDateComponentsFormatter example
import Foundation
let locale = NSLocale(localeIdentifier: "ru_RU")
let dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = .ShortStyle
dateFormatter.dateStyle = .MediumStyle
dateFormatter.locale = locale
dateFormatter.doesRelativeDateFormatting = true
@garkhipov
garkhipov / gist:41a088998af07d66be6c
Created March 31, 2015 10:28
Optional chaining inside closure
// http://stackoverflow.com/questions/29365781/weird-behavious-using-optionals-inside-closure
struct GameSettings {}
protocol Delegate {
func didFinishSettings(settings: GameSettings, controller: Controller)
}
class Controller {