Skip to content

Instantly share code, notes, and snippets.

View talenguyen's full-sized avatar
🎯
Focusing

Nguyen Truong Giang talenguyen

🎯
Focusing
View GitHub Profile
/*
Given a list of non negative integers. Write code to make the largest number.
Example 1:
- Input: arr = {2, 10}
- Output: "210"
Example 2:
- Input: arr = {3, 30, 34, 5, 9}
- Output: "9534330"
/*
Given an array of integers, find the first repeating element in it.
We need to find the element that occurs more than once and whose index of first occurrence is smallest.
Example 1:
- Input: arr = {10, 5, 3, 4, 3, 5, 6}
- Output: 5
Example 2:
- Input: arr = {6, 10, 5, 4, 9, 120, 4, 6, 10}
/**
* Source: https://medium.com/androiddevelopers/suspending-over-views-19de9ebd7020
*/
suspend fun Animator.awaitEnd() = suspendCancellableCoroutine<Unit> { cont ->
// Add an invokeOnCancellation listener. If the coroutine is
// cancelled, cancel the animation too that will notify
// listener's onAnimationCancel() function
cont.invokeOnCancellation { cancel() }
addListener(object : AnimatorListenerAdapter() {
@file:Suppress("BlockingMethodInNonBlockingContext")
package features.file.download
import android.content.Context
import androidx.hilt.Assisted
import androidx.hilt.work.WorkerInject
import androidx.lifecycle.Observer
import androidx.work.Constraints
import androidx.work.CoroutineWorker

Cầu nguyện

Khi đối diện với một thảm kịch tang thương hay một tai họa hiểm nghèo, ai mà không hướng lời van xin về một Đấng Tối Cao? Ai mà không cầu nguyện khi bị vây hãm với thần chết, với bệnh hiểm, với những huyền bí ngoài sự hiểu biết của con người? Cái trực giác sâu kín này đã đến từ đâu, mà mỗi con người hay thú vật đều phải dùng đến trong những giờ phút hiểm nguy?

Mắt chúng ta sẽ tự động chớp khi có một bàn tay đưa ngang. Chân cẳng chúng ta sẽ tự động giật khi có ai gõ vào đầu gối. Đe dọa một người nào bằng cái “Hù” bất chợt, miệng hắn sẽ tự động nói “Trời ơi”. Cái trực giác tự động này, từ đâu tới?

Dù tôi không phải là một con chiên hay một tín đồ rất ngoan đạo, tôi cũng nhận hiểu cái huyền nhiệm cao cả này của thiên nhiên. Tất cả mọi sinh vật trên trái đất này, kể cả con người, đều chia chung các trực giác về sự cầu nguyện.

Và lời cầu nguyện chỉ là một van xin lớn tiếng hướng về một Đấng Tối Cao. Khi thiên nhiên đã ban cho con lừa, con chim, con người khả năng và trực giác để cất cao lời van x

@talenguyen
talenguyen / MiddlewareFunction.kt
Last active November 26, 2019 03:16
Implementation of ExpressJS Middleware functions for Kotlin.
typealias Next<A, R> = (param: A) -> R
typealias Middleware<A, R> = (param: A, next: Next<A, R>) -> R
private class NextImpl<A, R>(
private val middleware: Middleware<A, R>,
private val next: Next<A, R>
) : Next<A, R> {
override fun invoke(param: A): R {
@talenguyen
talenguyen / Tools.md
Last active February 7, 2020 04:31
Useful tools
@talenguyen
talenguyen / load-local-properties.gradle
Last active August 6, 2019 04:06
Script to read local properties
def propertiesFile = new File(rootDir, "local.properties")
if (propertiesFile.exists()) {
def properties = new Properties()
properties.load(propertiesFile.newDataInputStream())
if (properties.containsKey("gradleScripts.dir")) {
ext.gradleScriptsDir = properties.getProperty("gradleScripts.dir")
} else {
throw new IllegalArgumentException("ERROR: Gradle Scripts location not found. " +
"Define location with gradleScripts.dir in the local.properties file")
}
@talenguyen
talenguyen / git-submodule.md
Last active August 5, 2019 03:54
Delete a submodule
# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule

# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule

# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule
package com.besimplify.android.test.ui.login;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.KeyEvent;
import android.view.View;