Skip to content

Instantly share code, notes, and snippets.

View marcouberti's full-sized avatar

Marco Uberti marcouberti

View GitHub Profile
@marcouberti
marcouberti / zlib.kt
Last active November 14, 2023 11:38
ZLIB compression and decompression in Kotlin / Android
import java.io.ByteArrayOutputStream
import java.util.zip.Deflater
import java.util.zip.Inflater
/**
* Compress a string using ZLIB.
*
* @return an UTF-8 encoded byte array.
*/
fun String.zlibCompress(): ByteArray {
@marcouberti
marcouberti / gzip.kt
Last active February 13, 2023 22:27
Gzip compression and decompression in Kotlin / Android
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
/**
* Compress a string using GZIP.
*
* @return an UTF-8 encoded byte array.
@marcouberti
marcouberti / blot.glsl
Created December 11, 2020 14:32
KodeLife basic RGB glitch shader
#version 150
uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform vec3 spectrum;
uniform sampler2D texture0;
out vec4 fragColor;
@marcouberti
marcouberti / blot.glsl
Last active December 11, 2020 13:35
KodeLife basic texture shader
#version 150
uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform vec3 spectrum;
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
@marcouberti
marcouberti / 001 - Kotlin lateinit.kt
Last active June 17, 2020 06:58
Alternative lateinit implementation without using the native lateinit Kotlin declaration.
class MyTest {
lateinit var subject: TestSubject
@SetUp fun setup() {
subject = TestSubject()
}
@Test fun test() {
subject.method() // dereference directly
}
Accept-Encoding: gzip
Accept-Language: en-US;q=1.0
Authorization: Bearer 2528dfc64a2f3a09b315dc64f73796711a05fa7f161cdee45ff8e0ef17ea543d
Connection: Keep-Alive
Content-Length: 109813
Content-Type: application/json; charset=UTF-8
Host: testaka3.sogei.it
Immuni-Dummy-Data: 0
User-Agent: Immuni
Accept-Encoding: gzip
Accept-Language: en-US;q=1.0
Authorization: Bearer 541f51af2878529f692094b222827e53bf83a0f61553932b2c91bc9ff959c514
Connection: Keep-Alive
Content-Length: 109813
Content-Type: application/json; charset=UTF-8
Host: api.staging.dec-poc1.immuni.org
Immuni-Dummy-Data: 0
User-Agent: Immuni
@marcouberti
marcouberti / Decrypter.java
Created May 5, 2020 12:28 — forked from scotttam/Decrypter.java
encrypt and decrypt with PBKDF2/SHA1 and AES
import javax.crypto.Cipher;
import java.security.spec.KeySpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.SecretKeyFactory;
import java.security.AlgorithmParameters;
import javax.crypto.spec.IvParameterSpec;
public class Decrypter {
@marcouberti
marcouberti / !SecretMenuGlobalTouchListener.kt
Last active April 24, 2020 12:07
Android Global Multitouch Events Interceptor. This multitouch events interceptor can be plugged into your app without directly coupling it with your activities.
/**
* This class is register to the [Application] activity lifecycle and
* add or remove the overlay view to each [Activity] as a content view.
*
* @see Activity.addContentView
*/
class SecretMenuGlobalTouchListener(
application: Application,
private val touchManager: SecretMenuTouchManager
): InvisibleOverlayView.TouchListener {
@marcouberti
marcouberti / CoroutineTestRule.kt
Last active June 1, 2021 01:51
Android Local Unit Test using Kotlin Coroutines and MockK. A CoroutineTestRule is needed if your tested classes use the Main dispatcher, otherwise an "IllegalStateException" is thrown. Also a InstantTaskExecutorRule is needed to avoid a "NullPointerException". Use runBlockingTest to skip all suspending delays. Use coEvery/coVerify to mock/verify…
import org.junit.rules.TestWatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.*
import org.junit.runner.Description
@ExperimentalCoroutinesApi
class CoroutineTestRule(val dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) : TestWatcher() {
override fun starting(description: Description?) {