Skip to content

Instantly share code, notes, and snippets.

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

Herman Cheung hkhc

🏠
Working from home
  • United Kingdom
View GitHub Profile
@hkhc
hkhc / build.gradle.kts
Created May 22, 2021 10:10
build.gradle.kts show errors in Android Studio
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
plugins {
kotlin("jvm")
id("org.jlleitschuh.gradle.ktlint")
id("io.gitlab.arturbosch.detekt")
id("io.hkhc.jarbird")
// for build script debugging
id("org.barfuin.gradle.taskinfo")
fun OkHttpClient.Builder.cleanupInterceptor() {
var foundLogger: Interceptor? = null
with(interceptors()) {
val newList = asSequence()
.filter {
if (it is HttpLoggingInterceptor) {
foundLogger = it
false
LOG-APP: --> GET https://dog.ceo/api/breed/hound/images
LOG-APP: --> END GET
LOG-NET: --> GET https://dog.ceo/api/breed/hound/images http/1.1
LOG-NET: Host: dog.ceo
LOG-NET: Connection: Keep-Alive
LOG-NET: Accept-Encoding: gzip
LOG-NET: User-Agent: okhttp/3.14.7
LOG-NET: --> END GET
LOG-NET: <-- 200 OK https://dog.ceo/api/breed/hound/images (469ms)
LOG-NET: Date: Thu, 30 Apr 2020 08:41:20 GMT
@hkhc
hkhc / loggingInterceptorDemo.kt
Created April 30, 2020 08:51
Demonstrating logging interceptor
val client = OkHttpClient.Builder().apply {
addInterceptor(HttpLoggingInterceptor(
HttpLoggingInterceptor.Logger { message ->
println("LOG-APP: $message")
}).apply {
level= HttpLoggingInterceptor.Level.BODY
})
addNetworkInterceptor(HttpLoggingInterceptor(
@hkhc
hkhc / webpack.config.js
Created April 30, 2020 03:47
Webpack config with ascii_only option
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
optimization: {
@hkhc
hkhc / webpack.config.js
Created April 30, 2020 03:32
Webpack config with BOM plugin
const path = require('path');
var BomPlugin = require('webpack-utf8-bom'); // add this line
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
@hkhc
hkhc / main.js
Created April 30, 2020 02:07
Webpack demo with unicode
const path = require('path');
module.exports = {
entry: './src/main.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
}
@hkhc
hkhc / webpack.config.js
Created April 30, 2020 02:05
Webpack config for webpack unicode demo
import _ from 'lodash';
function component() {
const element = document.createElement('div');
element.innerHTML = _.join(['Hello', 'webpack'], ' ');
return element;
}
@hkhc
hkhc / index.html
Created April 30, 2020 01:59
Demo for webpack with unicode
<!doctype html>
<html>
<head>
<title>Webpack Unicode Demo</title>
</head>
<body>
<h1>Webpack Unicode Demo</h1>
<script src="bundle.js"></script>
</body>
</html>
@hkhc
hkhc / gist:69481aac39c2f4fdfdceabbb2a5bf8c4
Last active March 12, 2019 17:23
rxjava to replace asynctask
// Assume you have three class to represent state of operations,
// and they have a common base class
sealed class BaseClass {
class ClassStart: BaseClass()
class ClassProgress(var percent: Int): BaseClass()
class ClassStop: BaseClass()
}
// Define the job here. It does not really execute it