Skip to content

Instantly share code, notes, and snippets.

@darkstone
darkstone / AvoidJUsingNull.kt
Created June 6, 2019 07:38
Avoid using null in function
fun serveCustomer(maybeCustomer: Customer?) {
maybeCustomer ?: return // simply return
greet(customer)
customer.pickTable()
giveMenuToCustomer(customer)
forgetAboutCustomer(customer)
}

Keybase proof

I hereby claim:

  • I am darkstone on github.
  • I am andriesfc (https://keybase.io/andriesfc) on keybase.
  • I have a public key ASBD_eqO9VxEDfUUe3nNxrmLW_wf-A99AQNOYcYICy69Rgo

To claim this, I am signing this object:

@darkstone
darkstone / toHex.md
Created September 27, 2018 04:48 — forked from FoxIvan/toHex.md
bytes to hex
  private final static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
  
  public static String toHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            int byteValue = bytes[i] & 0xFF;
            hexChars[i * 2] = HEX_ARRAY[byteValue >>> 4];
            hexChars[i * 2 + 1] = HEX_ARRAY[byteValue & 0x0F];
 }
@darkstone
darkstone / AndroidTestOrchestrator.java
Created September 21, 2018 13:13 — forked from tomkoptel/AndroidTestOrchestrator.java
Extracted AndroidTestOrchestrator class from orchestrator-1.0.2-beta1.apk
package android.support.test.orchestrator;
import android.app.Instrumentation;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build.VERSION;
import android.os.Bundle;
@darkstone
darkstone / ReadPrivateRSAKey.kt
Created January 27, 2018 16:35
How to read RSA private key from SSL command output.
val rivateKey = privateKeyAsText
.replace("-----BEGIN PRIVATE KEY-----\n", "")
.replace("-----END PRIVATE KEY-----", "")
.replace("\n", "")
.let {
val encodedKey = Base64.getDecoder().decode(it)
val kf = KeyFactory.getInstance("RSA")
val keySpec = PKCS8EncodedKeySpec(encodedKey)
kf.generatePrivate(keySpec) as RSAPrivateKey
}
@darkstone
darkstone / tomcat7
Created February 12, 2014 16:57 — forked from clstokes/tomcat7
#
# Since I have to look this up every time...
#
# Add the following in /etc/default/tomcat7
#
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote"
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.port=9991"
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false"