Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Alashov Berkeli alashow

🏠
Working from home
View GitHub Profile
View Zoomable.kt
/*
* Copyright (C) 2021, Alashov Berkeli
* All rights reserved.
*/
package tm.alashow.common.compose.ui
import androidx.compose.animation.core.Animatable
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
View Search.kt
@Composable
internal fun SearchScreen(
viewModel: SearchViewModel,
) {
// if state is remembered here, pagers WILL restart
val viewState by rememberFlowWithLifecycle(viewModel.state).collectAsState(initial = SearchViewState.Empty)
val listState = rememberLazyListState()
SearchList(viewModel, viewState, listState)
View AppColorsTheme.kt
@Composable
private fun App() {
val isDarkMode = isSystemInDarkTheme()
val (darkMode, setDarkMode) = remember { mutableStateOf(isDarkMode) }
AppTheme(darkTheme = darkMode) {
Switch(checked = darkMode, onCheckedChange = setDarkMode)
Text("${AppTheme.colors.onSurfaceInputBackground.toArgb()}")
}
}
@alashow
alashow / rclone.conf
Created Jun 4, 2021
Simple gdrive service account rotations with rclone
View rclone.conf
[driva-0-sa]
type = drive
scope = drive
team_drive = xyz0
root_folder_id = xyz0
service_account_file = path
[driva-1-sa]
type = drive
scope = drive
View mhnetworktest.py
import requests
from threading import Thread
from concurrent.futures import ThreadPoolExecutor
import threading
threadLock = threading.Lock()
URL = "https://modularhistory.com/"
N = 10
workers = 20
View Async.kt
/**
* The T generic is unused for some classes but since it is sealed and useful for Success and Fail,
* it should be on all of them.
*
* Complete: Success, Fail
* ShouldLoad: Uninitialized, Fail
*/
sealed class Async<out T>(val complete: Boolean, val shouldLoad: Boolean) {
open operator fun invoke(): T? = null
View QueryHighlighter.kt
import android.graphics.Typeface
import android.text.SpannableString
import android.text.TextUtils
import android.text.style.CharacterStyle
import android.text.style.StyleSpan
import android.widget.TextView
import java.text.Normalizer
import java.util.Locale
import java.util.regex.Pattern
@alashow
alashow / webtextsSolver.js
Created Nov 15, 2019
Solves multiple choice question parts of webtexts/soomo learning. Just run this code on browser's console.
View webtextsSolver.js
prepareAnswers();
setTimeout(resetQuestions, 1500);
setTimeout(solveQuestions, 3000);
function prepareAnswers() {
$.each($.find('.multiple-choice-question-element'), function(i, wrapper) {
wrapper = $(wrapper);
var button = wrapper.find('.save-answers');
var choice = $(wrapper.find('.question-choice')[0]).find('input');
View AppBarLifListeners.kt
// activity
private val onAppBarLiftListeners = HashSet<AppBarLiftListener>()
val appBar = findViewById<AppBarLayout>(R.id.appBar)
if (appBar != null) {
appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
onAppBarLiftListeners.forEach { it.onAppBarLift(verticalOffset) }
})
}
@alashow
alashow / DateTimePickerLocalizer.kt
Created May 4, 2019
Android Localize months in DatePickerDialog or am/pm in TimePickerDialog
View DateTimePickerLocalizer.kt
import timber.log.Timber
/**
* Patch date picker or time picker to use custom months or am/pm
* From: https://stackoverflow.com/a/33599403/2897341
*
* @param picker [android.widget.DatePicker] or [android.widget.TimePicker]
* @param values months or am/pm
*/
fun localizePicker(picker: Any, values: Array<String>) {