Skip to content

Instantly share code, notes, and snippets.

If you find a bug in my code, I've probably haven't had enough coffee yet...

Erik Hellman ErikHellman

If you find a bug in my code, I've probably haven't had enough coffee yet...
Block or report user

Report or block ErikHellman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ErikHellman / KittyLog.kt
Last active Sep 4, 2019
A super tiny wrapper for Android Log utility that allows log printing in unit tests. For a more advanced log wrapper for Android, see
View KittyLog.kt
Licensed under Apache 2.0 (
This is a tiny log utility for Android Logcat. It allows logs to be used in code that is unit
tested on host (without Android framework available).
The only advantage with this utility above Timber is that it doesn't require any setup.
For real-world, production application I strongly recommend using Timber (see instead.
ErikHellman / KittyLog.kt
Created Aug 19, 2019
A super tiny wrapper for Android Log utility.
View KittyLog.kt
package se.hellsoft.coroutineantipatterns
import android.util.Log
internal const val TAG = "KittyLog"
fun logi(message: String, throwable: Throwable? = null) {
try {
ErikHellman / NonBlockingEchoServer.kt
Last active Aug 16, 2019
A very simple example of an echo-server using the non-blocking Java I/O APIs
View NonBlockingEchoServer.kt
package se.hellsoft.nonblocking.echo
import java.nio.ByteBuffer
import java.nio.channels.SelectionKey
import java.nio.channels.Selector
import java.nio.channels.ServerSocketChannel
import java.nio.channels.SocketChannel
ErikHellman / ImageFormatName.kt
Last active Aug 8, 2019
Kotlin functions for getting the name of an ImageFormat or PixelFormat Integer.
View ImageFormatName.kt
fun imageFormatName(format: Int): String = when (format) {
ImageFormat.DEPTH16 -> "DEPTH16"
ImageFormat.FLEX_RGBA_8888 -> "FLEX_RGBA_8888"
ImageFormat.FLEX_RGB_888 -> "FLEX_RGB_888"
ImageFormat.HEIC -> "HEIC"
ImageFormat.JPEG -> "JPEG"
ImageFormat.NV16 -> "NV16"
ImageFormat.NV21 -> "NV21"
ErikHellman / WebViewServer.kt
Last active Nov 8, 2019
This class is no longer needed now that Google provides WebViewAssetLoader (see
View WebViewServer.kt
MIT License
Copyright (c) 2019 Erik Hellman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
ErikHellman / WebViewServer.kt
Created Apr 8, 2019
A simple "web server" for handling intercepted WebView requests on Android and deliver local content.
View WebViewServer.kt
package se.hellsoft.webviewserver
import android.content.res.AssetManager
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
ErikHellman / generateSelector.js
Last active Jan 10, 2019
Generate a selector for an element.
View generateSelector.js
// Create a path to an element of the form 2/1/1/34 (index of each child)
function getDomPath(el) {
const stack = [];
while (el.parentNode != null) {
let sibCount = 0;
let sibIndex = 0;
for (let i = 0; i < el.parentNode.childNodes.length; i++) {
const sib = el.parentNode.childNodes[i];
if (sib === el) {
ErikHellman / LitElementDialogExample.js
Last active Sep 9, 2019
Basic dialog example with LitElement
View LitElementDialogExample.js
import { LitElement, html } from '@polymer/lit-element'
import { classMap } from 'lit-html/directives/classMap'
class MyDialog extends LitElement {
constructor () {
this.opened = false
View SimpleService.kt
class SimpleService : Service() {
companion object {
@JvmStatic fun launchService(context: Context) {
override fun onBind(intent: Intent?): IBinder {
return Binder()
ErikHellman / BackgroundThreadFunction.kt
Last active Jan 16, 2018
Background Thread Function
View BackgroundThreadFunction.kt
fun launchBackgroundJob(job: () -> Unit) {
thread { job() }
You can’t perform that action at this time.