Skip to content

Instantly share code, notes, and snippets.

View babedev's full-sized avatar

Christopher Ng babedev

  • BabeDev
  • Bangkok, Thailand
View GitHub Profile
#include "hello.h"
char * hello() {
return "Hello World\n";
}
#ifndef HELLO_H_
#define HELLO_H_
char * hello();
#endif
group 'com.babedev'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
import kotlinx.cinterop.*
import hello.*
fun main(args: Array<String>) {
print(hello()?.toKString())
}
headers = /path/to/header/hello.h
GsonBuilder().registerTypeAdapterFactory(NullStringToEmptyAdapterFactory())
.create()
.run {
return fromJson(this@toObject, T::class.java)
}
class NullStringToEmptyAdapterFactory : TypeAdapterFactory {
override fun <T> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T>? {
if (type.rawType != String::class.java) {
@babedev
babedev / get-ip.groovy
Last active December 23, 2017 14:41
Get IP address
static def getIPAddress() {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces()
while (interfaces.hasMoreElements()) {
Enumeration<InetAddress> addresses = interfaces.nextElement().getInetAddresses()
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement()
if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) {
@babedev
babedev / use-get-ip.groovy
Last active December 23, 2017 14:47
Use getIPAddress()
buildTypes {
local {
buildConfigField("String", "API_URL", "\"http://${getIPAddress()}:5000/api/v1\"")
}
debug {
buildConfigField("String", "API_URL", "\"http://my.staging.server/api/v1\"")
}
release {
public final class BuildConfig {
public static final boolean DEBUG = false;
public static final String APPLICATION_ID = "my.app";
public static final String BUILD_TYPE = "local";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "0.1.0";
// Fields from build type: local
public static final String API_URL = "http://192.165.36.44:5000/api/v1";
}
@babedev
babedev / bnv-disable-shift.kt
Created January 30, 2018 08:37
Disable shift mode for BottomNavigationView
@SuppressLint("RestrictedApi")
fun BottomNavigationView.disableShiftMode() {
val menuView = this.getChildAt(0) as BottomNavigationMenuView
try {
val shiftingMode = menuView.javaClass.getDeclaredField("mShiftingMode")
shiftingMode.isAccessible = true
shiftingMode.setBoolean(menuView, false)
shiftingMode.isAccessible = false