Skip to content

Instantly share code, notes, and snippets.

@nxax
nxax / MySQLiteOpenHelper
Created August 5, 2012 18:56
Check table if exists on SQLite
// Check table if exists on SQLite
// http://stackoverflow.com/questions/3058909/how-does-one-check-if-a-table-exists-in-an-android-sqlite-database
//
public boolean isTableExists(String tableName, boolean openDb) {
if(openDb) {
if(mDatabase == null || !mDatabase.isOpen()) {
mDatabase = getReadableDatabase();
}
if(!mDatabase.isReadOnly()) {
@nxax
nxax / ios_first_launch
Created August 16, 2012 07:14
Detect first launch iOS
// http://stackoverflow.com/questions/308832/iphone-the-quickest-and-easiest-way-to-detect-first-launch
// -applicationDidFinishLaunching:
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]];
// to check it:
[[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"];
// -applicationWillTerminate:
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
@nxax
nxax / ios_take_screenshot
Created August 16, 2012 07:33
Take screenshots on ios
// http://developer.apple.com/library/ios/#qa/qa1703/_index.html#//apple_ref/doc/uid/DTS40010193
- (UIImage*)screenshot
{
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
@nxax
nxax / log-macro
Created August 21, 2012 13:10
iOS log macros
// http://stackoverflow.com/questions/969130/nslog-tips-and-tricks
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
@nxax
nxax / gist:3784780
Created September 25, 2012 22:09 — forked from mwaterfall/gist:953657
Runtime iOS Version Checking
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@nxax
nxax / android_signature
Created December 25, 2012 15:47
Androidアプリケーションのパーミッション改竄を検知するスニペット http://visible-true.blogspot.com/2011/12/android.html
private static List<String> missingPermissions(Context context, String[] expectations) {
return missingPermissions(context, new ArrayList<String>(Arrays.asList(expectations)));
}
private static List<String> missingPermissions(Context context, List<String> expectations){
if (context == null || expectations == null) {
return null;
}
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS);