Skip to content

Instantly share code, notes, and snippets.

@akuraru
akuraru / NSArray-Fanctional.h
Created October 10, 2012 12:03
Objective-Cで関数型プログラミングしたいなーと思ってやってみた。とりあえずFizzBuzz
#import <Foundation/Foundation.h>
typedef id (^fanc_t)(id);
typedef void (^noReturn_t)(id);
@interface NSArray (Fanctional)
+ (NSArray *)from:(NSInteger)from to:(NSInteger)to;
- (NSArray *)map:(fanc_t)fanc;
@akuraru
akuraru / gist:5361253
Created April 11, 2013 06:44
[Objective-C]ランダムな長さのランダムな文字列を作る
- (NSString *)randStringWithMaxLenght:(NSInteger)max {
NSInteger length = [self randBetween:1 max:max];
unichar letter[length];
for (int i = 0; i < length; i++) {
letter[i] = [self randBetween:65 max:90];
}
return [[NSString alloc] initWithCharacters:letter length:length];
}
- (NSInteger)randBetween:(NSInteger)min max:(NSInteger)max {
return (random() % (max - min + 1)) + min;
@akuraru
akuraru / gist:6618829
Last active December 23, 2015 09:59
Objective-Cでタプル
#define tuple(_1, _2) [Tuple tupleWithFirst:_1 second:_2];
@interface Tuple : NSObject
@property (readonly, nonatomic) id _1;
@property (readonly, nonatomic) id _2;
+ (id)tupleWithFirst:(id)_1 second:(id)_2;
- (id)initWithFirst:(id)_1 second:(id)_2;
@interface Tuple : NSObject
@property (readonly, nonatomic) id _1;
@property (readonly, nonatomic) id _2;
+ (id)tupleWithFirst:(id)_1 second:(id)_2;
- (id)initWithFirst:(id)_1 second:(id)_2;
@end
@akuraru
akuraru / gist:7765683
Created December 3, 2013 08:10
segueのidをいちいち比較するのが面倒なので、最近はこんな感じで書いてたりする。senderがBlocks以外だったらどうするか?知りませんよそんなの
- (IBAction)touchMove:(id)sender {
__weak typeof (self) this = self;
[self performSegueWithIdentifier:kSeguePicture sender:^(id controller) {
[controller setViewObject:this.viewObject];
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(void (^)(id))sender {
if (sender) {
@akuraru
akuraru / gist:7783786
Created December 4, 2013 07:54
いつの間にかこれでも良くなった
@implementation HogeViewController {
__weak IBOutlet UIView *piyo;
}
@end
@akuraru
akuraru / gist:9406640
Created March 7, 2014 07:01
Objective-Cで翌日の9時を取得する
// pod 'NSDate-Escort'
// pod 'AZDateBuilder'
#import "NSDate+Escort.h"
#import "NSDate+AZDateBuilder.h"
NSDate *date = [[[NSDate date] dateByAddingDays:1] AZ_dateByUnit: @{
AZ_DateUnit.hour : @9,
AZ_DateUnit.minute : @0,
AZ_DateUnit.second : @0,
@akuraru
akuraru / gist:10706319
Created April 15, 2014 06:10
よくあるシングルトン
+ (instancetype)sharedManager {
static id manager_ = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager_ = [[self alloc] init];
});
return manager_;
}
@akuraru
akuraru / gist:11201920
Created April 23, 2014 03:27
ぶどう問題。最後の方は明らかに力尽きている
require 'set'
class Bunch
def initialize(bunch1, bunch2 = nil)
(bunch2 != nil) ? mergeBunch(bunch1, bunch2) : initValue(bunch1)
end
def initValue(value)
@bunch1 = nil
@bunch2 = nil
@value = value
@implementation HideTabBar
+ (void)tabBarHidden:(BOOL)hide tabBar:(UITabBarController *)tabBarController {
CGFloat viewHeight = [self viewHeight:hide];
for (UIView *view in tabBarController.view.subviews) {
CGRect _rect = view.frame;
if ([view isKindOfClass:[UITabBar class]]) {
_rect.origin.y = viewHeight;
} else {