Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Josias Sena JosiasSena

🏠
Working from home
View GitHub Profile
@JosiasSena
JosiasSena / RxJavaEventBus
Last active Jul 14, 2016
RxJavaEventBusExample
View RxJavaEventBus
public class EventBus {
private final Subject<Boolean, Boolean> eventBus = new SerializedSubject<>(PublishSubject.<Boolean>create());
private EventBus() {
}
private static class SingleTonHelper {
private static final EventBus INSTANCE = new EventBus();
}
@JosiasSena
JosiasSena / uncheckAll
Last active Jul 14, 2016
Check/Uncheck all supported devices in the playstore with this JavaScript snippet
View uncheckAll
// Rather than going one by one and unchecking each and every one, run this JS query from
//the console on chrome or firefox that shows up after "inspecting the code" and then just
// check the ones that you want after wards.
switches = document.getElementsByClassName("M0PRCSC-Rc-g M0PRCSC-Rc-h");
for(i = 0; i < switches.length; i++) {
if (switches[i].getAttribute("aria-checked") == "false") {
switches[i].click()
}
View Pixel to DP
/**
* The calculation (value * scale + 0.5f) is a widely used to convert from dps to pixel units
* based on density scale
* see developer.android.com (Supporting Multiple Screen Sizes)
*/
public static int convertDpToPixels(int dp, DisplayMetrics displayMetrics) {
return Math.round(dp * ((displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)));
}
Note: to get the display metrics do: getContext().getResources().getDisplayMetrics();
@JosiasSena
JosiasSena / to_lower.sh
Created Jul 15, 2016
Set all file names in current directory to lowercase
View to_lower.sh
#!/usr/bin/env bash
for file in *; do mv "$file"`echo $file | tr "[:upper:]" "[:lower:]"`"; done
@JosiasSena
JosiasSena / vmOptions
Created Jul 15, 2016
Preffered android studio VM options
View vmOptions
-Xms512m
-Xmx3g
-XX:MaxPermSize=2g
-XX:ReservedCodeCacheSize=1g
-XX:+UseCompressedOops
@JosiasSena
JosiasSena / reflection
Created Jul 15, 2016
Reflection example in Java/Android
View reflection
// without reflection
ClassName className = new ClassName();
className.unsubscribe();
// with reflection
Object className = ClassName.class.newInstance();
Method m = className.getClass().getDeclaredMethod("unsubscribe", new Class[0]);
m.invoke(className);
@JosiasSena
JosiasSena / javaJDK
Created Jul 15, 2016
Find out the path of the latest java JDK by running the following command
View javaJDK
/usr/libexec/java_home
@JosiasSena
JosiasSena / genFbHash.txt
Last active Jul 15, 2016
Generate KeyHash for Facebook SDK
View genFbHash.txt
Generate KeyHash for Facebook SDK
1. First open a terminal (open a command prompt in windows).
2. Navigate in the terminal to the directory where your Android debug.keystore is stored.
3. Mostly it will located under “/Users/user_name/.android/” (In Windows will be C:\Documents and Settings\.android).
4. Once you are in the “.android” directory, run the following command.keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

Note: “androiddebugkey” can be the username for the keystone file and “debug.keystore” can be the name of the keynote file
1. When it prompts you for a password, type android and hit Enter
@JosiasSena
JosiasSena / hideKeyboard
Created Jul 15, 2016
Hide keyboard in Android
View hideKeyboard
final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
@JosiasSena
JosiasSena / getStringFromAssetFile
Created Jul 15, 2016
Load string from a file in Asset folder
View getStringFromAssetFile
public static String getStringFromAssetFile(final Context context, final String filename) {
final int MAX_BUFF = 1024 * 100;
final InputStream is;
final InputStreamReader isr;
final BufferedReader br;
String resultData = "";
try {
final AssetManager am = context.getAssets();