Skip to content

Instantly share code, notes, and snippets.

@naotty
naotty / gist:6657074a1e62e5c702b43ea3eab6c89e
Last active July 27, 2017 12:44
20170729 JAWS-UG沖縄 ハンズオン事前お試しメモ
@naotty
naotty / DecodeBase64Image.m
Created January 16, 2015 11:36
Base64でエンコードされた画像をデコードして表示するサンプル
// optionsは適切なものを入れること・・
NSData *imageData = [[NSData alloc]initWithBase64EncodedString:@"base64EncodingStrings"
options:NSDataBase64DecodingIgnoreUnknownCharacters];
UIImage *Image = [UIImage imageWithData:imageData];
UIImageView *imageView = [[UIImageView alloc]initWithImage:Image];
imageView.frame = CGRectMake(0, 0, Image.size.width, Image.size.height);
[self.view addSubview:imageView];
@naotty
naotty / Debug.xcconfig
Created January 6, 2015 12:04
XCodeのConfiguration Settings FileでURLを指定する
SLASH = /
BASE_URL = http:${SLASH}${SLASH}google.com
@naotty
naotty / TextFieldBorder.m
Created December 14, 2014 08:02
UITextFieldの上下にボーダーを付ける
// Add a topBorder.
CALayer *topBorder = [CALayer layer];
topBorder.frame = CGRectMake(0.0f, 0.0f, textField.frame.size.width, 1.0f);
topBorder.backgroundColor = [UIColor blackColor].CGColor;
[textField.layer addSublayer:topBorder];
// Add a bottomBorder.
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, textField.frame.size.height - 1.0f, textField.frame.size.width, 1.0f);
bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
@naotty
naotty / NaviBar.m
Last active August 29, 2015 14:11
ナビゲーションバーをコードで作成する
// ナビゲーションバー
UINavigationBar *naviBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 44)];
[naviBar sizeToFit]; // 必須
UINavigationItem *naviItem = [[UINavigationItem alloc]initWithTitle:@"タイトル"];
UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave // スタイルを指定
target:self // デリゲートのターゲットを指定
action:@selector(onClickNaviButton:) // ボタンが押されたときに呼ばれるメソッドを指定
];
naviItem.leftBarButtonItem = btn;
[naviBar pushNavigationItem:naviItem animated:YES];
@naotty
naotty / DateSample.m
Created December 8, 2014 10:52
指定した日時でNSDateを作成する
- (NSDate *)createTargetDate:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc]init];
components.year = year;
components.month = month;
components.day = day;
components.hour = hour;
components.minute = minute;
components.second = second;
@naotty
naotty / PhotoController.m
Created December 2, 2014 11:07
カメラで撮った写真が勝手に90度回転するのを戻す
// 勝手に90度回転するのを元に戻す
// cf. http://blog.katty.in/105
- (UIImage *)fixImageRotation:(UIImage *)originalImage
{
if(originalImage.imageOrientation != UIImageOrientationUp){
UIGraphicsBeginImageContextWithOptions(originalImage.size, NO, originalImage.scale);
[originalImage drawInRect:(CGRect){0, 0, originalImage.size}];
originalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
@naotty
naotty / ModalViewSample.m
Created November 26, 2014 11:37
XIBとStoryboardのそれぞれでModalViewを表示する方法
- (IBAction)pressXibModalButton:(id)sender {
// xibでの指定
// XibChildViewController.xibならinitWithNibName:bundleは省略可能 => initでおk
XibChildViewController *xibChildViewController = [[XibChildViewController alloc]init];
xibChildViewController.delegate = self;
xibChildViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:xibChildViewController animated:YES completion:nil];
}
- (IBAction)pressStoryboardModalButton:(id)sender {
@naotty
naotty / opencv_hsv.py
Created November 18, 2014 10:21
OpenCVで色みを数値化(HSV)
# -*- coding: utf-8 -*-
import cv
import cv2
def main():
img_bgr = cv2.imread('test_red.png')
#img_bgr = cv2.imread('orange.jpeg')
#img_bgr = cv2.imread('tomato.jpg')
img_hsv = cv2.cvtColor(img_bgr, cv.CV_BGR2HSV)
valid_hue_list = [[ hsv[0] for hsv in img_line if hsv[1] > 0] for img_line in img_hsv]
@naotty
naotty / opencv_rgb.py
Created November 18, 2014 10:18
OpenCVで色みを数値化(RGB)
# -*- coding: utf-8 -*-
import cv
import cv2
def main():
img = cv2.imread('test_red.png')
#img = cv2.imread('orange.jpeg')
#img = cv2.imread('tomato.jpg')
averages = img.mean(0).mean(0)
print averages