Skip to content

Instantly share code, notes, and snippets.

View rizumita's full-sized avatar
🏠
Working from home

Ryoichi Izumita rizumita

🏠
Working from home
View GitHub Profile
@rizumita
rizumita / gist:10333688
Last active August 29, 2015 13:58
Using ReactiveCoreData with NSBlockOperation
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
[[[RACSignal startEagerlyWithScheduler:[RACScheduler scheduler] block:^(id <RACSubscriber> subscriber) {
NSManagedObjectContext *context = [NSManagedObjectContext contextWithMainContext:self.managedObjectContext]; // self is AppDelegate
[context attachToCurrentScheduler];
[subscriber sendNext:nil];
[subscriber sendCompleted];
}] saveContext] subscribeCompleted:^{
NSLog(@"Completed");
}];
}];
@rizumita
rizumita / 0_reuse_code.js
Created April 12, 2014 01:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rizumita
rizumita / file0.swift
Last active August 29, 2015 14:03
Swiftのif letでは二つ以上の変数を同時に束縛できないのでその代替方法 ref: http://qiita.com/rizumita/items/14f92c540039af16b7a5
let first : Int? = "1".toInt()
let second : Int? = "2".toInt()
switch (first, second) {
case (.Some(let f), .Some(let s)):
println(f + s)
default:
println("error")
}
@rizumita
rizumita / gist:e32d839c8d55c75c952c
Created August 1, 2014 06:31
UILabelで幅固定で高さを計算する
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 500.0)];
view.translatesAutoresizingMaskIntoConstraints = NO;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 44.0)];
label.translatesAutoresizingMaskIntoConstraints = NO;
label.lineBreakMode = NSLineBreakByWordWrapping;
[label setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
label.text = @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
label.numberOfLines = 0;
NSLog(@"%@", NSStringFromCGRect(label.frame));
@rizumita
rizumita / file0.txt
Created August 18, 2014 00:54
SwiftでNSManagedObjectのサブクラスを作成してフェッチする方法(Beta5で) ref: http://qiita.com/rizumita/items/3129b18bb65fb72c2cbb
let person = NSEntityDescription.insertNewObjectForEntityForName("Person", inManagedObjectContext: context) as Person
@rizumita
rizumita / file0.txt
Last active August 29, 2015 14:19
SwiftにおけるBuilderパターンの実装 ref: http://qiita.com/rizumita/items/fe90d09a07d9b2d0e490
class A {
var firstName: String?
var lastName: String?
}
class B: A {
var middleName: String?
}
@rizumita
rizumita / sum_optional_ints.swift
Created August 31, 2015 05:17
Int? = Int? + Int? in Swift
let a: Int? = 10
let b: Int? = 20
let values = [a, b].flatMap { $0 }
let c: Int? = values.isEmpty ? nil : values.reduce(0, combine: +)
@rizumita
rizumita / getvalue.swift
Created September 18, 2015 13:18
Get value of property of class or struct by key as string
func get<T>(sv: T, key: String) -> Any? {
let mirror = Mirror(reflecting: sv)
for (name, value) in mirror.children where name == key {
return value
}
return nil
}
@rizumita
rizumita / recursive_flatMap.swift
Last active October 19, 2021 09:54
RxSwift recursive flatMap
func recursive(observable: Observable<Int>) -> Observable<Int> {
return observable.flatMap { value -> Observable<Int> in
guard value < 10 else {
return Variable(-1).asObservable()
}
print(value)
return recursive(Variable(value + 1).asObservable())
}
}
@rizumita
rizumita / CodePiece.swift
Created October 21, 2015 07:24
protocolで組み上げるRESTクライアントライブラリ書いてる。 #swift #CodePiece
protocol TestResourceType: JRResourceType {
typealias ServiceType = TestService
}
struct TestService: JRServiceType {