Skip to content

Instantly share code, notes, and snippets.

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

OSCAR EMILIO PÉREZ MARTÍNEZ oscarito9410

🏠
Working from home
  • Mexico City
View GitHub Profile
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i + 1), 16));
}
return data;
}
// Ref: https://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java/140861#140861
@oscarito9410
oscarito9410 / HostSelectionInterceptor.java
Created July 27, 2018 21:25 — forked from swankjesse/HostSelectionInterceptor.java
This OkHttp application interceptor will replace the destination hostname in the request URL.
import java.io.IOException;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
/** An interceptor that allows runtime changes to the URL hostname. */
public final class HostSelectionInterceptor implements Interceptor {
private volatile String host;
@oscarito9410
oscarito9410 / OAuthClient.java
Created February 22, 2018 23:15 — forked from dzolnai/OAuthClient.java
Retrofit OAuth2 refreshing tokens without modifying all requests.
package com.example.yourapp;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.example.yourapp.AuthenticationModel;
import retrofit.client.Header;
import retrofit.client.OkClient;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.security.KeyPairGeneratorSpec;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import java.io.ByteArrayInputStream;