Skip to content

Instantly share code, notes, and snippets.

View MP0w's full-sized avatar
🏍️

Alex Manzella MP0w

🏍️
View GitHub Profile
@MP0w
MP0w / MergeSort.playground
Created January 15, 2016 22:32
MergeSort playground
//: Playground - noun: a place where people can play
import UIKit
func mergeArrays<T: Comparable>(left: [T], _ right: [T]) -> [T] {
var leftIndex = 0
var rightIndex = 0
var orderedArray = [T]()
while leftIndex < left.count && rightIndex < right.count {
@MP0w
MP0w / SILSegFault.swift
Created March 13, 2016 17:11
SIL segmentation fault (same crash as https://bugs.swift.org/browse/SR-358 , already fixed)
public protocol A {
func methodName()
}
extension A {
func methodName(differentParam: Any) {}
}
class Test: A {}
@MP0w
MP0w / arrayOfRanges.swift
Created March 17, 2016 21:19
Compiler Infinite loop [SR-774]
let someRanges = [1..<4, 1..<8, 1..<16, 1..<32, 1..<64, 1..<128, 1..<256, 1..<512, 1..<1024]
@MP0w
MP0w / CustomLayerView.swift
Created April 14, 2016 13:21
Generic view with custom layer class
class CustomLayerView<T: CALayer>: UIView {
var customLayer: T {
get {
return self.layer as! T
}
}
override class func layerClass() -> AnyClass {
return T.self
@MP0w
MP0w / SwiftCompilerDebugTime
Created May 3, 2016 09:22
SwiftCompilerDebugTime
-Xfrontend -debug-time-function-bodies
Found somewhere:
pbpaste | egrep '\.[0-9]ms' | sort -t "." -k 1 -n | tail -20
@MP0w
MP0w / ScrollMatcher.swift
Created November 16, 2016 11:52
ScrollMatcher
import Foundation
import UIKit
import Nimble
func scroll(_ axis: UILayoutConstraintAxis) -> ScrollMatcher {
return ScrollMatcher(axis: axis)
}
struct ScrollMatcher: Matcher {
@MP0w
MP0w / IntrinsicSizeAwareScrollView.swift
Created November 29, 2016 13:47
A `UIScrollView` subclass that adapts its `intrinsicContentSize` to its `contentSize`
import Foundation
import UIKit
/// A `UIScrollView` subclass that adapts its `intrinsicContentSize` to its `contentSize`
final class IntrinsicSizeAwareScrollView: UIScrollView {
private let keyPath = NSStringFromSelector(#selector(getter: contentSize))
override init(frame: CGRect) {
super.init(frame: frame)
@MP0w
MP0w / dummy.swift
Last active January 13, 2017 10:56
Dummy
import Foundation
/// Creates a Test dummy of the needed type!
/// Works with any value type or class (?)
func dummy<T>() -> T {
let size = MemoryLayout<T>.size
let alignment = MemoryLayout<T>.alignment
let p = UnsafeMutableRawPointer.allocate(bytes: size, alignedTo: alignment)
return p.bindMemory(to: T.self, capacity: 1).pointee
@MP0w
MP0w / CallRecordMatcher.swift
Created January 13, 2017 11:32
A matcher to spy
//
// CallRecordMatcher.swift
// Verse
//
// Created by Alex Manzella on 13/01/17.
// Copyright © 2017 Verse Technologies, Inc. All rights reserved.
//
import Foundation
import Nimble
@MP0w
MP0w / ConstraintPriorityPlayground.swift
Last active February 16, 2017 22:01
Add Strideble to ConstraintPriority
//: Playground - noun: a place where people can play
import Foundation
public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable, Strideable {
public typealias FloatLiteralType = Float
public typealias Stride = Float
public let value: Float