Skip to content

Instantly share code, notes, and snippets.

@ptekchand
ptekchand / gist:5370884
Created April 12, 2013 09:43
Checking if code is running on an Android emulator seems to be an inexact process. This helper traces all the (static String) variables inside the android.os.Build class. This may help you choose a workaround/hack of your choice when required. http://stackoverflow.com/questions/2799097/how-can-i-detect-when-an-android-application-is-running-in-t…
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import android.os.Build;
private void traceBuildValues() {
Build build = new Build();
Class<?> c = build.getClass();
Field[] fieldArray = c.getDeclaredFields();
for(Field aField : fieldArray) {
int modifiers = aField.getModifiers();
@ptekchand
ptekchand / shallowStringify.js
Created August 24, 2012 07:57
Hack to work around "TypeError: Converting circular structure to JSON"
/**
* Hack to work around "TypeError: Converting circular structure to JSON"
* which is seen when using JSON.stringify
* Intended to inspection/debugging purposes.
* Note: Will not display an Array in square brackets.
* Shows extra trailing comma before closing brace.
* @param obj
* @param [onlyProps] - Show only property names
* @param {String[]} [skipTypes=['function']] - array of types to trace only the type instead of value.
* @return {String}