Skip to content

Instantly share code, notes, and snippets.

View kalaiselvan369's full-sized avatar
🎯
Focusing

Kalaiselvan kalaiselvan369

🎯
Focusing
View GitHub Profile
@kalaiselvan369
kalaiselvan369 / characters.kt
Last active June 8, 2023 11:43
usage of characters
fun main() {
val escapeQuotes = "\"a\""
println("\thello")
println('\n')
println(escapeQuotes)
println("\\h")
println('5'.code) // prints the ASCII code
println(56.toChar()) // prints 8 the value for ASCII code 56
@kalaiselvan369
kalaiselvan369 / numbers.kt
Created June 8, 2023 11:12
Various notation in double, float and literal constants
fun main() {
// double declaration
val d = 1.234 // type is inferred
val doubleNotation = 1.2e10
println(doubleNotation)
// float declaration
val floatValue = 123.23452F
val floatValueRoundedOff = 1.234278690234f
@kalaiselvan369
kalaiselvan369 / val_immutable.kt
Last active June 8, 2023 14:23
val & var difference
fun main() {
val a = 10
//a = 11 //Error: val cannot be reassigned
// Line: 3 won't compile hence commented
}
@kalaiselvan369
kalaiselvan369 / entry_point.kt
Last active June 7, 2023 07:55
Kotlin Basics
fun main() {
println("Hello World")
}
fun main() {
sumOfTwoBytes()
}
/*
Why the answer is -16 when we expect the result in byte. Let's do that manually. We know that byte can store values
from -128 to 127 only. Here we want to store the 240 which is not possible. But how -16 is returned.
Binary value of 240 is 11110000
@kalaiselvan369
kalaiselvan369 / mpp-build.gradle
Last active April 24, 2020 12:31
Build gradle for MPP
plugins {
id 'org.jetbrains.kotlin.multiplatform'
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'maven-publish'
// Because the components are created only during the afterEvaluate phase, you must
// configure your publications using the afterEvaluate() lifecycle method.
afterEvaluate {
@kalaiselvan369
kalaiselvan369 / spotless.gradle
Created April 17, 2020 11:20
Gradle file for spotless plugin
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
kotlin {
target '**/*.kt'
ktlint("0.36.0")
//ktlint("0.36.0").userData(['disabled_rules': 'no-wildcard-imports'])
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
@kalaiselvan369
kalaiselvan369 / build.gradle
Created April 17, 2020 11:11
Project build gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$androidGradlePluginVersion"
@kalaiselvan369
kalaiselvan369 / pre-commit.bash
Last active April 17, 2020 11:04
Precommit hooks that runs spotless code formatter.
#!/bin/bash
LC_ALL=C
RED='\033[0;1;31m'
NC='\033[0m' # No Color
echo "Running git pre-commit hook"
local_branch="$(git rev-parse --abbrev-ref HEAD)"
@kalaiselvan369
kalaiselvan369 / app_build.gradle
Created April 17, 2020 10:49
Spotless and pre-commit
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: 'com.google.gms.google-services'
apply from: "$rootDir/spotless.gradle"
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()