Skip to content

Instantly share code, notes, and snippets.

View mg6maciej's full-sized avatar

Maciej Górski mg6maciej

View GitHub Profile
pragma solidity ^0.4.23;
contract ComposableRegistry {
function ownerOf(address erc721, uint tokenId) public view returns (address);
function parent(address erc721, uint tokenId) public view returns (address, uint);
function transfer(address toErc721, uint toTokenId, address erc721, uint tokenId) public;
function transferToAddress(address to, address erc721, uint tokenId) public;
}

Keybase proof

I hereby claim:

  • I am mg6maciej on github.
  • I am mg6maciej (https://keybase.io/mg6maciej) on keybase.
  • I have a public key ASDxHRuoFjOpaQnCgcWQalTLR3ATQ5iBOEA0I3Ixkjudgwo

To claim this, I am signing this object:

@mg6maciej
mg6maciej / FileProviderHack.kt
Created May 11, 2017 15:12
Real hacky way to let yourself use android.support.v4.content.FileProvider with exported and without grantUriPermissions.
import android.content.Context
import android.content.pm.ProviderInfo
import android.support.v4.content.FileProvider
class FileProviderHack : FileProvider() {
override fun attachInfo(context: Context, info: ProviderInfo) {
try {
super.attachInfo(context, info)
} catch (ex: SecurityException) {
@mg6maciej
mg6maciej / MoshiExtensions.kt
Created May 6, 2017 10:07
Moshi generic type adapters
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import java.lang.reflect.Type
// val adapter = moshi.listAdapter<MyModel>()
// val adapter = moshi.mapAdapter<String, List<MyModel>>(valueType = listType<MyModel>())
inline fun <reified E> Moshi.listAdapter(elementType: Type = E::class.java): JsonAdapter<List<E>> {
return adapter(listType<E>(elementType))
@mg6maciej
mg6maciej / Incremental Kotlin
Created May 1, 2017 17:58
Comparison of incremental compilation times when tests are in the same module vs in separate one (~900 unit tests in 140 classes)
Serious change (e.g. public function name)
tests in the same module
▇▇▇▇▇▇▇▇ 15% :compileKotlin (0:02.743)
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 66% :compileTestKotlin (0:11.629)
▇▇▇▇▇▇▇▇▇▇ 19% :junitPlatformTest (0:03.323)
tests in separate module
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 34% :compileKotlin (0:02.646)
▇▇▇▇▇▇▇▇▇▇▇▇ 21% :core-tests:compileTestKotlin (0:01.579)
fun <T> stubbable(function: KCallable<T>) = object : ReadWriteProperty<Any?, T> {
override fun getValue(thisRef: Any?, property: KProperty<*>) = throw UnsupportedOperationException()
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
val args = listOf(thisRef) + function.parameters.drop(1).map { anyList<Any>() }
whenever(function.call(*args.toTypedArray())).thenReturn(value)
}
}
@mg6maciej
mg6maciej / BetterMinus.kt
Last active April 2, 2017 19:38
Better implementation of Kotlin's minus extension function
fun <T> List<T>.betterMinus(other: List<T>): List<T> {
return if (other.isEmpty()) {
this
} else {
(this - other.first()).betterMinus(other.subList(1, other.size))
}
}
@mg6maciej
mg6maciej / DisposeOnDestroy.kt
Last active April 5, 2018 08:45
disposeOnDestroy
import android.app.Activity
import android.app.Application
import android.os.Bundle
import io.reactivex.disposables.Disposable
import io.reactivex.functions.Consumer
fun Activity.disposeOnDestroy() = Consumer<Disposable> { disposable ->
application.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
override fun onActivityDestroyed(activity: Activity) {