Skip to content

Instantly share code, notes, and snippets.

Avatar

Maciej Górski mg6maciej

View GitHub Profile
View gist:f38820866aa8db3e3227079592e67491
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;
}
View keybase.md

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
Real hacky way to let yourself use android.support.v4.content.FileProvider with exported and without grantUriPermissions.
View FileProviderHack.kt
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
Moshi generic type adapters
View MoshiExtensions.kt
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
Comparison of incremental compilation times when tests are in the same module vs in separate one (~900 unit tests in 140 classes)
View Incremental Kotlin
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)
View Stubbable.kt
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 Apr 2, 2017
Better implementation of Kotlin's minus extension function
View BetterMinus.kt
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))
}
}
View DisposeOnDestroy.kt
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) {