Skip to content

Instantly share code, notes, and snippets.

View kittinunf's full-sized avatar

Kittinun Vantasin kittinunf

View GitHub Profile
sealed class Either<out L, out R> {
companion object {
fun <L> left(left: L): Left<L, Nothing> = Left(left)
fun <R> right(right: R): Right<Nothing, R> = Right(right)
}
fun left(): L? = when (this) {
is Left -> this.l
is Right -> null
public protocol Apply {}
extension Apply where Self: Any {
//let f = Foo().apply {
// $0.foo = 10
// $0.bar = "bar"
//}
public func apply(_ block: (inout Self) -> Void) -> Self {
var copy = self
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
//swift
protocol Addable {
func add(lhs: Self, rhs: Self) -> Self
}
extension String: Addable {
func add(lhs: String, rhs: String) -> String {
return lhs + rhs
}
" Colemak stuff
nnoremap k h
nnoremap n j
nnoremap e k
nnoremap i l
nnoremap d v
nnoremap D V
nnoremap s d
nnoremap S D
#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
using namespace std;
class Possible {
vector<bool> _b;
public:
Possible() : _b(9, true) {}
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()
#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;
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
# 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)[[