Skip to content

Instantly share code, notes, and snippets.

View mpurbo's full-sized avatar

Mohamad Purbo mpurbo

View GitHub Profile
@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: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: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: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:1651260
Created January 21, 2012 04:18
Japanese Postcode Regular Expression
public static final String SPACE = "[\\s\u3000]";
public static final String NUMBER = "[0-9\uff10-\uff19]"; // 0-90-9
public static final String HYPHEN = "[-\uff0d\u2212]";
public static final String NOT_NUMBER_OR_HYPHEN = "[^" + NUMBER.substring(1, NUMBER.length()-1) + HYPHEN.substring(1);
public static final String REGEX_POSTCODE =
"(?:" + NOT_NUMBER_OR_HYPHEN.substring(0, NOT_NUMBER_OR_HYPHEN.length() - 1) + "\\)]|^)" +
"\u3012?" +
SPACE + "*(" + NUMBER + "{3})" +
SPACE + "*" + HYPHEN +
@mpurbo
mpurbo / gist:1651273
Created January 21, 2012 04:22
Converting all double bytes UTF-8 numbers (0-9) in a String to single bytes (0-9)
private static String toHankakuNumbers(String zenkaku) {
if (zenkaku == null)
return null;
StringBuffer ret = new StringBuffer();
char [] src = zenkaku.toCharArray();
for (char c : src) {
if (c >= 0xff10 && c <= 0xff19) {
ret.append((char)(c - 65248));
} else {
ret.append(c);
@mpurbo
mpurbo / gist:1651282
Created January 21, 2012 04:25
Regular expression for format commonly used in Japanese phone number
public static final String SPACE = "[\\s\u3000]";
public static final String NUMBER = "[0-9\uff10-\uff19]"; // 0-90-9
public static final String HYPHEN = "[-\uff0d\u2212]";
public static final String NOT_NUMBER_OR_HYPHEN = "[^" + NUMBER.substring(1, NUMBER.length()-1) + HYPHEN.substring(1);
public static final String SEPARATOR = "[\\(\\)" + HYPHEN.substring(1, HYPHEN.length()-1) + "]";
public static final String REGEX_PHONEFAX =
"(?:" + NOT_NUMBER_OR_HYPHEN + "|^)" +
SPACE + "*(" + NUMBER + "{2,4})" +
SPACE + "*" + SEPARATOR +
@mpurbo
mpurbo / gist:1037518
Created June 21, 2011 09:25
Correct and transform SRID with PostGIS
-- add temporary column for storing geometry with correct SRID
select AddGeometryColumn('places', 'geom_4301', 4301, 'GEOMETRY', 2);
-- add temporary column for storing geometry with target SRID
select AddGeometryColumn('places', 'geom_4326', 4326, 'GEOMETRY', 2);
BEGIN;
-- set the source temporary column with geometries with corrected SRID
UPDATE places SET geom_4301 = 'SRID=4301;POINT('|| ST_X(geom) || ' ' || ST_Y(geom) || ')';
@mpurbo
mpurbo / gist:1030840
Created June 17, 2011 03:57
nfkc.c compile error fix when building Senna
# do configure
./configure --prefix=/usr --without-mecab
# compile nfkc.c manually before make
cd lib
../libtool --tag=CC --mode=compile \
gcc -I. -I.. -Wall -O0 -fno-strict-aliasing -g -MT nfkc.lo \
-MD -MP -MF .deps/nfkc.Plo -c -o nfkc.lo nfkc.c
# do make
@mpurbo
mpurbo / gist:1030837
Created June 17, 2011 03:50
Sample SQL with function in ORDER BY clause
SELECT ...
FROM ...
WHERE ...
ORDER BY ST_Distance(...)