Skip to content

Instantly share code, notes, and snippets.

@kavanmevada
kavanmevada / TextViewChip.kt
Created September 8, 2018 05:21
Chip like TextView [ Rounded Corners ]
package /* Package Name */
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.widget.TextView
class TextViewChip(context: Context, attrs: AttributeSet) : TextView(context, attrs) {
private val path = Path()
@kavanmevada
kavanmevada / write_to_text_file.kt
Last active January 23, 2019 20:12
Kotlin/Native : Write to a text file using fprintf()
package sample.helloworld
import platform.posix.*
/*
Reference of C code:
---------------------
int main()
{
@kavanmevada
kavanmevada / macOS_genrate_app.sh
Created March 1, 2019 06:56
Create macOS Install app from apple cdn packages
#!/bin/bash
# Root location of file
#--------------------------
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Check for Source files exist or not.
#----------------------------------------
if [ ! -f $DIR/src/BaseSystem.dmg ]; then # Check for BaseSystem.dmg
@kavanmevada
kavanmevada / ListAdapter.kt
Created April 7, 2019 22:34
RecyclerView with ModelView
class ListAdapter(val list: MutableList<User>) : RecyclerView.Adapter<ListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
ViewHolder(inflate(LayoutInflater.from(parent.context), parent, false))
override fun getItemCount() = list.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(position)
inner class ViewHolder(private val binding: ListItemTwoTxtImgBinding) : RecyclerView.ViewHolder(binding.root) {
package sample
import glibresources.*
import kotlinx.cinterop.*
import libgtk3.*
import libgtk3.G_APPLICATION_FLAGS_NONE
@kavanmevada
kavanmevada / Application.kt
Last active March 8, 2022 17:48
kotlin-native-gtk
package sample.GtkHelpers
import kotlinx.cinterop.*
import libgtk3.*
import platform.posix.exit
abstract class Application(application_id: String, gApplicationFlagsNone: GApplicationFlags) {
val fd = open(file_path, O_RDONLY)
val buffer_size = 2
val buffer = nativeHeap.allocArray<ByteVar>(buffer_size)
var bytesRead: ssize_t = 0
while (bytesRead < 19) {
val ret = read(fd, buffer + bytesRead, (buffer_size).convert())
@kavanmevada
kavanmevada / Basic.kt
Last active November 29, 2019 13:17
BigIntegers
import kotlinx.coroutines.*
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
@kavanmevada
kavanmevada / server.kt
Last active March 25, 2023 15:33
Kotlin/Native POSIX Socket Server
package sample
import kotlinx.cinterop.*
import platform.linux.inet_ntoa
import platform.posix.*
/**
*
*/
@kavanmevada
kavanmevada / json.kt
Last active January 25, 2020 01:40
Json Parser Kotlin Multiplatform
/**
* ------------
* JSON Parser
* -----------
*
* Fully Parse: JSON(Jsontxt).parse()
* Get Single Object: JSON(Jsontxt).getObject("ggg")
* From Hashmap or List to JSON String: JsonObj.toJSONString()
*
*