Skip to content

Instantly share code, notes, and snippets.

@g-1
g-1 / file0.cpp
Created July 8, 2014 04:18
JSBでC++のmapをJavascriptのオブジェクトとして返す方法 ref: http://qiita.com/g-1/items/7d52cef20e37ccf5dd2c
JSObject *object = JS_NewObject(_cx, NULL, NULL, NULL );
JSBool result = JS_TRUE;
std::map< std::string, std::string >::const_iterator it = params.begin();
while(it != params.end()){
CCLOG("%s => %s",it->first.c_str(), it->second.c_str());
JSString* jsValue = JS_NewStringCopyN(_cx, it->second.c_str(), it->second.length());
result &= JS_DefineProperty(_cx, object, it->first.c_str(), STRING_TO_JSVAL(jsValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT);
++it;
}
@g-1
g-1 / file0.txt
Created April 19, 2014 10:02
iOS7でカスタムURLスキームでMapアプリに遷移する。 ref: http://qiita.com/g-1/items/75cfc474e15d4b22e1e9
NSString* q = @"http://maps.apple.com/maps?q='渋谷駅'";
NSURL* url = [NSURL URLWithString:[q stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
@g-1
g-1 / file0.txt
Created April 8, 2014 15:40
GCDでWaitForMultipleObjectsを代替する方法 ref: http://qiita.com/g-1/items/dde3f3c34c50c6d6f055
dispatch_group_t group = dispatch_group_create();
[self.arrayLocalSearch removeAllObjects];
NSError* error = nil;
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Location"
inManagedObjectContext:[MapData sharedManager].managedObjectContext];
[fetchRequest setEntity:entity];
@g-1
g-1 / file0.txt
Created April 8, 2014 11:26
NSFetchedResultControllerでのセクションごとのソート順がUITableViewControllerで反映されない場合の対処法 ref: http://qiita.com/g-1/items/c97685fc98ff7e499c75
NSSortDescriptor* sortDescriptorWithName = [[NSSortDescriptor alloc] initWithKey:@"name"
ascending:YES];
NSArray* aSortDescriptor = @[sortDescriptorWithName];
[fetchRequest setSortDescriptors:aSortDescriptor];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"status >= 0"];
[fetchRequest setPredicate:predicate];
NSFetchedResultsController* fetchedResultsController =
@g-1
g-1 / AppDelegate.m
Created April 7, 2014 16:39
Storyboardで3.5inchディスプレイに手っ取り早く対応する。 ref: http://qiita.com/g-1/items/074aa4a3f0f886e271ec
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//3.5inchと4inchを読み分けする
CGRect rect = [UIScreen mainScreen].bounds;
if (rect.size.height == 480) {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"3_5_inch" bundle:nil];
UIViewController* rootViewController = [storyboard instantiateInitialViewController];
self.window.rootViewController = rootViewController;
}
@g-1
g-1 / Rakefile
Created March 22, 2014 17:05
rakeでcoco2dx-3.0rc0用のstaticライブラリを作成する ref: http://qiita.com/g-1/items/01f6c430326dfd125af9
PROJECT_PATH = "../cocos2d/build/cocos2d_libs.xcodeproj"
TARGET_NAME="'build all libs iOS'"
OUTPUT_DEBUG="tmp/iphonesimulator"
OUTPUT_RELEASE="tmp/iphoneos"
OUTPUT_LIB="../lib"
desc "静的ライブラリをビルドします"
task "lib" do
sh "xcodebuild -project #{PROJECT_PATH} -configuration Release -sdk iphonesimulator7.1 -target #{TARGET_NAME} TARGET_BUILD_DIR=../../build/#{OUTPUT_DEBUG} BUILT_PRODUCTS_DIR=../../build/#{OUTPUT_DEBUG} clean build"
@g-1
g-1 / gist:1258464
Created October 3, 2011 04:56
意外と知られていないマクロ __FILE__, __LINE__

案外知られていないマクロなので、念のため。 こんな感じにログに埋め込んでおくと、ファイル名とライン行が出力されて便利。

DLog(@"Error:%s:%d",__FILE__,__LINE__);

下記のように#defineに定義してもよいが、処理系によってはマクロの多重展開がうまくいかない場合があるので、必ずテストすること

#define LOG( _x_ ) printf("%s:%d->%s\n",__FILE__,__LINE__,_x_)