Skip to content

Instantly share code, notes, and snippets.

View Takhion's full-sized avatar

Eugenio Marletti Takhion

View GitHub Profile
@Takhion
Takhion / Test.kt
Created January 22, 2017 15:52
Flat `use` in Kotlin
fun test() {
val lines = use {
val a = File("path1").reader().use
val b = File("path2").reader().use
val c = File("path3").reader().use
a.readLines() + b.readLines() + c.readLines()
}
}
import android.animation.TimeInterpolator;
/**
* Interpolator that produces a decaying sine wave oscillating around zero.
*/
public class ShakeInterpolator implements TimeInterpolator {
private static final double AMP, FREQ = 5, DECAY = 6;
static {
fun test() {
val item1 = Item(GameObject())
val item2 = Item(GameObject())
assert(ItemStack(setOf(item1, item2)) is ItemStack)
assert(ItemStack(setOf(item1)) is Item)
assert(ItemStack(emptySet()) is Empty)
}
class ItemStack private constructor(val items: Set<Item>) : Elem() {
companion object {
import rx.Observable
import rx.subjects.BehaviorSubject
import SingletonObservable.ItemWrapper
/**
* Represents the current subscription status (either 'unsubscribed' or 'subscribed') of a [SingletonObservable].
* The index starts at [SingletonObservable.firstSubscriptionIndex] as 'unsubscribed', and every subsequent value alternates between the two states.
* Use [SingletonObservable.isSubscribed] to calculate the status for a specific [SubscriptionIndex].
*
* Note that a subscription index is constant for the lifetime of a stream, which is completed by the first time either one of
@Takhion
Takhion / SharedPreferencesPropertyDelegate.kt
Created October 13, 2017 07:58
Shared Preferences Kotlin property delegate with injected provider
import android.app.Activity
import kotlin.reflect.KProperty
interface SharedPreferencesWriter //TODO
interface SharedPreferencesWriterProvider {
val sharedPreferencesWriter: SharedPreferencesWriter
fun <T> prefs() = SharedPreferencesPropertyDelegate<T>()
}
@Takhion
Takhion / build.gradle
Last active December 20, 2017 07:35 — forked from gabrielemariotti/build.gradle
Store APK signing credentials in an external file using Gradle
android {
signingConfigs {
release
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
@Takhion
Takhion / gorun.go
Created March 24, 2018 17:00 — forked from mattn/gorun.go
//
// gorun - Script-like runner for Go source files.
//
// https://wiki.ubuntu.com/gorun
//
// Copyright (c) 2011 Canonical Ltd.
//
// Written by Gustavo Niemeyer <gustavo.niemeyer@canonical.com>
//
package main
@Takhion
Takhion / facebook-photo-download.go
Last active March 24, 2018 17:03 — forked from thebitguru/facebook-photo-download.go
A simple go program to download all the high resolution pictures from your facebook albums.
package main
/*
* A simple go program to download all the high resolution pictures from your facebook albums.
*
* To run this:
* 1. Go to https://developers.facebook.com/tools/explorer/?method=GET&path=me&version=v2.8
* 2. Get an Access Token: Get Token > Get User Access Token > Check "user_photos"
* 3. Paste in the app.
*/
import android.app.Activity
import android.content.Intent
import android.os.Parcel
import android.os.Parcelable
import java.io.Closeable
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
/**
* A special [Parcelable] that carries an in-memory reference to any instance of type [T], which will obviously
@Takhion
Takhion / 0_build.gradle.kts
Last active April 3, 2019 17:36
Kotlin generics are 🍌🍌🍌
// ...stuff...
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf(
"-Xnew-inference",
"-Xallow-kotlin-package"
)
}
}