Skip to content

Instantly share code, notes, and snippets.

View rayworks's full-sized avatar
:atom:

rayworks rayworks

:atom:
  • Shanghai, China
  • 17:30 (UTC +08:00)
View GitHub Profile
@pyricau
pyricau / graphviz.dominators.main.kts
Last active September 25, 2024 06:19
A Kotlin script that generates the dominator tree of a heap dump, as a CSV file for importing into Google Spreadsheets
#!/usr/bin/env kotlin -language-version 1.9
// Make sure you run "brew install kotlin graphviz" first.
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:Repository("https://dl.google.com/dl/android/maven2/")
@file:DependsOn("com.squareup.leakcanary:shark-android:3.0-alpha-8")
@file:DependsOn("androidx.collection:collection-jvm:1.4.0")
import androidx.collection.IntList
@KlassenKonstantin
KlassenKonstantin / Pull2Refresh.kt
Created March 26, 2024 11:23
Fitbit style Pull 2 Refresh
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
setContent {
P2RTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
CompositionLocalProvider(
LocalOverscrollConfiguration provides null // Disable overscroll otherwise it consumes the drag before we get the chance
@theapache64
theapache64 / launcTime.sh
Last active August 18, 2022 13:09
To measure average Activity startup time
# To measure lauch time
fun launchTime(){
# Config
LAUNCH_COUNT=10
REGEX='TotalTime: (\d+)'
# The two params are configurable via argument
DEFAULT_PACKAGE_NAME='com.your.packagename'
@TheMelody
TheMelody / Compose - CustomWebView.kt
Last active March 28, 2024 06:43
Jetpack Compose - WebView 使用方法
@Composable
fun CustomWebView(modifier: Modifier = Modifier,
url:String,
onBack: (webView:WebView?) -> Unit,
onProgressChange: (progress:Int)->Unit = {},
initSettings: (webSettings:WebSettings?) -> Unit = {},
onReceivedError: (error: WebResourceError?) -> Unit = {}){
val webViewChromeClient = object:WebChromeClient(){
override fun onProgressChanged(view: WebView?, newProgress: Int) {
//回调网页内容加载进度
@vganin
vganin / FlexRow.kt
Last active September 1, 2024 19:19
[DEPRECATED, use official FlowRow instead] Jetpack Compose simple flex-wrap container
@Composable
fun FlowRow(
horizontalGap: Dp = 0.dp,
verticalGap: Dp = 0.dp,
alignment: Alignment.Horizontal = Alignment.Start,
content: @Composable () -> Unit,
) = Layout(content = content) { measurables, constraints ->
val horizontalGapPx = horizontalGap.toPx().roundToInt()
val verticalGapPx = verticalGap.toPx().roundToInt()
@devadvance
devadvance / part_video_to_gif.sh
Created February 28, 2021 03:10
Create animated GIF and WebP from videos using ffmpeg
ffmpeg -ss $INPUT_START_TIME -t $LENGTH -i $INPUT_FILENAME \
-vf "fps=$OUTPUT_FPS,scale=$OUTPUT_WIDTH:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop $NUMBER_OF_LOOPS $OUTPUT_FILENAME
# Change these placeholders:
# * $INPUT_START_TIME - number of seconds in the input video to start from.
# * $LENGTH - number of seconds to convert from the input video.
# * $INPUT_FILENAME - path to the input video.
# * $OUTPUT_FPS - ouput frames per second. Start with `10`.
# * $OUTPUT_WIDTH - output width in pixels. Aspect ratio is maintained.
@FreddieOliveira
FreddieOliveira / docker.md
Last active November 17, 2024 21:14
This tutorial shows how to run docker natively on Android, without VMs and chroot.

Docker on Android 🐋📱

Edit 🎉

All packages, except for Tini have been added to termux-root. To install them, simply pkg install root-repo && pkg install docker. This will install the whole docker suite, left only Tini to be compiled manually.


Summary

@rharter
rharter / Scoped.kt
Last active August 12, 2024 09:48
A kotlin property delegate to scope any object to an android lifecycle. Blog post at https://ryanharter.com/blog/easy-android-scopes/
import androidx.lifecycle.get
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
/**
* Returns a property delegate to access the wrapped value, which will be retained for the
* duration of the lifecycle of this [ViewModelStoreOwner].
*
@8bitbuddhist
8bitbuddhist / create-android-display.sh
Last active October 6, 2023 14:03
Bash script to use an Android device as a second monitor for Linux. See https://blog.8bitbuddhism.com/2019/12/01/how-to-use-your-android-tablet-as-second-monitor/ for detailed instructions.
#!/bin/bash
# Make sure your Android device is plugged in and accessible over adb.
#### Remember to enable virtual displays in xorg by adding the following to your configuration (e.g. /usr/share/X11/xorg.conf.d/20-virtual.conf)
# Section "Device"
# Identifier "intelgpu0"
# Driver "intel"
# Option "VirtualHeads" "1"
#EndSection
@rayworks
rayworks / gist:15ba92c2e93bc6b4d6270d52942313e3
Last active October 28, 2021 15:21
ffmpeg in practice
1. Compile configure
configuration: --enable-libass --enable-gpl --enable-libfreetype --enable-libvpx --enable-libx264 --enable-libmp3lame
--enable-libspeex --enable-libx265 --enable-nonfree --enable-videotoolbox --enable-audiotoolbox --enable-fontconfig
--enable-libfdk-aac
2. Add subtitles(字幕)
./ffmpeg -i input.mp4 -vf subtitles=your.srt output.mp4
3. Specify subtitles when playing the video
./ffplay -vf subtitles=your.srt input.mp4