How to check that two format strings are compatible?

Checking if 2 printf() format strings are compatible is an exercise in format parsing. C, at least, has no standard run-time compare function such as: int format_cmp(const char *f1, const char *f2); // Does not exist Formats like “%d %f” and “%i %e” are obviously compatible in that both expect an int and float/double. Note: …

Read more

Handling the missing MENU button in new versions of Android (3.x and up)

Let me share another scenario where Menu Button becomes critical even though it is not a game. I have app implement its own tool bars which behave to some extent like ActionBar. Well I did that coz my app was released with 1.5 sdk. At that time there is no such concept. And to accomodate …

Read more

c++ #ifdef Mac OS X question

According to this answer: #ifdef __APPLE__ #include “TargetConditionals.h” #ifdef TARGET_OS_IPHONE // iOS #elif TARGET_IPHONE_SIMULATOR // iOS Simulator #elif TARGET_OS_MAC // Other kinds of Mac OS #else // Unsupported platform #endif #endif So in short: #ifdef __APPLE__ #include “TargetConditionals.h” #ifdef TARGET_OS_MAC #include <GLUT/glut.h> #include <OpenGL/OpenGL.h> #endif #elif defined _WIN32 || defined _WIN64 #include <GL\glut.h> #endif

Alternative to sun.misc.Signal

As you will find repeated ad infinitum when learning about signal handling in Java, you are encouraged to avoid writing Java code that depends directly on signals. The general best practice is to allow the JVM to exit normally on ctrl+c and other signals by registering a shutdown hook instead. Handling signals directly makes your …

Read more

Theme not applying to DialogFragment on Android

You shoudn’t use the AlertDialog.Builder(Context, int) constructor with the support library because it is only available since API 11. To setup a theme to your dialog, use instead a ContextThemeWrapper like this: ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Dialog_NoActionBar); AlertDialog.Builder builder = new AlertDialog.Builder(context);

println vs System.out.println in Scala

Predef.println is shortcut for Console.println and you can use Console.setOut or Console.withOut for redirecting. Also, Console.setOut only affects the current thread while System.setOut affects the whole JVM. Additionally Scala 2.9 repl evaluates each line in its own thread, so Console.setOut is not usable there. scala> val baos = new java.io.ByteArrayOutputStream baos: java.io.ByteArrayOutputStream = scala> Console.withOut(baos)(print(“hello”)) …

Read more

Effective maximum mailto: body lengths

The standard doesn’t define a maximum length, leaving implementation up to browsers and mail clients (See IETF RFC 2368). Microsoft products do have set limits: IE GET limit is 2,083 http://support.microsoft.com/kb/208427 Outlook express: 456 characters http://support.microsoft.com/kb/q182985/ Other browsers are likely to work up to lengths beyond that of a reasonable email body. The iPhone doesn’t …

Read more