This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
private func angle(_ degree: Double) -> CGFloat { | |
return CGFloat(Double.pi * degree / 180.0) | |
} | |
let bounds = CGRect(x: 0, y: 0, width: 150, height: 100) | |
// corner radius for bottom right, bottom left, top left, and top right | |
let r: (CGFloat, CGFloat, CGFloat, CGFloat) = (5, 10, 20, 40) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ReactiveSwift | |
import enum Result.NoError | |
extension BindingSource { | |
@discardableResult | |
func bind<P: BindingTargetProvider>(to provider: P) -> Disposable? where P.Value == Value, Error == NoError { | |
return provider <~ self | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let hexString = "0123456789abcdefABCDEF" | |
let bytes = zip(hexString.characters, hexString.characters.dropFirst()) | |
.enumerated() | |
.filter { $0.offset % 2 == 0 } | |
.map { String([$0.element.0, $0.element.1]) } | |
.flatMap { UInt8($0, radix: 16) } | |
Data(bytes: bytes) as NSData // <01234567 89abcdef abcdef> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let hexString = "0123456789abcdefABCDEF" | |
var bytes = [UInt8]() | |
var index = hexString.startIndex | |
while let i = hexString.index(index, offsetBy: 2, limitedBy: hexString.endIndex) { | |
let byteLiteral = hexString.substring(with: index..<i) | |
guard let byte = UInt8(byteLiteral, radix: 16) else { continue } | |
bytes.append(byte) | |
index = i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let hexString = "0123456789abcdefABCDEF" | |
let even = hexString.characters.enumerated().filter { $0.offset % 2 == 0 }.map { $0.element } | |
let odd = hexString.characters.enumerated().filter { $0.offset % 2 == 1 }.map { $0.element } | |
let bytes = zip(even, odd).flatMap { UInt8(String([$0.0, $0.1]), radix: 16) } | |
Data(bytes: bytes) as NSData // <01234567 89abcdef abcdef> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BLEPeripheral.swift | |
// BLEPeripheral | |
// | |
// Created by ooba on 26/07/2017. | |
// Copyright © 2017 mercari. All rights reserved. | |
// | |
import Foundation | |
import CoreBluetooth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BLEDump.swift | |
// BLEDump | |
// | |
// Created by Shinichiro Oba on 2017/07/25. | |
// Copyright © 2017 Shinichiro Oba. All rights reserved. | |
// | |
import Foundation | |
import CoreBluetooth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
func createImage(text: String, fontSize: CGFloat, imageSize: CGSize) -> UIImage? { | |
UIGraphicsBeginImageContextWithOptions(imageSize, false, 0) | |
guard let context = UIGraphicsGetCurrentContext() else { return nil } | |
let rect = CGRect(x: 0, y: 0, width: imageSize.width, height: imageSize.height) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import APIKit | |
import RxSwift | |
import ReactiveSwift | |
import Result | |
extension Session : RxSwift.ReactiveCompatible {} | |
extension RxSwift.Reactive where Base: Session { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import lldb | |
def process(debugger, command, result, internal_dict): | |
lldb.debugger.HandleCommand(""" | |
expr -l swift -- | |
func $process(object: AnyObject) { | |
func json(object: AnyObject) -> String { | |
if let data = try? NSJSONSerialization.dataWithJSONObject(object, options: .PrettyPrinted) { |