Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Erik Hellman ErikHellman

🏠
Working from home
View GitHub Profile
@ErikHellman
ErikHellman / KittyLog.kt
Created Aug 19, 2019
A super tiny wrapper for Android Log utility.
View KittyLog.kt
@file:Suppress("unused")
package se.hellsoft.coroutineantipatterns
import android.util.Log
internal const val TAG = "KittyLog"
fun logi(message: String, throwable: Throwable? = null) {
try {
@ErikHellman
ErikHellman / MyActivity.java
Last active Aug 12, 2019
Simple LocalBinder demo for Android
View MyActivity.java
package se.hellsoft.simpleservicecallbackdemo;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@ErikHellman
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.DEPTH_JPEG -> "DEPTH_JPEG"
ImageFormat.DEPTH_POINT_CLOUD -> "DEPTH_POINT_CLOUD"
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
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
@file:Suppress("unused")
package se.hellsoft.webviewserver
import android.content.res.AssetManager
import android.net.Uri
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import java.io.ByteArrayInputStream
import java.io.File
@ErikHellman
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) {
console.log(el.nodeName);
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
ErikHellman / MainActivity.java
Created Apr 1, 2016
Async communication with Service
View MainActivity.java
package se.hellsoft.handlerthreadingdemo;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
@ErikHellman
ErikHellman / MyActivity.java
Created Jul 27, 2014
Android sample showing how to use Handlers for efficient foreground/background operations.
View MyActivity.java
package se.hellsoft.demo.codesnippetdemo;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;
import android.view.View;
View RxJavaAndDiffUtil.java
private void subscribeToData() {
Flowable<List<Data>> dataLists = Flowable
.interval(0, 3, TimeUnit.SECONDS, Schedulers.computation())
.map(val -> {
Log.d(TAG, "Shuffling original list...");
return Data.shuffle(originalList).subList(0, (int) (0.8 * originalList.size()));
})
.share();
Flowable<List<Data>> startWith = dataLists
View SimpleService.kt
class SimpleService : Service() {
companion object {
@JvmStatic fun launchService(context: Context) {
context.startService(Intent(context, SimpleService::class.java))
}
}
override fun onBind(intent: Intent?): IBinder {
return Binder()
}
@ErikHellman
ErikHellman / BackgroundThreadFunction.kt
Last active Jan 16, 2018
Background Thread Function
View BackgroundThreadFunction.kt
fun launchBackgroundJob(job: () -> Unit) {
thread { job() }
}