Skip to content

Instantly share code, notes, and snippets.

View LongClipeus's full-sized avatar
:atom:
Focusing

Long Le Van LongClipeus

:atom:
Focusing
View GitHub Profile
@LongClipeus
LongClipeus / InstallJdk.sh
Last active March 25, 2023 19:00
Install jdk from tar.gz file in Ubuntu
sudo su
#create jvm directory
mkdir /usr/lib/jvm
#uncompress, change to your file name
tar -zxf jdk-8u211-linux-x64.tar.gz -C /usr/lib/jvm
#check if files are there
#ls /usr/lib/jvm
@LongClipeus
LongClipeus / Date.java
Last active July 24, 2019 08:01
Training java
import java.util.Scanner;
/**
* Display the calendar of any year
*
* @author LongClipeus
*
*/
public class Date {

Note

  1. You will need Java 8 to run Signaling Server. If you have multiple Java versions installed on the server you can change the default version using the update-alternatives tool as shown below:
sudo update-alternatives --config java 

Set the Default Java Version

#!/usr/bin/env python3
version= '3.0'
title = '''
_ \ __ \ __ \ ___| _) |
| | | | | | | | _ \ __| \___ \ __| __| | __ \ __|
___/ | | | | | | ( |\__ \ | ( | | | | |
_| \__, |____/ ____/ \___/ ____/ _____/ \___|_| _| .__/ \__|
____/ _|
@LongClipeus
LongClipeus / ToastUtils.kt
Created July 22, 2021 03:37
custom toast in kotlin
fun showToastGreen(context: Context, message: String) {
val toast: Toast = Toast.makeText(context, "", Toast.LENGTH_LONG)
val view = toast.view
view.background.setColorFilter(
ContextCompat.getColor(context, R.color.green_dark),
PorterDuff.Mode.SRC_IN
)
val text = view.findViewById<TextView>(android.R.id.message)
text.setTextColor(ContextCompat.getColor(context, R.color.white))
text.text = message
@LongClipeus
LongClipeus / HashUtils.kt
Last active January 15, 2025 06:32
How to generate checksum hash for a file in Kotlin
import StringUtils.encodeHex
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.security.MessageDigest
object HashUtils {
const val STREAM_BUFFER_LENGTH = 1024
@LongClipeus
LongClipeus / TrafficLightStatus.kt
Created August 3, 2021 15:45
How to make enum Parcelable in Kotlin?
import android.os.Parcel
import android.os.Parcelable
enum class TrafficLightStatus(val id: Int) : Parcelable {
RED(1),
YELLOW(2),
GREEN(3);
constructor(parcel: Parcel) : this(parcel.readInt())
@LongClipeus
LongClipeus / PermissionUtils.kt
Last active September 25, 2021 07:41
How to know if user has disabled Picture in Picture feature permission?
const val ACTION_PIP_SETTING = "android.settings.PICTURE_IN_PICTURE_SETTINGS"
@RequiresApi(Build.VERSION_CODES.O)
fun AppCompatActivity.hasPictureInPicturePermission(): Boolean {
val appOps = getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
val uid = android.os.Process.myUid()
val mode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
appOps.unsafeCheckOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, uid, packageName)
} else {
@Suppress("DEPRECATION")
import android.content.Context
import androidx.annotation.RawRes
import com.tech.melait.common.utils.ResourceUtils.readRawFile
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
suspend fun readRawFile(context: Context, @RawRes res: Int) = withContext(Dispatchers.Default) {
context.resources.readRawFile(res)
}