Skip to content

Instantly share code, notes, and snippets.

View leonardoaramaki's full-sized avatar
🛰️

Leonardo Aramaki leonardoaramaki

🛰️
View GitHub Profile
@leonardoaramaki
leonardoaramaki / AddCookiesInterceptor.java
Created March 12, 2017 22:26 — forked from tsuharesu/AddCookiesInterceptor.java
Handle Cookies easily with Retrofit/OkHttp
/**
* This interceptor put all the Cookies in Preferences in the Request.
* Your implementation on how to get the Preferences MAY VARY.
* <p>
* Created by tsuharesu on 4/1/15.
*/
public class AddCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
@leonardoaramaki
leonardoaramaki / helloworld.dex.md
Created May 24, 2017 04:58 — forked from lifuzu/helloworld.dex.md
execute the dex file in android with command
public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("Hello World!");
    }
}

To run it on an android device:

javac HelloWorld.java
val user: User = getUser() ?: throw IllegalStateException("User not found!")
println("Hello, ${user.name}")
fun fail(message: String) {
throw IllegalStateException(message)
}
….
val user: User = getUser() ?: fail("User not found!")
println("Hello, ${user.name}")
fun fail(message: String) {
throw IllegalStateException(message)
}
// Is the same as:
fun fail(message: String): Unit {
throw IllegalStateException(message)
}
fun fail(message: String): Nothing {
throw IllegalStateException(message)
}
// ...
val user: User = getUser() ?: fail("User not found!")
println("Hello, ${user.name}")
fun fail(message: String): Nothing {
val throwable = Throwable(message)
Thread.setDefaultUncaughtExceptionHandler { t, e -> System.err.println(e.message) }
throw throwable
}
// ...
val user: User = getUser() ?: fail("User not found!")
println("Hello, ${user.name}")
Thread.setDefaultUncaughtExceptionHandler ({ t, e -> //… })
fun getUser(): User? {
// ...
}
val user: User? = getUser()
if (user != null) {
println("Hello, ${user.name}")
} else {
throw IllegalStateException("User not found!")
}
// Java
@FunctionaInterface
public interface UncaughtExceptionHandler {
void uncaughtException(Thread t, Throwable e);
}