Skip to content

Instantly share code, notes, and snippets.

View gamako's full-sized avatar

SUGAMA Tatsuo gamako

  • SST Inc.
  • Japan
View GitHub Profile
@gamako
gamako / AppDelegate.swift
Last active March 30, 2020 09:57
Xcode11.4でビルドすると32bit iPhoneでクラッシュするサンプルコード
import UIKit
protocol P {
init()
}
struct AAA : P {
}
struct BBB<T: P> {
let a : Int = 0
@gamako
gamako / SwiftStringCompare.swift
Last active December 20, 2018 08:45
swift version string compare
import Foundation
ComparisonResult.orderedAscending.rawValue // -1
ComparisonResult.orderedSame.rawValue // 0
ComparisonResult.orderedDescending.rawValue // 1
"1.0.0".compare("1.0.1", options: .numeric, range: nil, locale: nil).rawValue // -1 (orderedAscending)
"1.0.0".compare("1.0.0", options: .numeric, range: nil, locale: nil).rawValue // 0 (orderedSame)
"1.0.0".compare("0.9.9", options: .numeric, range: nil, locale: nil).rawValue // 1 (orderedDescending)
@gamako
gamako / show-apple-device.js
Last active July 17, 2018 05:13
create Apple device list in Apple Developer Site
// print Apple Device List (https://developer.apple.com/account/ios/device/iphone) on Chrome Developer Console
Array.from({length: $("tr").filter((i,o)=>/^[0-9]+$/.test(o.id)).length}, (v, k) => k).forEach(j=>{var i=j+1;setTimeout(()=>{;$("tr#"+i).click()},100*i);setTimeout(()=>{console.log(""+i+",", ["dd.name","dd.model","dd.deviceNumber"].map((s)=>'"'+$('tr#'+i+'+tr').find(s).text()+'"').join())},50+100*i);})
@gamako
gamako / String+hex.swift
Last active March 21, 2024 02:51
Convert Hexadecimal String to Array<Uint> or Data with Swift3 style.
import Foundation
// "".hexData.hexString //
// "01".hexData.hexString // 01
// "ab".hexData.hexString // ab
// "abff 99".hexData.hexString // abff99
// "abff\n99".hexData.hexString // abff99
// "abzff 99".hexData.hexString // ab
// "abf ff 99".hexData.hexString // ab
// "abf".hexData.hexString // ab
@gamako
gamako / AppDelegate.swif
Created February 23, 2017 01:42
Template of UIApplicationDelegate without storyboard.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let vc = ViewController()
@gamako
gamako / NSObject+tap.swift
Created May 28, 2016 14:24
Ruby, Underscoreライクなtapメソッドのextension実装
import UIKit
protocol Tappable : class {
}
extension Tappable where Self : NSObject {
func tap(@noescape function: (Self) -> ()) -> Self {
function(self)
return self
@gamako
gamako / UIView+NoescapeClosureInitialzable.swift
Created May 28, 2016 02:12
closureでUIViewの初期化処理をあたえられるための拡張
import UIKit
/**
closureでUIViewの初期化処理をあたえられるための拡張
@noescapeをつけているのでclosureの中でselfをつける必要はない
ex.)
```
override func viewDidLoad() {
extension ObservableType {
/**
throttleFirst
RxJava reference
http://reactivex.io/RxJava/javadoc/rx/Observable.html#throttleFirst(long,%20java.util.concurrent.TimeUnit,%20rx.Scheduler)
*/
func throttleFirst(time: RxTimeInterval, scheduler: SchedulerType) -> Observable<E> {
let s = self.share()
@gamako
gamako / optional+swift2LikeFlatmap.swift
Created May 17, 2016 12:30
RxSwift extension for flatmap like Swift2.x
extension Observable {
/**
example:
Observable<String>.of("1", "a", "3", "4")
.flatMap { Int($0) }
.subscribeNext { print("\($0)") }
result:
1
3
4
@gamako
gamako / UIViewController+ScrollWhenShowKeyboard.swift
Last active October 4, 2019 09:13
UITextViewやUITextFieldがキーボードで隠れないようにスクロールする処理を、RxSwift, RxCocoaを使って1メソッドでセットできるようにしました
//
// UIViewController+ScrollWhenShowKeyboard.swift
//
//
import UIKit
import RxSwift
import RxCocoa
extension UIViewController {