Skip to content

Instantly share code, notes, and snippets.

@zach-klippenstein
zach-klippenstein / SegmentedControl.kt
Last active May 3, 2024 11:15
iOS-style segmented control in Compose
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
@christianb
christianb / pipe.kt
Created January 23, 2021 12:07
Pipe function in Kotlin
// 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
@NitinPraksash9911
NitinPraksash9911 / UnzipUtils.kt
Last active May 6, 2024 15:31
Unzipping file in android/kotlin
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 {
@haxscramper
haxscramper / languages-and-vms.md
Last active March 16, 2024 19:45
languages-and-vms
@Eng-Fouad
Eng-Fouad / SampleMingw.kt
Created July 9, 2019 22:38
Kotlin Native Win32 GUI Sample
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.
@bastman
bastman / forwardCompose.kt
Created August 11, 2018 08:07
FP forwardCompose: andThen, andAlso
/**
* 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)
*/
@nishanthvijayan
nishanthvijayan / PipeForward.md
Last active April 30, 2023 12:54
Simple Pipe forward operator in Kotlin

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:

@SkyzohKey
SkyzohKey / SettingsListBox.vala
Last active February 4, 2023 04:12
A simple ListBox to display Settings in a proper way.
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);
@vjache
vjache / PipeForward.kt
Created November 18, 2016 15:11
Pipe forward operator
operator fun <T,T1> ((T) -> T1).unaryPlus(): (T.()->T1) {
val f = this
return {
f(this)
}
}
fun mkStr(t:Int) : String {
return ""
}