Skip to content

Instantly share code, notes, and snippets.

View kittinunf's full-sized avatar

Kittinun Vantasin kittinunf

View GitHub Profile
@kittinunf
kittinunf / kotlin2_0.kt
Last active July 11, 2024 05:58
Kotlin2.0 and Beyond
package com.github.kittinunf.kotlin2_0
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
fun example1() {
// 1.
/**
* 1. Better operator and understanding code
*
open class Holder<out T: Any, in A>(creator: (A) -> T) {
private var creator: ((A) -> T)? = creator
@Volatile private var instance: T? = null
fun instance(arg: A): T {
val ins = instance
if (ins != null) {
return ins
}
class Solution {
public:
struct Position{
int row;
int col;
int cost;
};
int toIndex(int M, int r, int c) {
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<int> sortKMessedArray(const vector<int>& v, int k) {
auto N = v.size();
if (N == 0) return {};
#!/usr/bin/env bash
# fail if any commands fails
set -eu
# Requirements
# - Set GITHUB_TOKEN as environment variable.
# - This token must have `repo` permission and authorize kouzoh organization.
if [[ $# -ne 2 ]]; then
echo "Usage: ./script/merge_branch.sh BASE_BRANCH COMPARE_BRANCH"
REMOTE_NAME=xxxxx
git branch -r | grep "${REMOTE_NAME}/" | grep -v 'master$' | grep -v HEAD | sed -E "s/^[[:space:]]*${REMOTE_NAME}\///g" | while read line; do git push $REMOTE_NAME :heads/$line; done;
# Regex for Kotlin
--langdef=kotlin
--langmap=kotlin:+.kt
--langmap=kotlin:+.kts
--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy|inner|open)[[:space:]]*)*(private[^ ]*|protected)?[[:space:]]*class[[:space:]]+([[:alnum:]_:]+)/\4/c,classes/
--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy)[[:space:]]*)*(private[^ ]*|protected)?[[:space:]]*object[[:space:]]+([[:alnum:]_:]+)/\4/o,objects/
--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy|open)[[:space:]]*)*(private[^ ]*|protected)?[[:space:]]*((abstract|final|sealed|implicit|lazy)[[:space:]]*)*data class[[:space:]]+([[:alnum:]_:]+)/\6/d,data classes/
--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy)[[:space:]]*)*(private[^ ]*|protected)?[[:space:]]*interface[[:space:]]+([[:alnum:]_:]+)/\4/i,interfaces/
--regex-kotlin=/^[[:space:]]*type[[:space:]]+([[:alnum:]_:]+)/\1/T,types/
--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy|override|open|private[^ ]*(\[[a-z]*\])*|protected)[[
import io.reactivex.Observable
import io.reactivex.Scheduler
import io.reactivex.annotations.CheckReturnValue
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
interface Action
interface State
#include <string>
#include <chrono>
#include <thread>
#include <iostream>
using namespace std::chrono;
auto calculation1(std::string d) {
std::this_thread::sleep_for(seconds(5));
return "cal1_" + d;
class RxJavaActivity : AppCompatActivity() {
val cities = Observable.just("Warsaw", "Paris", "London", "Madrid", "Tokyo")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
concatMap()
// flatMap()