Skip to content

Instantly share code, notes, and snippets.

@vorobeij
vorobeij / scan.kt
Created April 12, 2023 21:19
scan Documents on device
/** List of extension file paths */
override fun scan(folders: List<Uri>, extensions: Regex): List<DocumentFile> {
val result = mutableListOf<DocumentFile>()
fun scan(root: DocumentFile?, extensions: Regex, outputUris: MutableList<DocumentFile>) {
if (root == null) return
val name = root.name
if (root.isFile && name != null && name.contains(extensions)) {
outputUris.add(root)
return
@vorobeij
vorobeij / XmlParser.kt
Created April 8, 2023 11:34
Parse xml
package au.suby.data.api.youtube.wrappers
import org.w3c.dom.Document
import org.w3c.dom.Element
import org.w3c.dom.Node
import org.w3c.dom.NodeList
@Suppress("unused")
class XmlParser {
fun String.cmd(workingDir: File): String? {
try {
val parts = this.split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
proc.waitFor(60, TimeUnit.MINUTES)
@vorobeij
vorobeij / removelicenseHeaders.regexp
Last active March 29, 2019 06:30
Remove license heades from code
/\*\n.*Copyright[\s\S]*(\*/)\n\n
/\*\n[\s\S]*\n\npackage
/\*\n[\s\S]*/\n*import
/\*[\s\S]*Copyright[\s\S]*\*/
@vorobeij
vorobeij / drawBadgeSquirqle.kt
Created February 25, 2019 09:05
squirqle bezier curve
private inline fun drawBadgeSquirqle(canvas: Canvas) {
val badgeText = badge.toString()
badgeTextPaint.textScaleX = absCos(animFloat.value * Math.PI)
badgeTextPaint.getTextBounds(badgeText, 0, badgeText.length, badge.drawRect)
val cx = centerX + iconHalf
val cy = centerY - iconHalf
val w = badge.drawRect.width() * 0.9f
@vorobeij
vorobeij / MemoryMonitorActivity.kt
Created February 20, 2019 12:23
memory app android
override fun getAllocatedMemoryMb(): Int {
val pids = intArrayOf(android.os.Process.myPid())
return activityManager.getProcessMemoryInfo(pids)[0].totalPss / 1000
}
@vorobeij
vorobeij / AuthActivity.kt
Created December 19, 2018 09:25
Google Firebase Auth
package XXX
import android.content.Intent
import android.os.Bundle
import au.sjowl.base.basex.BaseActivity
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import io.michaelrocks.lightsaber.getInstance
import kotlinx.android.synthetic.main.activity_auth.*
import kotlinx.coroutines.GlobalScope
@vorobeij
vorobeij / CommonHandler.kt
Created November 21, 2018 12:53
Android MVP multithreading with coroutines
package au.sjowl.coroutinesplay
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.lang.Exception
import kotlin.coroutines.CoroutineContext
@vorobeij
vorobeij / Mainframer-setup.sh
Created October 29, 2018 19:49
mainframer setup
# create user on remote machine
scp remote_machine_setup.sh root@remote-machine:~/
ssh remoteMachine
sudo bash remote_machine_setup.sh sj_1 "new_user_ssh_public_key"
# From local machine
# sj_1@192.168.1.104 - remote machine
# press enters
ssh-keygen -t rsa
@vorobeij
vorobeij / screenshot.sh
Created October 8, 2018 17:17
adb screenshot
adb exec-out screencap -p > ~/Pictures/screen.png