Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Kok erickok

  • Contractor at VRT Sporza & open-source dev as 2312 development
  • Leuven, Belgium
View GitHub Profile
@erickok
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
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
erickok / PreferenceCompatActivity.java
Created Jul 9, 2020
androidx-compatible PreferenceActivity
View PreferenceCompatActivity.java
package nl.nl2312.example;
import android.os.Bundle;
import androidx.annotation.XmlRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatCallback;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
View OperatorFreeze.java
/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@erickok
erickok / OkHttpGzippedLoggingInterceptor.java
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)
View OkHttpGzippedLoggingInterceptor.java
if (BuildConfig.DEBUG) {
httpclient.interceptors().add(new LoggingInterceptor());
}
public class LoggingInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
long t1 = System.nanoTime();
@erickok
erickok / SelfSignedCrtCertificate.java
Last active Jul 23, 2021
Loading a self-signed SSL certificate .crt file and packaging it into a SSLSocketFactory for use with a HttpsURLConnection.
View SelfSignedCrtCertificate.java
// Usage example...
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://someurl.com").openConnection();
connection.setSSLSocketFactory(buildSslSocketFactory());
private static SSLSocketFactory buildSslSocketFactory(Context context) {
// Add support for self-signed (local) SSL certificates
// Based on http://developer.android.com/training/articles/security-ssl.html#UnknownCa
try {
@erickok
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 (https://github.com/erickok/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 mydomain.org . 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
erickok / OnOffPageIndicator.java
Created Aug 30, 2012
A simple ViewPagerIndicator that shows an 'on' or 'off' image per page appropriately
View OnOffPageIndicator.java
package nl.nl2312.android.components;
import nl.nl2312.android.R;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ImageView;