This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some example programs in Om to showcase just how bad it is to program in. | |
# These are from my CS course. | |
$Task2 = { | |
@_ = $_; | |
/Cone = [ | |
$h = @_/input-float (@_/string "height"); | |
$r = @_/input-float (@_/string "little radius"); | |
$R = @_/input-float (@_/string "big radius"); | |
M/if ($h /less-than-or-equal-to 0/f) { @_ = @_; @h=$h;@r=$r;@R=$R; /do = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.annotation.SuppressLint | |
import androidx.compose.animation.core.animateDpAsState | |
import androidx.compose.animation.core.animateFloatAsState | |
import androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.gestures.awaitFirstDown | |
import androidx.compose.foundation.gestures.forEachGesture | |
import androidx.compose.foundation.gestures.horizontalDrag | |
import androidx.compose.foundation.layout.Arrangement.spacedBy | |
import androidx.compose.foundation.layout.Box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://discuss.kotlinlang.org/t/pipe-forward-operator/2098/22 | |
// Showes how to implement a pipe function in Kotlin | |
infix fun <T, R> T.into(func: (T) -> R) = func(this) | |
// How to use | |
fun add(x: Int): Int = x + 1 | |
fun mul(x: Int): Int = x * 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.* | |
import java.util.zip.ZipFile | |
/** | |
* UnzipUtils class extracts files and sub-directories of a standard zip file to | |
* a destination directory. | |
* | |
*/ | |
object UnzipUtils { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample | |
import kotlinx.cinterop.* | |
import platform.windows.* | |
@ExperimentalUnsignedTypes | |
fun WndProc(hwnd: HWND?, msg: UINT, wParam: WPARAM, lParam: LPARAM) : LRESULT | |
{ | |
// This switch block differentiates between the message type that could have been received. If you want to | |
// handle a specific type of message in your application, just define it in this block. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example: forward compose | |
* | |
* see: | |
* - https://discuss.kotlinlang.org/t/pipe-forward-operator/2098/43 | |
* - https://hackernoon.com/funktionale-function-composition-for-kotlin-1f6e3e3c3a83 | |
* | |
* val composition = ::sqrt thenAlso ::println then ::sqrt thenAlso ::println | |
* val result:Double = composition(16.0) | |
*/ |
Here I try to implement a simple pipe forward operator similar to |> operator in Elixir or the andThen operator in Scala
Let's say you have a need for doing something like this
val x = f("something")
val y = g(x)
val z = h(y)
This is also equivalent to saying:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SettingsListBox: Gtk.Box { | |
public Gtk.Box scrolled_box; | |
public Gtk.ListBox listbox; | |
public SettingsListBox () { | |
this.set_orientation (Gtk.Orientation.HORIZONTAL); | |
Gtk.ScrolledWindow scroll = new Gtk.ScrolledWindow (null, null); | |
scroll.set_size_request (400, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operator fun <T,T1> ((T) -> T1).unaryPlus(): (T.()->T1) { | |
val f = this | |
return { | |
f(this) | |
} | |
} | |
fun mkStr(t:Int) : String { | |
return "" | |
} |
NewerOlder