Skip to content

Instantly share code, notes, and snippets.

View urouro's full-sized avatar

Kenta Nakai urouro

View GitHub Profile
@urouro
urouro / gist:3382f8b2558093ed7b32
Last active August 29, 2015 14:25
Swift Keyboard InputAccessoryView
private var keyboardInputView: UIToolbar {
let toolbar = UIToolbar(frame: CGRectMake(0, 0, self.view.frame.size.width, 44))
let completeItem = UIBarButtonItem(title: "完了", style: .Done, target: self, action: "completeEditing:")
let space = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
toolbar.items = [space, completeItem]
return toolbar
}
@urouro
urouro / gist:dd97a0228fb1d648a470
Last active August 29, 2015 14:23
UIScrollView+GetCurrentPage
func currentPageIndex(#maxPageIndex: Int) -> Int {
let w: CGFloat = CGRectGetWidth(self.frame)
let x: CGFloat = self.contentOffset.x
var index: Int = Int(round(x / w))
if index < 0 {
index = 0
} else if index > maxPageIndex {
index = maxPageIndex
}
@urouro
urouro / gist:9a967ef042fb416f040f
Created June 5, 2015 16:35
Swift Keyboard Show/Hide Scroll
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "keyboardWillShow:",
name: UIKeyboardWillShowNotification,
object: nil)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "keyboardWillHide:",
name: UIKeyboardWillHideNotification,
@urouro
urouro / gist:0c4dd0a72a0b29486b28
Created June 5, 2015 16:04
CALayer+StoryboardAdditions
import UIKit
extension CALayer {
func setBorderColorFromUIColor(color: UIColor) {
self.borderColor = color.CGColor
}
}
+ (instancetype)builder:(MyClass * (^)(MyClass *obj))buildHandler
{
MyClass *obj = [MyClass new];
return buildHandler(obj);
}
#import "NSDate+String.h"
@implementation NSDate (String)
- (NSString *)stringValue
{
NSDateFormatter *fm = [[NSDateFormatter alloc] init];
[fm setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *str = [fm stringFromDate:self];
[fm release];
@urouro
urouro / gist:eabb855a3af5c4d00710
Last active August 29, 2015 14:08
Keyboard Show/Hide Events
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// キーボード表示・非表示イベント
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
@urouro
urouro / gist:decbc88708b3e2b35ea8
Last active August 29, 2015 14:07
ディレクトリ内のタスクリストを参照して日ごとの所要時間を計算
#!/usr/bin/ruby
days = Hash::new
if ARGV[0].nil?
# get latest file name
file_names = Dir::glob(File.expand_path("~/Dropbox/Tasks/*.md")).sort{|x, y| y <=> x}
target_file_name = file_names[0]
else
# get selected file name
@urouro
urouro / gist:846906ba84ec0f6a257c
Created October 21, 2014 05:31
Obj-C 都道府県 配列
NSArray *array = @[@"北海道",
@"青森県",
@"岩手県",
@"宮城県",
@"秋田県",
@"山形県",
@"福島県",
@"茨城県",
@"栃木県",
@"群馬県",
@urouro
urouro / gist:9c22597b4dd037753228
Created October 3, 2014 08:56
PHP 都道府県 配列
$prefNames = array(
'北海道',
'青森県',
'岩手県',
'宮城県',
'秋田県',
'山形県',
'福島県',
'茨城県',
'栃木県',