Skip to content

Instantly share code, notes, and snippets.

View mpurbo's full-sized avatar

Mohamad Purbo mpurbo

View GitHub Profile
@mpurbo
mpurbo / gist:1651292
Created January 21, 2012 04:28
Regular expression for pattern commonly found in Japanese time range data
public static final String REGEX_TIMERANGE = "(?:AM|PM)?([0-90-9]{1,2})[::\\.]([0-90-9]{1,2})[\uff5e\u301c-―-](?:AM|PM)?([0-90-9]{1,2})[::\\.]([0-90-9]{1,2})";
public static final Pattern PATTERN_TIMERANGE = Pattern.compile(REGEX_TIMERANGE);
@mpurbo
mpurbo / gist:1852930
Created February 17, 2012 11:51
geomon-client-ios: ユーザーの登録(同期のリクエスト)
// MMGClient *client = ...
MMGObject *registerUserObj = [client registerUserWithId:@"baabaa"
name:@"Baa Baa Black Sheep"
email:@"baabaa@blacksheep.com"
password:@"moomoo"
delegate:nil];
if (registerUserObj.error != nil || registerUserObj.type != kMMGUser) {
NSLog(@"ユーザー登録のエラーが発生しました: %@", [registerUserObj.error localizedDescription]);
@mpurbo
mpurbo / gist:1852892
Created February 17, 2012 11:44
geomon-client-ios: ユーザーの存在の確認(同期のリクエスト)
// MMGClient *client = ...
// ユーザーIDはサーバーで既に登録されるか確認する。
// デリゲートがnilすると、同期してリクエストをする。
MMGObject *checkUserObj = [client checkAvailabilityOfUserId:@"baabaablacksheep" withDelegate:nil];
if (checkUserObj.error != nil || checkUserObj.type != kMMGUser) {
NSLog(@"ユーザー確認のエラーが発生しました: %@", [checkUserObj.error localizedDescription]);
} else {
// タイプはkMMGUserの場合は、安全にMMGUserにキャストできる。
@mpurbo
mpurbo / gist:1852689
Created February 17, 2012 11:03
geomon-client-ios: ライブラリの初期化
#import "MMGClient.h"
// アプリケーションのデリゲート。Geomonにログインするため、MMGRequestDelegateのプロトコルが実装される。
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate, MMGRequestDelegate>
// 他のプロパティの定義...
// Geomonのクライアントオブジェクト
@property (strong, nonatomic) MMGClient *client;
@mpurbo
mpurbo / gist:1875511
Created February 21, 2012 09:43
geomon-client-ios: ユーザーの登録(非同期のリクエスト)
/**
* 非同期的にユーザーを登録する。
*/
- (void)registerUserUsingClient:(MMGClient *)client
{
[client registerUserWithId:@"baabaa"
name:@"Baa Baa Black Sheep"
email:@"baabaa@blacksheep.com"
password:@"moomoo"
delegate:self];
@mpurbo
mpurbo / gist:5087295
Created March 5, 2013 01:31
Generic methods for fetching rows from table using Core Data.
- (NSArray *)fetchRecordsForEntity:(NSString *)entityName
{
return [self fetchRecordsForEntity:entityName orderBy:nil];
}
- (NSArray *)fetchRecordsForEntity:(NSString *)entityName orderBy:(NSString *)column
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
@mpurbo
mpurbo / gist:5104750
Created March 7, 2013 01:14
Disable horizontal auto-rotation on iOS >= 6.0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
@mpurbo
mpurbo / gist:5131291
Created March 11, 2013 01:10
GCD for static array of objects.
static NSArray *objectRegistry;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
objectRegistry = [[NSArray alloc] initWithObjects:obj1, obj2, nil];
});
return objectRegistry[index];
@mpurbo
mpurbo / gist:5132544
Created March 11, 2013 07:33
Integer bits of double/float
#include <stdint.h>
uint64_t doubleToBits(double x) {
const union { double f; uint64_t i; } xUnion = { .f = x };
return xUnion.i;
}
uint32_t floatToBits(float x) {
const union { float f; uint32_t i; } xUnion = { .f = x };
return xUnion.i;
@mpurbo
mpurbo / create_framework_prj.sh
Created August 30, 2013 04:53
XCode .framework build script for xcodeproj based projects.
# adapted from following sources:
# https://github.com/jverkoey/iOS-Framework
# http://codefriend.blogspot.jp/2011/09/creating-ios-framework-with-xcode4.html
# http://www.cocoanetics.com/2010/04/making-your-own-iphone-frameworks/
# "No architecture.." error resolved by trying some of these:
# http://stackoverflow.com/questions/6151549/how-can-i-build-a-specific-architecture-using-xcodebuild
set -e
set +u