Skip to content

Instantly share code, notes, and snippets.

View JosiasSena's full-sized avatar
🏠
Working from home

Josias Sena JosiasSena

🏠
Working from home
View GitHub Profile
@JosiasSena
JosiasSena / reflection
Created July 15, 2016 23:14
Reflection example in Java/Android
// 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 / vmOptions
Created July 15, 2016 23:12
Preffered android studio VM options
-Xms512m
-Xmx3g
-XX:MaxPermSize=2g
-XX:ReservedCodeCacheSize=1g
-XX:+UseCompressedOops
@JosiasSena
JosiasSena / to_lower.sh
Created July 15, 2016 23:10
Set all file names in current directory to lowercase
#!/usr/bin/env bash
for file in *; do mv "$file” "`echo $file | tr "[:upper:]" "[:lower:]"`"; done
/**
* 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 / uncheckAll
Last active July 14, 2016 17:52
Check/Uncheck all supported devices in the playstore with this JavaScript snippet
// 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()
}
@JosiasSena
JosiasSena / RxJavaEventBus
Last active July 14, 2016 17:51
RxJavaEventBusExample
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();
}