橋本聖子さんのHPのIPから使用しているサーバまで
なんとなく調べてみた。
1.pingを飛ばす
ping www.seiko-hashimoto.com
PING seiko-hashimoto.com (202.69.231.96): 56 data bytes
64 bytes from 202.69.231.96: icmp_seq=0 ttl=49 time=28.383 ms
64 bytes from 202.69.231.96: icmp_seq=1 ttl=49 time=12.152 ms
2.判明したIPをwhoisで検索する
whois 202.69.231.96
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# http://www.arin.net/public/whoisinaccuracy/index.xhtml
#
#
# Query terms are ambiguous. The query is assumed to be:
# "n 202.69.231.96"
#
# Use "?" to get help.
#
#
# The following results may also be obtained via:
# http://whois.arin.net/rest/nets;q=202.69.231.96?showDetails=true&showARIN=false&ext=netref2
#
NetRange: 202.0.0.0 - 202.255.255.255
CIDR: 202.0.0.0/8
OriginAS:
NetName: APNIC-CIDR-BLK
NetHandle: NET-202-0-0-0-1
Parent:
NetType: Allocated to APNIC
Comment: This IP address range is not registered in the ARIN database.
Comment: For details, refer to the APNIC Whois Database via
Comment: WHOIS.APNIC.NET or http://wq.apnic.net/apnic-bin/whois.pl
Comment: ** IMPORTANT NOTE: APNIC is the Regional Internet Registry
Comment: for the Asia Pacific region. APNIC does not operate networks
Comment: using this IP address range and is not able to investigate
Comment: spam or abuse reports relating to these addresses. For more
Comment: help, refer to http://www.apnic.net/apnic-info/whois_search2/abuse-and-spamming
RegDate: 1994-04-05
Updated: 2010-08-02
Ref: http://whois.arin.net/rest/net/NET-202-0-0-0-1
OrgName: Asia Pacific Network Information Centre
OrgId: APNIC
Address: PO Box 3646
City: South Brisbane
StateProv: QLD
PostalCode: 4101
Country: AU
RegDate:
Updated: 2012-01-24
Ref: http://whois.arin.net/rest/org/APNIC
ReferralServer: whois://whois.apnic.net
OrgAbuseHandle: AWC12-ARIN
OrgAbuseName: APNIC Whois Contact
OrgAbusePhone: +61 7 3858 3188
OrgAbuseEmail: search-apnic-not-arin@apnic.net
OrgAbuseRef: http://whois.arin.net/rest/poc/AWC12-ARIN
OrgTechHandle: AWC12-ARIN
OrgTechName: APNIC Whois Contact
OrgTechPhone: +61 7 3858 3188
OrgTechEmail: search-apnic-not-arin@apnic.net
OrgTechRef: http://whois.arin.net/rest/poc/AWC12-ARIN
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# http://www.arin.net/public/whoisinaccuracy/index.xhtml
#
% [whois.apnic.net]
% Whois data copyright terms http://www.apnic.net/db/dbcopyright.html
% Information related to '202.69.224.0 - 202.69.239.255'
inetnum: 202.69.224.0 - 202.69.239.255
netname: ARCSTAR
descr: ARCSTAR (NTT COMMUNICATIONS CORPORATION)
descr: NTT Hibiya Bldg. 7F, 1-6 Uchisaiwai-cho 1-Chome, Chiyoda-ku, Tokyo 100-8019, Japan
country: JP
admin-c: JNIC1-AP
tech-c: JNIC1-AP
status: ALLOCATED PORTABLE
remarks: Email address for spam or abuse complaints : abuse@ntt.net
mnt-irt: IRT-JPNIC-JP
mnt-by: MAINT-JPNIC
mnt-lower: MAINT-JPNIC
changed: hm-changed@apnic.net 20050208
changed: ip-apnic@nic.ad.jp 20100409
changed: ip-apnic@nic.ad.jp 20111012
source: APNIC
irt: IRT-JPNIC-JP
address: Urbannet-Kanda Bldg 4F, 3-6-2 Uchi-Kanda
address: Chiyoda-ku, Tokyo 101-0047, Japan
e-mail: hostmaster@nic.ad.jp
abuse-mailbox: hostmaster@nic.ad.jp
admin-c: JNIC1-AP
tech-c: JNIC1-AP
auth: # Filtered
mnt-by: MAINT-JPNIC
changed: abuse@apnic.net 20101108
changed: hm-changed@apnic.net 20101111
changed: ip-apnic@nic.ad.jp 20140702
source: APNIC
role: Japan Network Information Center
address: Urbannet-Kanda Bldg 4F
address: 3-6-2 Uchi-Kanda
address: Chiyoda-ku, Tokyo 101-0047,Japan
country: JP
phone: +81-3-5297-2311
fax-no: +81-3-5297-2312
e-mail: hostmaster@nic.ad.jp
admin-c: JI13-AP
tech-c: JE53-AP
nic-hdl: JNIC1-AP
mnt-by: MAINT-JPNIC
changed: hm-changed@apnic.net 20041222
changed: hm-changed@apnic.net 20050324
changed: ip-apnic@nic.ad.jp 20051027
changed: ip-apnic@nic.ad.jp 20120828
source: APNIC
% Information related to '202.69.224.0 - 202.69.231.255'
inetnum: 202.69.224.0 - 202.69.231.255
netname: VPS-TOKYO
descr: NTT Communications BroadBand IP Services Business Division
country: JP
admin-c: JP00017877
tech-c: JP00017877
remarks: This information has been partially mirrored by APNIC from
remarks: JPNIC. To obtain more specific information, please use the
remarks: JPNIC WHOIS Gateway at
remarks: http://www.nic.ad.jp/en/db/whois/en-gateway.html or
remarks: whois.nic.ad.jp for WHOIS client. (The WHOIS client
remarks: defaults to Japanese output, use the /e switch for English
remarks: output)
changed: apnic-ftp@nic.ad.jp 20040701
changed: apnic-ftp@nic.ad.jp 20070820
source: JPNIC
% This query was served by the APNIC Whois Service version 1.69.1-APNICv1r0 (WHOIS3)
3.IP直でアクセスする
New Server -- crayon.securesites.net
レスポンスヘッダ
Server:Apache/1.3.42 Ben-SSL/1.60 (Unix) PHP/4.4.9 with Suhosin-Patch
nginxのupstream設定
nodejsとgoの2つのアプリをバランシングして動かしたく、
LBをいじるのは面倒なので、nginxでうまい事できないか調べたら、
upstreamという設定を使うとうまくできそうなことが分かった。
いつもの設定方法だと、
location /test/ {
proxy_pass http://127.0.0.1:10080/;
access_log /data/logs/nginx.log main;
}
upstreamを使った設定方法だと、
location /test/ {
proxy_pass http://appbalance/;
access_log /data/logs/nginx.log main;
}
upstream appbalance {
server 127.0.0.1:10080;
server 127.0.0.1:10081;
}
これは便利ですね。
アーキテクチャ構成考える際に幅が広がりそうです。
gitコマンド
このページからよく使うgitコマンドを抜粋
ブランチ作成:
git branch branch-test
ブランチ切り替え:
git checkout branch-test
ブランチ作成および切り替え:
git checkout -b branch-test
変更のコミット
git commit -a -m 'few bug fix'
-a:ファイルの削除・更新を含む
-m:コミットメッセージの追加
変更のマージ
git merge branch-test
※マージ先のブランチで実施
ブランチの削除
git branch -d branch-test
ブランチの状態確認
git status
iOSの画面サイズ取得
//画面サイズ取得
CGFloat width = [[UIScreen mainScreen] bounds].size.width;
CGFloat height = [[UIScreen mainScreen] bounds].size.height;
です。
トレーディングカードアプリを作る~デッキ構成機能(実装その3)~
CoreDataを使ったカード管理部分を実装した。
前回紹介したサンプルアプリのコードを参考にして、自分のプロジェクトに追加。
無事動くようになった。
動くようになるまでに結構大変だったので、備忘録的に書いときます。
・AppDelegate.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
NSManagedObjectModel *managedObjectModel; ➡追加
NSManagedObjectContext *managedObjectContext; ➡追加
NSPersistentStoreCoordinator *persistentStoreCoordinator; ➡追加
}
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; ➡追加
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; ➡追加
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; ➡追加
- (NSURL *)applicationDocumentsDirectory; ➡追加
・AppDelegate.m
// Returns the managed object context for the application.
// If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
- (NSManagedObjectContext *)managedObjectContext
{
if (_managedObjectContext != nil) {
return_managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [selfpersistentStoreCoordinator];
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContextalloc] init];
[_managedObjectContextsetPersistentStoreCoordinator:coordinator];
}
return_managedObjectContext;
}
// Returns the managed object model for the application.
// If the model doesn't already exist, it is created from the application's model.
- (NSManagedObjectModel *)managedObjectModel
{
if (_managedObjectModel != nil) {
return_managedObjectModel;
}
NSURL *modelURL = [[NSBundlemainBundle] URLForResource:@"Card"withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModelalloc] initWithContentsOfURL:modelURL];
return_managedObjectModel;
}
// Returns the persistent store coordinator for the application.
// If the coordinator doesn't already exist, it is created and the application's store added to it.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return_persistentStoreCoordinator;
}
NSURL *storeURL = [[selfapplicationDocumentsDirectory] URLByAppendingPathComponent:@"Card.sqlite"];
_persistentStoreCoordinator = [[NSPersistentStoreCoordinatoralloc] initWithManagedObjectModel:[selfmanagedObjectModel]];
if (![_persistentStoreCoordinatoraddPersistentStoreWithType:NSSQLiteStoreTypeconfiguration:nilURL:storeURL options:nilerror:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
Typical reasons for an error here include:
* The persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.
If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
If you encounter schema incompatibility errors during development, you can reduce their frequency by:
* Simply deleting the existing store:
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return_persistentStoreCoordinator;
}
#pragma mark - Application's Documents directory
// Returns the URL to the application's Documents directory.
- (NSURL *)applicationDocumentsDirectory
{
return [[[NSFileManagerdefaultManager] URLsForDirectory:NSDocumentDirectoryinDomains:NSUserDomainMask] lastObject];
}
・ViewController.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h> ➡追加
@interface ViewController : UIViewController <NSFetchedResultsControllerDelegate> ➡追加
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; ➡追加
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext; ➡追加
・VIewController.m
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return_fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescriptionentityForName:@"Card"inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
// 取得数
[fetchRequest setFetchBatchSize:5];
// Edit the sort key as appropriate.
// ソート配列を作成し、timeスタンプ取得時の表示順を定義
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"cardid" ascending:YES];
NSArray *sortDescriptors = @[sortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
// データ取得用のコントローラ作成
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsControlleralloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContextsectionNameKeyPath:nilcacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
//データ取得処理
if (![self.fetchedResultsControllerperformFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return_fetchedResultsController;
}
上記が基本的なコードです。
これを実装していざ実行すると下記エラーが発生。
+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'XXX''
ググったりデバッグした結果、managedObjectContextの値がnilになっていることが判明。
よくよく考えるとViewControllerのmanagedObjectContextのオブジェクトを作成していなかった。なのでオブジェクトを作成するコードを追加。この部分がXcodeのサンプルとはちょっと異なる部分です。
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
Xcodeのサンプルアプリは、StoryBoradを使っているため、こんな感じでオブジェクトを渡していた。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];
}
}
これで完成です。
で、データ保存とか色々する場合のコードは、こんな感じ。
※これはデータ保存用のコードです。
- (void)insertNewObject:(id)sender
{
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
// データ取得
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
NSArray *result = self.fetchedResultsController.fetchedObjects;
NSLog(@"result:%@",[result description]);
// If appropriate, configure the new managed object.
// Normally you should use accessor methods, but using KVC here avoids the need to add a custom class to the template.
[newManagedObject setValue:[NSNumber numberWithInt:1] forKey:@"cardid"];
// Save the context.
// 保存処理
if (![context save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
で実装した結果、考えなければいけないことが増えた。
・アプリの大きさについて
カード枚数が増えれば増えるほど、アプリが肥大化していく。カード情報を圧縮して対応する予定だが、どこまで小さくなるかは不明。今度、人気アプリのサイズを確認してみる。また、最初からある程度(初期デッキセット)のカード情報をアプリに含めるか、アプリ初回立ち上げ時にダウンロードさせるかを決めないといけない。カード情報に関しては、サーバから差分更新で対応できるようにする予定。
とりあえず、上記考えなければいけないことがあるということを認識して続けます。
次は、デッキ制御部分の処理を実装していきます。
CoreDtaのサンプル(Xcode5.0.1)
昨日に引き続きCoreDataの使い方について調べてみた。
ググってみましたが、記事が全部古く、記載されているコードの通りに書くとエラーが発生します。
色々考えた結果、新しいプロジェクトを作成する際に
[Master-Detail Application]を選択し、[Use CoreData]にチェックを入れればサンプルアプリをゲットできることに気づきました。
ググっても昔の記事が多いので、サンプルアプリのコードを読み、わからない部分があれば、その記事(基本的な考えは一緒のため)を参考にするやり方で進めた方ががいいです。
サンプルアプリの超簡単な動きとしては、
ボタンを押すと位置情報を取得し、それを画面に表示とDBに突っ込んでいく感じの動きになっています。
これからコードを確認してトレーディングカードアプリに移植する作業を行います。
CoreDataを使うための基本的なクラス一覧と用途は以下サイトにまとめられておりましたので、そこから引用しました。
時計仕掛けのiPhoneアプリ(6) – CoreDataを使ってみる | アルゴニートブログ
NSManagedObjectModel機能:Data Modelで作成したモデル情報を読み込み、プログラムコード上で利用できるようにします。NSPersistentStoreCoordinator機能:[NSPersistentStore]クラスを使い、ファイルの読み書きを行ないます。NSManagedObjectContext機能:データベースの1レコードに相当する[NSPersistentObject]クラスのを使い、データの追加・削除を行ないます。
これを元になんとか作っていきます。