Skip to content

Instantly share code, notes, and snippets.

View RationalRank's full-sized avatar

Ranjith RationalRank

View GitHub Profile
@RationalRank
RationalRank / adb_proxy_settings.sh
Created December 29, 2024 19:08
Proxyman helper functions to toggle global proxy on the device via adb
# Function to get Mac's IP address on the current network
get_mac_ip() {
# Try primary interface first (en0 for most Macs)
local ip=$(ipconfig getifaddr en0)
if [ -z "$ip" ]; then
# Try alternative interface if en0 didn't work
ip=$(ipconfig getifaddr en1)
fi
echo "$ip"
}
@RationalRank
RationalRank / TimeoutCallAdapterFactory.kt
Created July 14, 2024 17:06
Retrofit adapter to control call timeouts per API / Dynamic timouts
import retrofit2.Call
import retrofit2.CallAdapter
import retrofit2.Retrofit
import java.lang.reflect.Type
import java.util.concurrent.TimeUnit
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class Timeout(
@RationalRank
RationalRank / tutorial.md
Created November 6, 2023 17:28 — forked from Makeshift/tutorial.md
Tutorial for automatically syncing an Obsidian vault with Git on an Android device

How to sync Obsidian with Git on Android

Limitations

  • If Termux is closed in the background by Android, the cron service will stop updating your repository and you must open Termux again. Refer to instructions for your device model to disable the killing of certain background applications.
  • This may negatively affect your devices battery life. I'm not entirely sure yet.

Setup

@RationalRank
RationalRank / NodeConnector.kt
Last active November 23, 2022 02:24
Appyx NodeConnector - Using kotlin flow
class NodeConnector<Input, Output> : Connectable<Input, Output> {
private val inputChannel: Channel<Input> = Channel(Channel.BUFFERED)
private val outputChannel: Channel<Output> = Channel(Channel.BUFFERED)
override val input: Flow<Input> = inputChannel.receiveAsFlow()
override val output: Flow<Output> = outputChannel.receiveAsFlow()
override fun send(value: Output) {
outputChannel.trySend(value)
<scheme name="Material" version="142" parent_scheme="Darcula">
<metaInfo>
<property name="created">2018-06-26T11:01:56</property>
<property name="ide">AndroidStudio</property>
<property name="ideVersion">3.2.0.18</property>
<property name="modified">2018-06-26T11:02:01</property>
<property name="originalScheme">My preference</property>
</metaInfo>
<attributes>
<option name="LOGCAT_ASSERT_OUTPUT">
// combines flowwithlifecycle, oneach and launchin
// warning: don't use inside coroutines!
fun <T> Flow<T>.launchOnEach(
owner: LifecycleOwner,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
action: suspend (T) -> Unit,
): Job = flowWithLifecycle(owner.lifecycle, minActiveState)
.onEach(action) // order matters here, see doc
.launchIn(owner.lifecycle.coroutineScope)
@RationalRank
RationalRank / gitSolutions.md
Created June 24, 2021 11:29 — forked from mrnabati/gitSolutions.md
Common Git problems (and solutions!)

Working with submodules in your repository

  • Create the submodule:

    git submodule add -b master <git@github.com:MYSUBMODULE.git> <path/to/MYSUBMODULE>

    This creates the submodule and makes it track submodule's master branch. You can change the branch name if you want to track a different branch.

  • Change some settings. In the parent repo:

    # make it so that git status will include changes to submodules.
@RationalRank
RationalRank / gist:822aa39e6a32839299c7d878543b297b
Last active April 27, 2021 05:13 — forked from paour/gist:11291062
Generate strings_array.xml
#! /usr/bin/python
import argparse
import os.path
import glob
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description='''\
Replacing values in arrays.xml with @string/ links. Generates three new files for each locale:
@RationalRank
RationalRank / colorUtils.kt
Created August 22, 2020 17:40 — forked from karangoel16/colorUtils.kt
ColorWithTransparency
fun String.toTransparentColor(num: Int): String {
return "#" + when (num) {
100 -> "FF"
99 -> "FC"
98 -> "FA"
97 -> "F7"
96 -> "F5"
95 -> "F2"
94 -> "F0"
@RationalRank
RationalRank / java_time.kt
Created July 9, 2020 18:54
java.time.* APIs quick ref
import java.time.*
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.time.temporal.TemporalAdjusters
// LocalDate, LocalTime, LocalDateTime - Represents date & time without timezone
val currentTime = LocalDateTime.now()
println("Current DateTime: $currentTime")
val currentDate = currentTime.toLocalDate()