Skip to content

Instantly share code, notes, and snippets.

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

Yusuke Hosonuma YusukeHosonuma

🏠
Working from home
View GitHub Profile
@YusukeHosonuma
YusukeHosonuma / gist:9989392
Created April 5, 2014 09:05
Javaですべてがtrue、1つでもtrueを判定する
// すべてがtrueか?
boolean flag = true;
for (boolean bit : bits) flag &= bit;
// 1つでもtrueか?
boolean flag = false;
for (boolean bit : bits) flag |= bit;
@YusukeHosonuma
YusukeHosonuma / gist:10518321
Last active August 29, 2015 13:59
Objective-Cの空文字列チェック
if ([someString length] > 0) { // 0が偽なのでnilチェックは不要
}
#define IS_EMPTY(s) ((s == nil) || ([s length] == 0))
NSString *emptyString = @"";
NSString *nilString = nil;
NSString *someString = @"foo";
// nilまたは空文字列でないかチェックする
NSLog(@"%@", !IS_EMPTY(emptyString) ? @"YES" : @"NO");
NSLog(@"%@", !IS_EMPTY(nilString) ? @"YES" : @"NO");
NSLog(@"%@", !IS_EMPTY(someString) ? @"YES" : @"NO");
@YusukeHosonuma
YusukeHosonuma / NSString+Additions.m
Created April 20, 2014 09:50
Objective-Cでカテゴリ拡張およびUtilクラスによる空文字列チェック ref: http://qiita.com/YusukeHosonuma/items/999d47a269435d094210
#import "NSString+Additions.h"
@implementation NSString (Additions)
- (BOOL)isNotEmpty {
return [self length] > 0;
}
@end
let old = 17
let foo = "I am \(old) old years."
@YusukeHosonuma
YusukeHosonuma / FizzBuzzSample.java
Last active August 29, 2015 14:23
Java8でFizzBuzz
import java.util.stream.Stream;
public class FizzBuzzSample {
public static void main(String[] args) {
// Stream.iterateを使用して自然数(の無限数列)のストリームを用意
Stream<Integer> naturalNumbers = Stream.iterate(1, integer -> integer + 1);
// 自然数(の無限数列)をfizzBuzzメソッド(参照)を利用して文字列のストリームに変換
@YusukeHosonuma
YusukeHosonuma / gist:57f2fc0d26e10da4400f
Last active August 29, 2015 14:23
SwiftでFizzBuzzと世界のナベアツ
import UIKit
extension Array {
func forEach(f: T -> ()) {
for n:T in self {
f(n)
}
}
}
@YusukeHosonuma
YusukeHosonuma / reflect.swift
Created September 6, 2015 17:08
Reflection in Swift 2.0
let p = Person(name: "Yusuke Hosonuma")
Mirror(reflecting: p).children.forEach {
print("\($0.label!), \($0.value)")
}
//
// ViewController.swift
// APISample
//
// Created by Yusuke on 11/8/15.
// Copyright © 2015 Yusuke. All rights reserved.
//
import UIKit
//
// SampleAPI.swift
// APISample
//
// Created by Yusuke on 11/8/15.
// Copyright © 2015 Yusuke. All rights reserved.
//
import Foundation