Skip to content

Instantly share code, notes, and snippets.

View amanurat's full-sized avatar

Assanai Manurat amanurat

  • Odd-e Thailand
  • Thailand
View GitHub Profile
@amanurat
amanurat / gist:d68bbd4f55d0a73559ad
Created March 28, 2016 08:15 — forked from dodyg/gist:5823184
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@amanurat
amanurat / gist:59167d22d2c8166446c9f1b981caa333
Last active April 8, 2016 13:42 — forked from dodyg/gist:5616605
Kotlin Programming Language Cheat Sheet Part 2

This is a quick guide to Kotlin programming language. The previous part of this guide is here

#Object Oriented

fun main(args : Array<String>) {
  class local (val x : Int)
  
  val y = local(10)
 println("${y.x}")
@amanurat
amanurat / gist:d4e992b31d8a33c7c4d2a9aae67b4359
Created April 8, 2016 13:43 — forked from dodyg/gist:5823756
Kotlin Programming Language Cheat Sheet Part 3

#Control Structures

##If statement

Kotlin if statement should look familiar with other language

fun main(args : Array<String>) {
 val total = 10
@amanurat
amanurat / BriefLogFormatter.kt
Last active May 23, 2016 17:17 — forked from mikehearn/BriefLogFormatter.kt
BriefLogFormatter
// A couple of inlined utility functions: the first is just a syntax convenience, the second lets us use
// Kotlin's string interpolation efficiently: the message is never calculated/concatenated together unless
// logging at that level is enabled.
inline fun <reified T : Any> loggerFor(): org.slf4j.Logger = LoggerFactory.getLogger(T::class.java)
inline fun org.slf4j.Logger.trace(msg: () -> String) {
if (isTraceEnabled) trace(msg())
}
/**
* A Java logging formatter that writes more compact output than the default.
open class A {
}
abstract class Adapter<T : A> {
abstract fun create(): T
abstract fun itemCount(): Int
open fun bind(a: T) {
}
}
@amanurat
amanurat / actor.kt
Created August 1, 2016 15:09 — forked from mgodave/actor.kt
Kotlin actor
package actors
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.SettableFuture
import com.google.common.util.concurrent.MoreExecutors
import java.util.concurrent.Executors
import java.util.ArrayList
import java.util.concurrent.LinkedBlockingQueue
import com.google.common.util.concurrent.ListeningExecutorService
import java.util.concurrent.ThreadFactory
@amanurat
amanurat / easyhttp-rx.kt
Created August 1, 2016 15:09 — forked from citizenmatt/easyhttp-rx.kt
RX + Kotlin
fun get(url: String, headers: Headers = Headers()): Observable<Response> {
//return getWithExplicitClass(url, headers)!!
//return getWithAnonymousClass(url, headers)!!
//return getWithInlineUsingObsoleteSubscribeFunc(url, headers)!!
return getWithFailingInlineFunction(url, headers)!!
}
fun getWithFailingInlineFunction(url: String, headers: Headers = Headers()) : Observable<Response>? {
// This fails. Looks like a bug in Kotlin: http://youtrack.jetbrains.com/issue/KT-4598
@amanurat
amanurat / build.gradle
Created August 1, 2016 15:15 — forked from mitchwongho/build.gradle
Kotlin Android build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'me.tatarka.retrolambda'
buildscript {
ext.kotlin_version = '1.0.0-beta-4584'
ext.android_support_lib_version = '23.1.1'
ext.retrolambda_version = '3.2.4'
repositories {
jcenter()
@amanurat
amanurat / KotlinRxExt.kt
Created August 1, 2016 15:16 — forked from AAverin/KotlinRxExt.kt
Kotlin Rx Extensions
import rx.Observable
import rx.Observer
import rx.Subscriber
import rx.Subscription
import rx.functions.Action0
import rx.functions.Action1
fun <T> Observable<T>.uiSubscribe(schedulers: Schedulers, subscriber: Subscriber<in T>): Subscription {
return subscribeOn(schedulers.io)
.observeOn(schedulers.mainThread)
package pl.kpob.utils.extensions
import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.support.v4.content.ContextCompat
import android.view.WindowManager
import flow.Flow
import org.jetbrains.anko.AlertDialogBuilder
import pl.sisms.gminformix.utils.extensions.supportsLollipop