Skip to content

Instantly share code, notes, and snippets.

View orangy's full-sized avatar

Ilya Ryzhenkov orangy

  • JetBrains
  • Tbilisi
View GitHub Profile
fun Modifier.shape(width: Dp, strokeBrush: Brush, fillColor: Color, shape: Shape): Modifier = composed(
factory = {
this.then(
when {
shape === RectangleShape -> rectangleModifier(width, strokeBrush, fillColor)
else -> shapeModifier(width, strokeBrush, fillColor, shape)
}
)
},
inspectorInfo = debugInspectorInfo {
@orangy
orangy / TransformCustomizedEditor.cs
Created October 26, 2019 20:15
Improve transform inspector to show and edit bounds
using UnityEditor;
using UnityEngine;
using System;
using System.Reflection;
using Component = UnityEngine.Component;
namespace Editor.Customizations
{
[CustomEditor(typeof(Transform))]
public class TransformCustomizedEditor : UnityEditor.Editor
fun let<T1:Any,T2:Any,R>(p1: T1?, p2: T2?, body: (T1,T2)->R) : R?= if (t1 != null && t2 != null) body(t1,t2) else null
@orangy
orangy / Akka.kt
Created December 26, 2014 15:57
Primitive Akka request-response code
package org.jetbrains.akkatest
import akka.actor.*
import akka.routing.*
class Request
class Response
class Handler : UntypedActor() {
override fun onReceive(message: Any): Unit = when (message) {
package x
fun fn(items: List<String?>) {
items.foreach(filter.notNull) { value ->
println("$value")
}
items.foreach(map.indexed) { (index,value) ->
println("$index $value")
}
trait SelectResult<T> {
val take: Boolean
val value: T
class object {
fun take<T>(value: T) = object : SelectResult<T> {
override val value: T = value
override val take: Boolean = true
}
fun skip<T>() = object : SelectResult<T> {
@orangy
orangy / JsonPath
Last active August 29, 2015 14:03
class JsonObject {
fun get(name : String) : JsonObject {
}
}
class JsonPathBuilder() {
fun String.div(name : String) : JsonPath {
}
class Event<T> {
typealias subscriber = (T)->Void
var subscribers = subscriber[]()
func subscribe(body : subscriber) {
subscribers.append(body)
}
func fire(value : T) {
for s in subscribers {
s(value)
}
Instead of init-increment-condition "for" statement, we use for-each style: "for (x in 0..10)", compiler optimises as needed.
Declare immutable value with "val" and mutable variable with "var", either in class, function or top-level.
Missing 'With' from Delphi? :) Standard library has "public inline fun <T, R> with(receiver: T, f: T.() → R): R = receiver.f()"
I can't have no fact for today, because type system forbids me from passing null to not-null parameter.
Last functional argument of a method can be passed outside of parentheses: https://gist.github.com/orangy/11474248 <— "using statement" DSL
trait Injected<T> {
fun instance() : T
}
trait Imap {
class object : Injected<Imap> {
override fun instance(): Imap {
return ImapImpl()
}