Skip to content

Instantly share code, notes, and snippets.


Eric Kok erickok

  • Contractor at VRT Sporza & open-source dev as 2312 development
  • Leuven, Belgium
View GitHub Profile
erickok / LazyDeferred.kt
Created Dec 24, 2020
Lazy deferred properties in Kotlin
View LazyDeferred.kt
* Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license.
package nl.nl2312.core.ext
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
fun <T> suspendBlockingLazy(
erickok / MemoryCookieJar.kt
Created Sep 16, 2020
An in-memory CookieJar compatible with OkHttp
View MemoryCookieJar.kt
package nl.nl2312.example
import okhttp3.Cookie
import okhttp3.CookieJar
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
class MemoryCookieJar : CookieJar {
private val cache = mutableSetOf<WrappedCookie>()
erickok /
Created Jul 9, 2020
androidx-compatible PreferenceActivity
package nl.nl2312.example;
import android.os.Bundle;
import androidx.annotation.XmlRes;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
* Copyright 2016 Maxim Tuev.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
erickok /
Last active Sep 3, 2021
Simple logging interceptor for OkHttp that logs full request headers and response headers + body (useful for use with Retrofit 2 where logging was removed)
if (BuildConfig.DEBUG) {
httpclient.interceptors().add(new LoggingInterceptor());
public class LoggingInterceptor implements Interceptor {
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
long t1 = System.nanoTime();
erickok /
Last active Jul 23, 2021
Loading a self-signed SSL certificate .crt file and packaging it into a SSLSocketFactory for use with a HttpsURLConnection.
// Usage example...
HttpsURLConnection connection = (HttpsURLConnection) new URL("").openConnection();
private static SSLSocketFactory buildSslSocketFactory(Context context) {
// Add support for self-signed (local) SSL certificates
// Based on
try {
erickok / diff-online-translations-ftp
Last active Feb 10, 2021
Set of simple shell/php scripts to send the base translation and retrieve updated translations from a PASTT ( installation. FTP (using ncftp) and SSH (using scp) versions are given. All scripts should be *run in a separate directory*, for example if your application 'myapp' resides in /home/myusername/dev/myapp/m…
View diff-online-translations-ftp
echo 'Get remote translation files from the server.'
rm -rf res
ncftpget -u myusername -R -F . www/translate/res
rm -rf res/values
php diff-online-translations.php
echo 'Copy new translation files to our local working copy.'
cp -rf res /home/myusername/dev/myapp/myandroidapp/
erickok /
Created Aug 30, 2012
A simple ViewPagerIndicator that shows an 'on' or 'off' image per page appropriately
import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ImageView;