Skip to content

Instantly share code, notes, and snippets.

View chuganzy's full-sized avatar

Takeru Chuganji chuganzy

View GitHub Profile
# Description:
# シャッフルランチの管理をします
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
import Foundation
extension NSString {
func utf16IndexForIndex(index: Int) -> Int {
var index = index
var result = 0
while result < index {
if result + 1 < self.length &&
CFStringIsSurrogateHighCharacter(self.characterAtIndex(result)) &&
CFStringIsSurrogateLowCharacter(self.characterAtIndex(result + 1)) {
import Foundation
import AVFoundation
import RxSwift
import RxCocoa
extension AVCaptureSession {
var rx_runnning: AnyObserver<Bool> {
return RxBindingObserver(element: self) { element, value in
if value {
element.startRunning()
import Foundation
import AVFoundation
import RxSwift
import RxCocoa
private let associatedkey = UnsafePointer<Void>(malloc(1))
class RxCaptureMetadataOutputObjectsDelegateProxy: DelegateProxy, DelegateProxyType, AVCaptureMetadataOutputObjectsDelegate {
static func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) {
(object as! AVCaptureMetadataOutput)
import Foundation
import APIKit
import Himotoki
extension RequestType where Response: Decodable, Response.DecodedType == Response {
func responseFromObject(object: AnyObject, URLResponse: NSHTTPURLResponse) -> Response? {
return try? decode(object)
}
}
extension UIVisualEffectView {
var effectColor: UIColor? {
get {
return self.colorEffectView()?.backgroundColor
}
set {
self.colorEffectView()?.backgroundColor = newValue
}
}
private func colorEffectView() -> UIView? {
@chuganzy
chuganzy / APIKit+Rx.swift
Last active April 24, 2017 10:05
RxSwift x APIKit
import Foundation
import APIKit
import RxSwift
extension Session {
func rx_sendRequest<T: RequestType>(request: T) -> Observable<T.Response> {
return Observable.create { observer in
let task = self.sendRequest(request) { result in
switch result {
case .Success(let res):
#import <XCTest/XCTest.h>
@interface XCTestCase (Private)
- (void)_enqueueFailureWithDescription:(id)arg1 inFile:(id)arg2 atLine:(unsigned long long)arg3 expected:(_Bool)arg4;
@end
@interface UniversalLinksUITests : XCTestCase
@property (assign, nonatomic) BOOL ignoreFailure;
@end
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
guard let url = request.URL else {
return true
}
if url.scheme.rangeOfString("^https?", options: .RegularExpressionSearch) != nil {
return true
}
if !UIApplication.sharedApplication().canOpenURL(url) {
// iOS9でInfo.plistに登録してないとfalseになるのでここに来る
return false
@chuganzy
chuganzy / gist:fe383dce2c8be3c8ac3c
Last active December 13, 2015 14:11
マイナンバー チェックデジット
extension String {
func isValidMyNumber() -> Bool {
enum Error: ErrorType {
case NonNumber
}
let numbers: [Int]
do {
numbers = try self.characters.map { (char) -> Int in
guard let value = Int(String(char)) else {
throw Error.NonNumber