Skip to content

Instantly share code, notes, and snippets.

View inamiy's full-sized avatar

Yasuhiro Inami inamiy

View GitHub Profile
@inamiy
inamiy / gist:b75cba8916716c81dd7d
Created December 5, 2015 15:51
swift-package-manager + SwiftState 4.0.0-RC build failure in Ubuntu 14.04
root@7093981bc8fc:~/PackageTest# swift build
Compiling Swift Module 'SwiftState' (14 sources)
swift: /home/buildslave/jenkins/workspace/oss-swift-linux-packages-ubuntu_14_04-one-off-build/swift/lib/SILPasses/IPO/CapturePromotion.cpp:831: swift::SILFunction *constructClonedFunction(swift::PartialApplyInst *, swift::FunctionRefInst *, IndicesSet &): Assertion `!genericSig && "Function type has Unexpected generic signature!"' failed.
0 swift 0x0000000002f15268 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000002f13a36 llvm::sys::RunSignalHandlers() + 54
2 swift 0x0000000002f15d9a
3 libpthread.so.0 0x00007f1e39e14340
4 libc.so.6 0x00007f1e3903ccc9 gsignal + 57
5 libc.so.6 0x00007f1e390400d8 abort + 328
6 libc.so.6 0x00007f1e39035b86
@inamiy
inamiy / String+Horspool.swift
Last active April 1, 2016 15:45
Boyer-Moore-Horspool Algorithm in Swift
extension String
{
// https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore%E2%80%93Horspool_algorithm
// http://www.cin.br/~paguso/courses/if767/bib/Horspool_1980.pdf
public func indexOf_horspool(pattern: String) -> String.Index?
{
let patternLength = pattern.characters.count
assert(patternLength > 0)
assert(patternLength <= self.characters.count)
@inamiy
inamiy / mutableArrayValueForKey-weak.m
Created March 23, 2015 01:17
mutableArrayValueForKey + weak is not really weak...
- (void)testExample {
MyObject* obj = [[MyObject alloc] init];
obj.array = @[];
NSMutableArray* array = [obj mutableArrayValueForKey:@"array"];
// NSMutableArray* array = @[].mutableCopy; // using this will pass test
__weak NSMutableArray* weakArray = array;
@inamiy
inamiy / deckset-hyperlink-test.md
Created August 7, 2016 02:13
Deckset v1.6.2 hyperlink bug
@inamiy
inamiy / DiscardableResultBug.swift
Last active September 18, 2016 18:16
@discardableResult bug in Swift 3 (Xcode 8) when Optional chaining + Optional return value https://bugs.swift.org/browse/SR-2687
// # Bug description
// `@discardableResult` won't work when:
// 1. optional chaining
// 2. function returns Optional + non-Void value
//
// ## See also
// - https://bugs.swift.org/browse/SR-1052
// - https://bugs.swift.org/browse/SR-1681
// - https://bugs.swift.org/browse/SR-1929
@inamiy
inamiy / SignalProducerSpec.diff
Created November 3, 2016 05:09
ReactiveSwift 1.0.0-alpha.3 (RAC5) Bug: Inner signal not interrupted on outer signal disposal
diff --git Tests/ReactiveSwiftTests/SignalProducerSpec.swift Tests/ReactiveSwiftTests/SignalProducerSpec.swift
index 21362e7..a363327 100644
--- Tests/ReactiveSwiftTests/SignalProducerSpec.swift
+++ Tests/ReactiveSwiftTests/SignalProducerSpec.swift
@@ -1413,13 +1413,14 @@ class SignalProducerSpec: QuickSpec {
}
}
- describe("disposal") {
+ fdescribe("disposal") {
@inamiy
inamiy / void-func-type-inference-swift4.swift
Last active June 11, 2017 16:20
'() -> ()' type inference doesn't work in Swift 4
func test<T>(_ f: (T) -> Void) {}
let intF: (Int) -> Void = { _ in }
let voidF: () -> Void = { }
test(intF) // works
//test(voidF) // error: cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'
//: # Workaround for zero-argument func to be passed into `test`
@inamiy
inamiy / swift-instance-method-retain-cycle-behavior.swift
Created June 15, 2017 03:37
Swift instance-method retain cycle behavior
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class A: NSObject {
let name: String
var callback: (() -> ())?
func funcDo() {}
@inamiy
inamiy / swift3.1-build-time.swift
Last active June 26, 2017 03:37
Swift 3.1 Build Time
class MyObj {
let arr1: [Int] = Array(0...100)
// Test A: Source Element = Typed
// 9.1ms
func test1() {
let arr = arr1
.filter { $0 % 2 == 0 }
@inamiy
inamiy / swift-backward-type-inference.swift
Created July 10, 2017 08:42
Swift backward type inference doesn't work
import Foundation
struct DebugTimeInterval: ExpressibleByFloatLiteral {
let rawValue: TimeInterval
public init(floatLiteral value: TimeInterval) {
self.rawValue = value
}
var tweaked: TimeInterval {