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()
{
package sample
import glibresources.*
import kotlinx.cinterop.*
import libgtk3.*
import libgtk3.G_APPLICATION_FLAGS_NONE
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
*/
// http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
//
// Usage:
// ----------------------------------------------
// val url = URL("http://abc.com:80/smith/home.html?key=value&key2=value2")
// println("${url.protocol} -- ${url.host} -- ${url.port} -- ${url.path} -- ${url.query}")
// ---------------------------------------------
class URL(url: String){
var protocol = ""
enum class Type { STATUS, HEADER, BODY }
fun readK(fd: Int, chunk: Int, block: (ByteArray) -> Unit) {
var type = Type.STATUS
var contentLength = 0L
var spaceCount = 0
var method = ""; var path = ""; var protocol = ""
var key = ""; var value = ""
@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()
*
*
import kotlinx.cinterop.*
import platform.posix.*
// IrFile
// ------------------------------------------------------
data class PsiFile internal constructor(val path: String, var name: String = path.substringAfterLast('/'))
val PsiFile.open get() = open(path, O_RDONLY)
val PsiFile.size get() = nativeHeap.alloc<stat>().apply { stat(path, ptr) }.st_size
# Install build tools
sudo apt-get install python3 python3-pip python3-setuptools python3-wheel ninja-build meson
#gnome-shell
echo "downloading gnome-shell..."
curl -o gnome-shell-3.35.91.tar.xz https://ftp.gnome.org/pub/GNOME/sources/gnome-shell/3.35/gnome-shell-3.35.91.tar.xz
tar -xz gnome-shell-3.35.91.tar.xz
echo "install gnome-shell dependencies..."
sudo apt-get install pkg-config cmake libecal2.0-dev libgirepository1.0-dev