Skip to content

Instantly share code, notes, and snippets.

View TomasValenta's full-sized avatar

Tomáš Valenta TomasValenta

View GitHub Profile
@nielsvanvelzen
nielsvanvelzen / DreamServiceCompat.kt
Last active May 4, 2024 11:34
Extension to DreamService to allow usage of Jetpack Compose inside
import android.service.dreams.DreamService
import androidx.annotation.CallSuper
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.setViewTreeLifecycleOwner
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryController
class LocationActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Listen to one flow in a lifecycle-aware manner using flowWithLifecycle
lifecycleScope.launch {
locationProvider.locationFlow()
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.collect {
// New location! Update the map
@marlosirapuan
marlosirapuan / gist:778d6beda5f8ab95695748011c864b19
Last active April 26, 2024 17:15
Download .m3u8 files on MacOS

Install ffmpeg

brew install ffmpeg

Download file through url, like this:

ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i "http://url-file.domain.m3u8" -c copy video.mp4

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

@thepoppingone
thepoppingone / m3u8streamffmpegdl.sh
Last active February 27, 2023 14:32
Download m3u8 playlist with ffmpeg - step by step download script (ffmpeg binary required)
#!/bin/sh
# Author : Wang Poh Peng
# Description : Use FFMPEG to download videos into mkv or mp4 format
RED='\033[1;31m'
NC='\033[0m' # No Color
GREEN='\033[0;32m'
CYAN='\033[0;36m'
@goodev
goodev / AndroidLogKotlin.xml
Last active November 1, 2021 07:29
Android log live template for kotlin:
<templateSet group="AndroidLogKotlin">
<template name="logm" value="android.util.Log.d(TAG, $FORMAT$)" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true">
<variable name="FORMAT" expression="groovyScript(&quot;def params = _2.collect {it + ' = [$' + it + ']'}.join(', '); return '\&quot;' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\&quot;'&quot;, kotlinFunctionName(), functionParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logd" value="android.util.Log.d(TAG, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
@Aidanvii7
Aidanvii7 / SparseArrayExtensions.kt
Last active December 17, 2019 14:48
A collection of extension functions for Android's SparseArray
package com.aidanvii.extensions
import android.util.SparseArray
import java.util.*
val SparseArray<*>.max: Int get () = size() - 1;
inline fun <V> SparseArray<V>.forEachValue(action: (V) -> Unit): SparseArray<V> {
for (index in 0..max) {
val key = keyAt(index)
@ctrl-freak
ctrl-freak / android-adb-pull-apk.md
Last active April 9, 2024 11:31
Retrieve APK from Non-Rooted Android Device through ADB

https://stackoverflow.com/a/18003462/348146

None of these suggestions worked for me, because Android was appending a sequence number to the package name to produce the final APK file name (this may vary with the version of Android OS). The following sequence of commands is what worked for me on a non-rooted device:

  1. Determine the package name of the app, e.g. com.example.someapp. Skip this step if you already know the package name.

    adb shell pm list packages

    Look through the list of package names and try to find a match between the app in question and the package name. This is usually easy, but note that the package name can be completely unrelated to the app name. If you can't recognize the app from the list of package names, try finding the app in Google Play using a browser. The URL for an app in Google Play contains the package name.

@FrancoisBlavoet
FrancoisBlavoet / DiaporamaAdapter.java
Created March 30, 2015 22:09
Helper Class allowing to load multiple images consecutively in the same view with Glide and animate between them.
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.animation.AlphaAnimation;
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active April 30, 2024 23:36
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName