Skip to content

Instantly share code, notes, and snippets.

View nosix's full-sized avatar

nosix nosix

View GitHub Profile
using UnityEditor;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace AssetLoader
{
[RequireComponent(typeof(AudioSource))]
public class AudioSourceLoader : MonoBehaviour
{
[SerializeField] private AssetReferenceAudioClip audioClip;
@nosix
nosix / LiveDataEditor.kt
Created October 9, 2019 06:16
How to make MutableLiveData declaration unnecessary in ViewModel.
package com.example.android.livedata
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
abstract class LiveDataEditor<R> {
fun <T> propertyOf() = LiveDataProperty<T>()
@nosix
nosix / capture.bat
Last active June 24, 2019 04:10
Batch file to start Android device screen capture. Please put it in the scrcpy folder and execute it.
@echo off
cd %~dp0
setlocal
set CMD=adb devices
for /f "usebackq tokens=1,2,3*" %%a in (`%CMD%`) do (
if "%%b" == "device" (
set DEVICE_ID=%%a
@nosix
nosix / ExampleTest.kt
Created July 12, 2018 03:56
pass JSONCompareMode to JSONAssert when testing with WebTestClient
@RunWith(SpringRunner::class)
@SpringBootTest
@AutoConfigureWebTestClient
class ExampleTests {
@Autowired
private lateinit var client: WebTestClient
@Test
fun test_of_get() {
client.get().uri("/api/todo")
@nosix
nosix / coroutineSample.kt
Last active July 28, 2024 11:15
Promise and async/await sample in Kotlin/JS
fun main(args: Array<String>) {
launch {
loadAllFiles()
}
}
fun launch(block: suspend () -> Unit) {
block.startCoroutine(object : Continuation<Unit> {
override val context: CoroutineContext get() = EmptyCoroutineContext
override fun resume(value: Unit) {}
@nosix
nosix / limitedExtensions.kt
Created September 7, 2017 04:23
How to limit the scope of extension functions in Kotlin.
interface Extension
// Why is keyword `class` instead of `object`?
// Because we can use the `foo` function after importing `FooExtension.foo`.
class FooExtension : Extension {
fun String.foo(): String = "Foo${this}"
}
class BarExtension : Extension {
fun String.bar(): String = "Bar${this}"
@nosix
nosix / after.kt
Created September 4, 2017 06:04
convert deprecated @nativeGetter/@nativeSetter to inline extension function
external interface MethodMap
inline operator fun MethodMap.get(propertyName: String): Function<Any>? = this.asDynamic()[propertyName]
inline operator fun MethodMap.set(propertyName: String, value: Function<Any>?) {
this.asDynamic()[propertyName] = value
}
@nosix
nosix / generated_sample.js
Last active September 5, 2017 03:07
union type in Kotlin/JS
function sample$lambda() {
return 'Bar';
}
function sample() {
var v1 = 'Foo';
var v2 = sample$lambda;
}
@nosix
nosix / Application.kt
Last active February 22, 2023 01:04
Google App Engine Standard Environment in Java8 with Kotlin and SpringBoot
package com.example
import com.example.mapper.json.JsonObjectMapper
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.web.support.SpringBootServletInitializer
import org.springframework.context.annotation.Bean
import org.thymeleaf.spring4.SpringTemplateEngine
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver
import org.thymeleaf.spring4.view.ThymeleafViewResolver
@nosix
nosix / pidep
Last active December 16, 2016 17:02
bash command to deploy and run python on remote Raspberry Pi.
#!/bin/bash
CMD=`basename $0`
usage() {
echo "Usage: $CMD [-r script] [-d dst] [-s src]" 1>&2
}
COMMAND=
DST=