Skip to content

Instantly share code, notes, and snippets.

View erickok's full-sized avatar

Eric Kok erickok

  • Contractor at VRT Sporza & open-source dev as 2312 development
  • Leuven, Belgium
View GitHub Profile
@erickok
erickok / OnOffPageIndicator.java
Created August 30, 2012 08:26
A simple ViewPagerIndicator that shows an 'on' or 'off' image per page appropriately
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;
@erickok
erickok / diff-online-translations-ftp
Last active February 10, 2021 09:36
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…
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 / SelfSignedCrtCertificate.java
Last active May 11, 2023 14:25
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("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 / OkHttpGzippedLoggingInterceptor.java
Last active February 14, 2024 06:27
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 {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
long t1 = System.nanoTime();
@erickok
erickok / OperatorFreeze.java
Created July 26, 2016 13:03
Rx Freeze operator
/*
* 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 / PreferenceCompatActivity.java
Created July 9, 2020 09:00
androidx-compatible PreferenceActivity
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;
@erickok
erickok / MemoryCookieJar.kt
Created September 16, 2020 12:37
An in-memory CookieJar compatible with OkHttp
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 / LazyDeferred.kt
Created December 24, 2020 12:15
Lazy deferred properties in Kotlin
/*
* 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(