Skip to content

Instantly share code, notes, and snippets.

Avatar
💻

Tiago Araujo Tgo1014

💻
View GitHub Profile
View NavigationBottomBarSectionsStateKeeperWorkaround.kt
package jetpack.navigation.workaround
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.navigation.NavController
import androidx.navigation.ui.setupActionBarWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import java.lang.ref.WeakReference
View CouroutinesUsefulExtensions.kt
fun launch(f: () -> Unit) {
GlobalScope.launch {
f.invoke()
}
}
inline fun <reified T> asyncAndWait(crossinline f: () -> T) = runBlocking {
return@runBlocking GlobalScope.async(Dispatchers.IO) {
f.invoke()
}.await()
View CallingTheSheet.kt
private fun showBottomSheetMenu() {
val v = layoutInflater.inflate(R.layout.your_custom_layout_here, null)
val bottomSheet = GoogleBottomSheetDialog(this)
bottomSheet.setContentView(v)
bottomSheet.show()
}
View gist:02c9c6a255f709b9bd8577dec5ca5025
This file has been truncated, but you can view the full file.
[03-03 13:02:12.321 2397:2397 I/vold]
Vold 3.0 (the awakening) firing up
[03-03 13:02:12.322 2397:2397 V/vold]
Detected support for: exfat ext4 ntfs vfat
[03-03 13:02:12.326 2397:2397 I/vold]
[libfs_mgr]fs_mgr_read_fstab_dt(): failed to read fstab from dt
@Tgo1014
Tgo1014 / recursive_update.sql
Created Apr 4, 2017
Useful when updating a large quantities of rows from a big table
View recursive_update.sql
WHILE 1 = 1
BEGIN
UPDATE TOP(100000) A
SET CIA = CASE
WHEN DS_INDICADOR = 'AUTO' THEN LEFT(RIGHT(CD_ITEM,14),3)
WHEN DS_INDICADOR IN ('RE','RAMOS ELEMENTARES') THEN LEFT(RIGHT(CD_ITEM,10),3)
ELSE 0
END
FROM DB_PGC_PRODUCAO..TB_DM_INFO_GER_ANALITICO_HIST A
@Tgo1014
Tgo1014 / recursive_delete.sql
Created Apr 4, 2017
Delete a batch of rows from a table. Helpful when deleting large quantities of rows from a big table.
View recursive_delete.sql
DECLARE @DT_ANOMES_REF INT = 201702
DECLARE @QTD_REG_BATCH INT = 0
DECLARE @ID INT = 0
SET @QTD_REG_BATCH = CEILING((SELECT COUNT(*) FROM DB_PGC_PRODUCAO..TB_VIDA_DBM WHERE DT_ANOMES_REF = @DT_ANOMES_REF) / 100000)
WHILE @ID <= @QTD_REG_BATCH -- Este número resulta no calculo [Qtde. Linhas a serem deletadas] / [100000]
BEGIN
;WITH CTE AS
(
@Tgo1014
Tgo1014 / script.sql
Created Mar 22, 2017
Auto reagendamento de job para o primeiro dia útil do mês seguinte após carregar tabela
View script.sql
DECLARE @DIA_UTIL INT
DECLARE @PROXIMO_DIA_UTIL VARCHAR(8)
DECLARE @PRIMEIRO_DIA_UTIL_MES_SEGUINTE VARCHAR(8)
/*****************************************************************************************************************/
--VERIFICA DIAS ÚTEIS
/*****************************************************************************************************************/
--TABELA DIAS UTEIS
IF OBJECT_ID('TEMPDB..#DIA_UTEIS_MES_ATUAL') IS NOT NULL
DROP TABLE #DIA_UTEIS_MES_ATUAL
@Tgo1014
Tgo1014 / Android - sendFile.java
Created Apr 28, 2016
Send a file from Android to Java Server
View Android - sendFile.java
//first you need to create a socket and connect with a socket then use the following code
private OutputStream out = socket.getOutputStream();;
//you need to use the file you want to send as a param
public void sendMessage(File file) throws IOException {
if (out != null) {
byte[] bytes = new byte[(int) file.length()];
BufferedInputStream bis;
bis = new BufferedInputStream(new FileInputStream(file));
bis.read(bytes, 0, bytes.length);