Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
import csv
import os
import subprocess
import time
from io import StringIO
from typing import List, Dict
from datadog import initialize, statsd
from kubernetes import client, config
tailrec fun fib(count: Long, seq: List<Int> = listOf(1,1)): List<Int> =
if (seq.size >= count) seq else fib(count, seq + (seq.last() + seq[seq.lastIndex - 1]))
class Person(val name: String, val city: String)
class ComposedObject(textDelegate: EditTextDelegate){
var text: String? by textDelegate
}
class EditTextDelegate {
// represents some editable text view
var editText: EditText = EditText();
operator fun getValue(thisRef: Any?, property: KProperty<*>): String? {
return editText.text
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String?) {
editText.text = value
var isChecked: Boolean by object {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Boolean {
return checkbox.checked
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean) {
checkbox.checked = value
}
}
(1..100000).map { it * it }.find { it.toString().contains(Regex(".*123.*")) }
listOf("This", "is","a", "sentence").reduce { accumulator, s -> accumulator +" " + s }
val listener: (View) -> Unit = { println(“clicked!”) }
some_view.setOnClickListener (listener)
// Or you can use closures
some_view.setOnClickListener {doSomething()}